Asciidoctorj: create an xref from an extension

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Asciidoctorj: create an xref from an extension

rockyallen
This extension should turn

text glossterm:FC[] more text

into

text xref:[a-FC,FC] more text

My code so far (v 1.6.0 alpha 5) is:

pubic class AbbreviationCollector extends InlineMacroProcessor {

public AbbreviationCollector() {super("glossterm", new HashMap<String,Object>()); }

public Object process(ContentNode parent, String target, Map<String,Object> attributes) {
  Map<String,Object> options = HashMap<String,Object>():
  options.put("1", "a-"+target);
  options.put("2", target);
  return createPhraseNode(parent, "macro", "xref", options).convert();
}}

I think the problem is with the middle 2 arguments because the error is:

... undefined method 'inline_xref' ....

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj: create an xref from an extension

Robert.Panzer
Looking at the source of Asciidoctor [1] I would say that the context of the node has to be anchor and the node type should be :xref

That would result in:

  Map<Object,Object> options = new HashMap<>();
  options.put(":type", ":xref");
  return createPhraseNode(parent, ":anchor", texttoshow, new HashMap<>, options);

But that's just guessing, I didn't test it.


[1] https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/converter/html5.rb#L1021-L1023