The project is in a healthy, maintained state
An extension for AsciiDoctor that converts a single AsciiDoc file to a DITA topic.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 6.0, >= 6.0.2
~> 13.3, >= 13.3.1
~> 3.4, >= 3.4.4

Runtime

~> 2.0, >= 2.0.26
 Project Readme

dita-topic

dita-topic is a custom converter for Asciidoctor that converts a single AsciiDoc file to a corresponding DITA 1.3 topic.

In combination with asciidoctor-dita-vale, dita-convert, and dita-cleanup, this project can be used to rapidly convert AsciiDoc content to DITA:

  1. Identify incompatible markup in the AsciiDoc source file:

    $ vale source_file.adoc
  2. Convert the AsciiDoc file to a generic DITA topic:

    $ dita-topic source_file.adoc
  3. Convert the generic DITA topic to a specialized DITA concept, reference, or task:

    $ dita-convert -g source_file.dita -o output_file.dita
  4. Optional: Clean up the resulting DITA file if necessary:

    $ dita-cleanup -i -D ../images -X . output_file.dita

Installation

Installing as a Ruby gem

Install the asciidoctor-dita-topic Ruby gem:

$ gem install asciidoctor-dita-topic

Installing as a container

Pull the asciidoc-to-dita container with Podman:

$ podman pull quay.io/jhradilek/asciidoc-to-dita

If you prefer to use Docker, replace podman with docker.

Usage

To convert an AsciiDoc file to a generic DITA topic by using the Ruby gem, run the dita-topic command-line interface as follows:

$ dita-topic your_file.adoc

This creates a new file, your_file.dita, in the same directory as your_file.adoc. You can also supply multiple files or use wildcards to convert entire documentation sets.

The command-line interface simplifies the code execution and provides a few options in addition to the conversion. If you prefer to use Asciidoctor directly, load the converter with the -r dita-topic option and then select dita-topic as the backend output format with -b dita-topic:

$ asciidoctor -r dita-topic -b dita-topic your_file.adoc

To run the dita-topic command in a container, use the following command:

$ podman run --rm -it -v `pwd`:/docs quay.io/jhradilek/asciidoc-to-dita:latest dita-topic your_file.adoc

If you are on a system with SELinux enabled, add :Z to the mount options:

$ podman run --rm -it -v `pwd`:/docs:Z quay.io/jhradilek/asciidoc-to-dita:latest dita-topic your_file.adoc

Replace podman with docker if you prefer to use Docker.

Adding content type definitions

DITA differentiates between three main topic types: concepts, tasks, and references. To replicate this behavior, the dita-topic converter recognizes the following :_mod-docs-content-type: attribute definition values in AsciiDoc files:

Attribute Value

Description

ASSEMBLY

The AsciiDoc file is a modular documentation assembly intended to convert to a DITA concept. This implies that the assembly file follows the modular documentation guidelines and in addition to include directives, it contains a title and an introduction.

ATTRIBUTES

The AsciiDoc file is an attribute definition file and is not intended to be converted to DITA on its own. This implies that the file is only used to provide attribute definitions and does not contain any printable content.

CONCEPT

The AsciiDoc file is a concept module intended to convert to a DITA concept.

PROCEDURE

The AsciiDoc file is a procedure module intended to convert to a DITA task.

REFERENCE

The AsciiDoc file is a reference module intended to convert to a DITA reference.

SNIPPET

The AsciiDoc file is a modular documentation text snippet and is not intended to be converted to DITA on its own.

For example, to identify an AsciiDoc file as a concept, add the following line at the top of the file above the document title:

:_mod-docs-content-type: CONCEPT

The dita-topic converter uses this information to add an appropriate outputclass="content_type" attribute to the <topic> element. The dita-convert Python package then transforms such a topic to the specialized DITA concept, reference, or task.

Adding short descriptions

DITA provides the <shortdesc> element which allows the user to describe the purpose of the topic and is often used as preview text in search results. To replicate this behavior, the dita-topic converter recognizes a paragraph preceded by the [role="_abstract"] attribute list and adds the outputclass="abstract" attribute to it. The dita-convert Python package transforms such a paragraph to <shortdesc> during conversion to a specialized DITA concept, reference, or task.

For example, to designate a paragraph as a short description, use the following AsciiDoc markup:

[id="topic-id"]
= Procedure title

[role="_abstract"]
A short description of the procedure module and what it helps the
user accomplish.

An introductory paragraph.

Adding semantic markup

