Convert Strings Using the API

To convert an AsciiDoc-formatted string:

 puts Asciidoctor.convert '*This* is Asciidoctor.'

When converting a string, the header and footer are excluded by default to make Asciidoctor consistent with other lightweight markup engines like Markdown. If you want the header and footer, enable it using the :header_footer option:

 puts Asciidoctor.convert '*This* is Asciidoctor.', :header_footer => true

Now you’ll get a full HTML 5 file.

If you only want the inline markup to be processed, set the :doctype option to 'inline':

 puts Asciidoctor.convert '*This* is Asciidoctor.', :doctype => 'inline'

As before, you can also produce DocBook 5.0:

 puts Asciidoctor.convert '*This* is Asciidoctor.', :header_footer => true,
   :backend => 'docbook'

When converting a string, the table of contents is only included by default when using the :header_footer option as shown above. However, you can force it to be included without the header and footer by setting the toc attribute with a value of macro and using the toc::[] macro in the string itself.