[Asciidoctorj API] How to add a line break?

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

[Asciidoctorj API] How to add a line break?

MoePad
This post was updated on .
Hi guys,

I'm playing around with the API of Asciidoctorj to create my own extensions. I successfully have simple examples running. But now I want to add a line break and tried for over 2h to achieve this ...

Here is my sample code, which is working except for the line breaking part (please see the last function createLineBreak):
ackage com.esentri.asciidoctor.extensions

import org.asciidoctor.extension.*
import org.asciidoctor.ast.*

import groovy.transform.CompileStatic

@CompileStatic
class DrawIOInlineMacro extends BlockMacroProcessor {

    DrawIOInlineMacro(final String name, final Map<String, Object> config) {
        super(name, config)
    }

    @Override
    protected Object process(final AbstractBlock parent,
        final String textAfterMacro, final Map<String, Object> attributes) {
          createBlock(parent, "pass",
            Arrays.asList(createExternalImageLink(parent, textAfterMacro, attributes),
                          createLineBreak(parent, attributes),
                          createEditButton(parent, textAfterMacro, attributes)),
            attributes, new HashMap<Object, Object>());
    }

    private String createExternalImageLink(final AbstractBlock parent,
        final String textAfterMacro, final Map<String, Object> attributes) {
          final Map options = [
              type: ':link',
              target: textAfterMacro
          ] as Map<String, Object>
          //context (2nd parameter): anchor, button, callout, footnote, image, indexterm, kbd (=keyboard shortcuts), menu, quoted
          final Inline imageObject = createInline(parent, 'image', textAfterMacro, attributes, options)
          imageObject.convert()
    }

    private String createEditButton(final AbstractBlock parent,
        final String textAfterMacro, final Map<String, Object> attributes) {
          final Map options = [
              type: ':link',
              target: textAfterMacro
          ] as Map<String, Object>

          final Inline editButton = createInline(parent, 'anchor', '[Bearbeiten]', attributes, options)
          editButton.convert()
    }

    private String createLineBreak(final AbstractBlock parent, final Map<String, Object> attributes) {
            final Inline lineBreak = createInline(parent, 'quoted', '{empty} +', attributes, [:])
            lineBreak.convert()
    }
}

The result of this extension is that I get {empty} + written to my translated document. I tried almost every configuration I could think of: using other context than quoted, using \n as text or {sp} +\n, etc. etc. etc.

Can someone show me the right direction? Every help will be appreciated  :)
Ted
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Asciidoctorj API] How to add a line break?

Ted
It looks like you are trying to inject :empty: into your AsciiDoc. This is how you assign {blank} to pass in the plus sign. You add :blank: at the top of the AsciiDoc

= Asciidoctor Blank Lines
:blank: pass:[ +]

Now you can add blank lines in the document:

{blank}
{blank}

This is the same as using +

- Ted @TedAtCIS
Loading...