Unlike AsciiDoc, DITA provides a number of semantic elements for software components such as file names, commands, or command-line options. To replicate this behavior, the dita-topic converter recognizes the following roles assigned to monospace (`) inline text:

AsciiDoc Role

DITA Element

Description

command

<cmdname>

A command name.

directory

<filepath>

A directory name.

filename

<filepath>

A file name.

option

<option>

A command-line option.

variable

<varname>

A variable name.

For example, to describe a file name, use the following AsciiDoc markup:

Read the [filename]`/etc/passwd` file to see the complete list of
available user accounts.

If you do not want to use semantic markup during conversion, for example when the source files do not use annotations for it consistently, you can disable this functionality.

Adding metadata

DITA provides four metadata attributes that can be used for conditional processing. To replicate this behavior, the dita-topic converter recognizes the following roles assigned to inline and block elements:

AsciiDoc Role

DITA Attribute

Description

platform:value
pl:value

platform="value"

Operating system or hardware architecture.

product:value
pr:value

product="value"

Product name.

audience:value
au:value

audience="value"

Target audience.

otherprops:value
op:value

otherprops="value"

Additional properties.

Use the following syntax to assign the role to the correct element:

  • To assign a role to a complete block such as a paragraph or an entire list, use the standard attribute list syntax:

    [role="pl:linux+mac au:beginner"]
    A paragraph with multiple roles.
  • To assign a role to a block element with an existing attribute list such as an admonition, a source code block, an example block, or a table, append the role assignment to it:

    [NOTE,role="au:beginner"]
    ====
    An admonition intended for beginners.
    ====
  • To assign a role to a formatted inline element, use the standard boxed attribute list in front of valid inline markup:

    A paragraph with text intended for [.pl:linux]#Linux.# [.pl:windows+macos]#other platforms.#
  • To assign a role to an inline element with an existing attribute list such as a link, a cross reference, or an image, append the role assignment to it:

    image:example-image.png[An image intended for beginners,role="au:beginner"]
    
    link:https://example.com/[An external link intended for Linux,role="pl:linux"]
    
    xref:other-platforms[A cross reference intended for other platforms,role="pl:windows+macos"]
  • To assign a role to an individual list item such as a procedure step or a prerequisite, assign it to the {empty} character reference attribute at the beginning of the list item:

    . [.pl:linux]#{empty}# A step intended for Linux.

    AsciiDoc does not provide native syntax for assigning roles to list items.

  • To assign a role to an individual description list term and explanation pair, assign it to the {empty} character reference attribute at the beginning of the description term:

    [.pl:linux]#{empty}# A term intended for Linux::
    A description intended for Linux.

    AsciiDoc does not provide native syntax for assigning roles to description list items.

  • To assign a role to an individual table row, assign it to the {empty} character reference attribute at the beginning of the first column:

    [cols="1,1"]
    |===
    |First column
    |Second column
    
    | [.au:beginner]#{empty}# A table row intended for beginners
    | Another cell in the same row
    |===

    AsciiDoc does not provide native syntax for assigning roles to table rows.

Options

AsciiDoc supports many formatting options that do not have a direct equivalent in DITA. By default, the dita-topic converter works around these limitations, but you can supply additional options to change this behavior.

Supplying individual attribute definitions

If your AsciiDoc files use attributes that are defined outside of these files, you can supply the attribute definitions on the command line with the -a attribute=value (or --attribute attribute=value) option:

$ dita-topic -a attribute=value your_file.adoc

If you prefer to use Asciidoctor directly, supply the attribute definitions with the -a attribute=value option as follows:

$ asciidoctor -r dita-topic -b dita-topic -a attribute=value your_file.adoc

You can provide multiple -a options at the same time. Providing relevant attribute definitions is especially important if your document contains conditional content.

Supplying attribute definition files

If listing individual attribute definitions is impractical, you can use the -p definition_file.adoc (or --prepend-file definition_file.adoc) option to supply another AsciiDoc file with attribute definitions in it:

$ dita-topic -p definition_file.adoc your_file.adoc

The supplied file is automatically prepended to each AsciiDoc file during conversion. You can provide multiple -p options at the same time or use a combination -p and -a options to construct your attribute definitions. If you define the same attribute twice this way, the value defined by using the -a option takes precedence.

This functionality is not available in standard Asciidoctor.

Disabling all include directives

By default, Asciidoctor resolves all include directives before converting the file. To only convert the contents of the selected file, run the dita-topic command with the -I (or --no-includes) option:

$ dita-topic -I your_file.adoc

If you prefer to use Asciidoctor directly, there is no direct equivalent to this functionality. As a workaround, you can specify the -S secure option:

$ asciidoctor -r dita-topic -b dita-topic -S secure your_file.adoc

This disables processing of the include directives, but leaves cross references to the included files in the converted output.

Disabling inclusion of assemblies and modules

By default, Asciidoctor resolves all include directives before converting the file. To only include content from files that are explicitly marked as attributes or snippets, run the dita-topic command with the -A (or --no-modules) option:

$ dita-topic -A your_file.adoc

This functionality is not available in standard Asciidoctor.

Enabling author lines

AsciiDoc topics are expected to be included in other files and therefore should not contain author line definitions. In most cases, lines that directly follow the topic title are intended as first paragraphs. For this reason, author lines are disabled by default. To avoid losing content during conversion, as a workaround, the dita-topic converter interprets the raw content of the author line as a paragraph and issues a warning.

To enable processing of author lines as metadata, run the dita-topic command with the -l (or --author-line) option:

$ dita-topic -l your_file.adoc

If you prefer to use Asciidoctor directly, set the value of the dita-topic-authors attribute to on:

$ asciidoctor -r dita-topic -b dita-topic -a dita-topic-authors=on your_file.adoc

Disabling floating titles

Unlike AsciiDoc, DITA does not support floating titles and only allows titles to be assigned to a limited number of elements. To avoid losing content during conversion, as a workaround, the dita-topic converter uses the following markup by default:

<p outputclass="title"><b>Floating title</b></p>

To disable this behavior, run the dita-topic command with the -T (or --no-titles) option:

$ dita-topic -T your_file.adoc

If you prefer to use Asciidoctor directly, set the value of the dita-topic-titles attribute to off:

$ asciidoctor -r dita-topic -b dita-topic -a dita-topic-titles=off your_file.adoc

Disabling callouts

Unlike AsciiDoc, DITA does not support callouts as a method to add annotations to specific lines in verbatim blocks. To avoid losing content during conversion, as a workaround, the dita-topic converter uses Unicode characters for circled numbers.

To disable this behavior, run the dita-topic command with the -C (or --no-callouts) option:

$ dita-topic -C your_file.adoc

If you prefer to use Asciidoctor directly, set the value of the dita-topic-callouts attribute to off:

$ asciidoctor -r dita-topic -b dita-topic -a dita-topic-callouts=off your_file.adoc

Disabling sidebars

Unlike AsciiDoc, DITA does not support sidebars as a method to visually separate information from the main text. To avoid losing content during conversion, as a workaround, the dita-topic converter uses the following markup by default:

<div outputclass="sidebar">
  Sidebar text.
</div>

To disable this behavior, run the dita-topic command with the -S (or --no-sidebars) option:

$ dita-topic -S your_file.adoc

If you prefer to use Asciidoctor directly, set the value of the dita-topic-sidebars attribute to off:

$ asciidoctor -r dita-topic -b dita-topic -a dita-topic-sidebars=off your_file.adoc

Disabling semantic markup

By default, the dita-topic converter supports additional semantic markup for elements like command names, file paths, command-line options, and variables. To disable this functionality, run the dita-topic command with the -M (or --no-semantic-markup) option:

$ dita-topic -M your_file.adoc

If you prefer to use Asciidoctor directly, set the value of the dita-topic-semantic attribute to off:

$ asciidoctor -r dita-topic -b dita-topic -a dita-topic-semantic=off your_file.adoc

Disabling non-breaking spaces in titles

In certain situations, excessive use of non-breaking spaces can cause rendering problems, for example in a narrow navigation side bar. For convenience, the dita-topic converter can remove the following characters from titles at conversion time:

AsciiDoc Attribute

HTML Character Entity Reference

Numeric Character Reference

Description

{nbsp}

&nbsp;

&#160;

Non-breaking space

N/A

&thinsp;, &ThinSpace;

&#8201;

Thin space

{zwsp}

&ZeroWidthSpace;

&#8203;

Zero-width space

{wj}

&NoBreak;

&#8288;

Word joiner

Note that this list is not excessive and is based on white space characters with corresponding character replacement attribute references in AsciiDoc.

To strip non-breaking spaces from titles, run the dita-topic command with the -B (or --no-spaces) option:

$ dita-topic -B your_file.adoc

If you prefer to use Asciidoctor directly, set the value of the dita-topic-spaces attribute to off:

$ asciidoctor -r dita-topic -b dita-topic -a dita-topic-spaces=off your_file.adoc

Warnings

Despite aspiring to avoid losing content during conversion and produce valid DITA output, there are limitations to what is possible because of the differences between the two markup languages. When the dita-topic converter encounters a possible problem, it prints a warning to standard error output in the following format:

asciidoctor: WARNING: dita-topic: The warning message

This possible warning messages are as follows:

Admonition titles not supported in DITA

AsciiDoc allows you to add a custom title to any admonition by including .Admonition title on the line above it. Unlike AsciiDoc, DITA does not allow titles for admonitions. dita-topic issues this warning whenever an admonition has a title defined in the converted AsciiDoc file.

Author lines not enabled for topics

AsciiDoc interprets the first line that directly follows the document title as an author line. Because topics are not expected to have author lines, dita-topic issues this warning when an author line is present in the converted AsciiDoc file.

Block titles not supported in DITA

AsciiDoc allows you to include .Block title on the line above most of the block elements to assign a custom title to them. Unlike AsciiDoc, DITA only allows titles to be assigned to a limited number of elements. dita-topic issues this warning when floating titles are disabled and a block title is present in the converted AsciiDoc file.

Callouts not supported in DITA

AsciiDoc allows you to use <1>, <2>, <3> and so on in verbatim blocks to add annotations to the specific lines. Unlike AsciiDoc, DITA does not provide a direct equivalent for this functionality. dita-topic issues this warning when callouts are disabled and a callout number is present in the converted AsciiDoc file.

Callout number not in range between 1 and 50

The dita-topic converter uses Unicode characters to represent callouts. Because the Unicode characters for circled numbers are only available for numbers between 1 and 50, dita-topic issues this warning when callouts are enabled and a callout number is outside of this range.

Examples not supported within object in DITA

AsciiDoc allows you to use an example block anywhere in the document. Unlike AsciiDoc, DITA only allows examples to appear directly in the topic body. dita-topic issues a warning whenever an example is nested in another AsciiDoc element.

Floating titles not supported in DITA

AsciiDoc allows you to use floating titles anywhere in the document. Unlike AsciiDoc, DITA does not support floating titles. dita-topic issues this warning when floating titles are disabled and a floating title is present in the converted AsciiDoc file.

Inline breaks not supported in DITA

AsciiDoc provides multiple ways to insert line breaks in paragraphs, such as inserting  + at the end of the line or specifying [%hardbreaks] on the line preceding the paragraph. Unlike AsciiDoc, DITA does not provide direct equivalent for this functionality. dita-topic issues this warning whenever an inline line break is present in the converted AsciiDoc file and places the <!-- break --> comment in the output file to mark its place.

Nesting of sections not supported in DITA

AsciiDoc allows you to nest sections up to 5 levels deep. Unlike AsciiDoc, DITA does not allow the <section> elements to be nested. dita-topic issues a warning whenever nested sections are present in the converted AsciiDoc file.

Page breaks not supported in DITA

AsciiDoc allows you to use <<< on a separate line to enforce a page break in output formats that support it. Unlike AsciiDoc, DITA does not support page breaks. dita-topic issues this warning whenever a page break is present in the converted AsciiDoc file and places the <p outputclass="page-break"></p> in the output file to mark its place.

Possible invalid reference: reference

AsciiDoc allows you to cross reference by using an ID no matter if this ID is defined within or outside of the converted document. Unlike AsciiDoc, DITA requires both the target ID and the ID of the target topic to be included in the cross reference if the reference leads outside of the current file. As dita-topic is meant to be run on individual AsciiDoc files, it does not have access to information from referenced files during conversion. dita-topic issues this warning whenever the cross reference target is not present in the converted AsciiDoc file.

Sidebars not supported in DITA

AsciiDoc allows you to assign any block the [sidebar] block style or enclose it between a pair of **** to create a delimited sidebar block. Unlike AsciiDoc, DITA does not support sidebar blocks. dita-topic issues this warning when sidebars are disabled and a sidebar block is present in the converted AsciiDoc file.

STEM support not implemented

AsciiDoc provides multiple ways to insert Science, Technology, Engineering and Math (STEM) expressions in the document, including the stem:[formula] inline macro and the [stem] delimited block. dita-topic does not implement this feature and issues this warning whenever such an expression is present in the converted AsciiDoc file.

Table footers not supported in DITA

AsciiDoc allows you to set the footer option to mark the last table row as a table footer. Unlike AsciiDoc, DITA does not support table footers. dita-topic issues this warning whenever a table footer is present in the converted AsciiDoc file.

Thematic breaks not supported in DITA

Asciidoc allows you to use ''', ---, or *** (the last two with possible optional spaces in between the characters) to insert a thematic break in between two blocks, most commonly represented by a horizontal line. Unlike AsciiDoc, DITA does not support thematic breaks. dita-topic issues this warning whenever a thematic break is present in the converted AsciiDoc file.

Copyright © 2024–2026 Jaromir Hradilek

This program is free software, released under the terms of the MIT license. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.