Re: How to create inline macro producing HTML? (In AsciidoctorJ)
Posted by
holyjak on
URL: https://discuss.asciidoctor.org/How-to-create-inline-macro-producing-HTML-In-AsciidoctorJ-tp8313p8336.html
Hi Dan, thanks a lot! This indeed works:
```clojure
(let [attrs (java.util.HashMap. {})
opts (java.util.HashMap. {"subs" []})]
(.createPhraseNode
this parent, "quoted",
(str "<abbr title=\"title\">abbreviation</abbr>")
attrs opts))
```
Is there some introduction to / brief overview of the API where I could learn about the available block x inline contexts and what they mean, and about the possible options and attributes? I feel like a blinded person walking in a maze :-)
> The create_inline_pass helper, which does exactly that, was added in Asciidoctor 2.
How do I use it from Java? If I change the context above to "pass" then it fails with
java.util.concurrent.ExecutionException: org.asciidoctor.jruby.internal.AsciidoctorCoreException: org.jruby.exceptions.NoMethodError: (NoMethodError) undefined method `convert_inline_pass' for #<Asciidoctor::Converter::Html5Converter:0x3227d4d1>
i.e. it is looking for `convert_inline_pass`, not `create_inline_pass`.
> Btw, an extension does not have to use the create* methods. It could just instantiate a new PhraseNode. The create* methods are just helpers.
I have looked into creating my own PhraseNode but the code that does it -
https://github.com/asciidoctor/asciidoctorj/blob/6a3a38925dc2683a2ba6d3dcffd6f71c21b7c8d7/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/extension/internal/JRubyProcessor.java#L175 - is currently beyond my understanding, as it calls into the Ruby code that I do not know. And I don't know what I would gain by doing this manually so I will keep to the helpers :)
Thanks a lot!