Interface SyntaxHighlighterAdapter

  • All Known Subinterfaces:
    Highlighter

    public interface SyntaxHighlighterAdapter
    This interface has to be implemented by all syntax highlighter adapters, regardless if they update the resulting HTML document to highlight sources on the client or on the server.

    Depending on how the syntax highlighter works in detail one or more of these interfaces should be implemented as well:

    Formatter
    If the highlighter requires certain classes on the <pre><code></code></pre> elements that enclose the source text.
    StylesheetWriter
    If the highlighter can write stylesheets to external files in case the document is rendered with the attributes :linkcss and :copycss.
    Highlighter
    If the highlighter actually highlights the source text while rendering the asciidoc document to html.
    Logging
    If the highlighter wants to log to the common Asciidoctor logger.

    SyntaxHighlighterAdapters have to be registered as classes at the SyntaxHighlighterRegistry:

    
         Asciidoctor asciidoctor;
         asciidoctor.syntaxHighlighterRegistry().register(MySyntaxHighligher.class, "mysyntaxhighighter");
         asciidoctor.convert(doc,
             Options.builder()
                 .attributes(Attributes.builder()
                     .sourceHighlighter("mysyntaxhighlighter")
                     .build())
                 .build());
     

    A SyntaxHighlighterAdapter is expected to have a constructor with 3 parameters:

    name
    A String containing the name of the highlighter.
    backend
    A String containing the backend used for rendering, e.g. "html5".
    options
    A Map<String, Object> that contains options for rendering. One key that is always present is document that contains the current Document that is rendered.
    All parameters are optional, that means if there is only a constructor that takes two String parameters, then this will be used to construct an instance. This includes using the default constructor if the class defines no constructor at all.

    The lifecycle of a SyntaxHighlighter is that one instance is created for every document that is converted.

    This API is experimental and might change in an incompatible way in a minor version update!

    • Method Detail

      • getDocinfo

        java.lang.String getDocinfo​(LocationType location,
                                    Document document,
                                    java.util.Map<java.lang.String,​java.lang.Object> options)