Re: Changing text content in a TreeProcessor extension
Posted by
David Jencks on
URL: https://discuss.asciidoctor.org/Changing-text-content-in-a-TreeProcessor-extension-tp8115p8118.html
Thanks for the example.
Asciidoctor parsing is conducted in more or less two phases: the “parser” identifies block content and creates the nodes for them, and the converter (e.g. html5) parses the content and identifies inline “blocks” such as links. A tree processor runs after the parser and before the converter, so inline nodes have not yet been recognized. This causes numerous problems but requires rewriting (at least) most of the parser to fix.
It looks to me as if blocks allow direct access to the source through lines (as you do) but that listItems insist on substitutions, thus requiring your workaround. This seems pretty unfortunate to me.
On Jul 28, 2020, at 5:18 PM, MattBlissett [via Asciidoctor :: Discussion] <
[hidden email]> wrote:
I now have it working on a test document, example here including the source:
http://mb.gbif.org/tmp/2020/07/asciidoctor-glossary.htmlThere is a role "glossary" on the crossreferences which point to items in the glossary, and the links are styled with a dotted underline instead of in blue.
My concern is this seemed more complicated than I expected -- traversing the document with a TreeProcessor is fine, but making changes to the text required disabling substitutions before calling the text method. I expected the tree to include inline elements like crossreferences or macros, but instead I'm just using a regular expression to find the <<crossreferences>> and change them to xref:crossreferences[role=glossary].