Asciidoctor fails to parse formatted text: "​<a data-type

796 views Asked by At

I'm running asciidoctor with the following command:

asciidoctor -r asciidoctor-pdf -b pdf master.asciidoc

And it fails to parse the following text:

pass:[<a data-type="xref" data-xrefstyle="ct" href="#m1">#m1</a>]::

With the following error:

failed to parse formatted text: ​<a data-type="xref" data-xrefstyle="ct" href="#m1">#m1</a>

How can I fix it?

1

There are 1 answers

1
uroesch On BEST ANSWER

Asciidoctor with backend PDF does only have limited support for passthrough syntax as the documentation states.

Asciidoctor PDF does not support arbitrary passthrough content. While the basebackend for the PDF converter is html, it only recognizes a limited subset of inline HTML elements that can be mapped to PDF (e.g., a, strong, em, code, ). Therefore, if your content contains passthrough blocks or inlines, you most likely have to use a conditional preprocessor to skip them (and make other arrangements).

While the a tag is mentioned above a small test shows that only basic syntax is supported.

Using the below adoc file...

= test pass

pass:[<em>#m1</em>]

pass:[<strong>#m1</strong>]

pass:[<code>#m1</code>]

pass:[<a href="#m1">#m1</a>]

pass:[<a href="#m1" data-type="xref" data-xrefstyle="ct">#m1</a>]

Running it through the asciidoctor pdf backend produces the same error as you already mentioned in your question.

$ asciidoctor -r asciidoctor-pdf -b pdf  test.adoc 
asciidoctor: ERROR: failed to parse formatted text: <a href="#m1" data-type="xref" data-xrefstyle="ct">#m1</a>

The resulting PDF looks like the below screenshot. The simple <a href="#m1">#m1</a> line is properly converted. But as soon as further attributes are added it fails. This is in sync with the documentation stating advanced html syntax is not recognized by the pdf backend.

test.adoc rendered

To generate a PDF with the desired passthrough you may want to convert it with plain asciidoctor and pipe it to wkhtmltopdf.

asciidoctor -o - test.adoc | wkhtmltopdf -  test.pdf

The result uses the html look and feel of as shown below with slightly smaller body text.

enter image description here