Interface Formatter


  • public interface Formatter
    If a SyntaxHighlighterAdapter also implements the Formatter interface, then it will be invoked to convert the full source block container including the <pre/> and <code/> elements. This way it is able to assign custom classes to these elements.

    A client side renderer will usually implement this interface so that it can certain marker classes including an indicator for the language of the source.

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

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.String format​(Block node, java.lang.String lang, java.util.Map<java.lang.String,​java.lang.Object> opts)
      Format the highlighted source for inclusion in an HTML document.
    • Method Detail

      • format

        java.lang.String format​(Block node,
                                java.lang.String lang,
                                java.util.Map<java.lang.String,​java.lang.Object> opts)
        Format the highlighted source for inclusion in an HTML document. Should call StructuralNode.getContent() to get the content of the source block, which might be highlighted by a Highlighter.

        Example:

        
             public String format(Block node, String lang, Map<String, Object> options) {
                 StringBuilder sb = new StringBuilder();
                 sb.append("<pre class='highlight'>");
                 sb.append("<code data-lang='").append(lang).append("'>");
                 sb.append(node.getContent());
                 sb.append("</code>");
                 sb.append("</pre>\n");
                 return sb.toString();
             }
         

        Parameters:
        node - The source Block being processed.
        lang - The source language String for this Block (e.g., ruby).
        opts - A Hash of options that control syntax highlighting:
        • nowrap: A Boolean that indicates whether wrapping should be disabled (optional).
        Returns:
        Returns the highlighted source wrapped in preformatted tags (e.g., pre and code)