Class MarkupToHTMLConverter


  • public class MarkupToHTMLConverter
    extends MarkupRenderer
    Converts markup written for a MarkupRenderer into simple HTML. It works by taking advantage of the customizability of MarkupRenderer's tag handling to insert "invisible" tags back into the markup. The tags are made invisible by surrounding them with special, non-printing characters instead of angle brackets. After the markup is processed, the styled text is converted back into plain text and the invisible tags are converted back into regular tags.

    This approach allow us to ensure that the markup is processed in exactly the same way as standard markup before being handed to the HTML converter.

    Author:
    Chris Jennings
    • Field Detail

      • dpiForInlineImages

        public static double dpiForInlineImages
    • Constructor Detail

      • MarkupToHTMLConverter

        public MarkupToHTMLConverter()
        Creates a new converter with default settings.
    • Method Detail

      • markupToHTML

        public java.lang.String markupToHTML​(java.lang.String markup)
        Converts the given markup to HTML.
        Parameters:
        markup - the markup to convert
        Returns:
        the HTML equivalent of the markup
      • markupToHTML

        public java.lang.String markupToHTML​(java.lang.String markup,
                                             java.lang.String title)
        Converts the given markup to HTML, using the given title for the HTML.
        Parameters:
        markup - the markup to convert
        title - the title to use in the HTML
        Returns:
        the HTML equivalent of the markup
      • markupToHTML

        public java.lang.String markupToHTML​(java.lang.String markup,
                                             java.lang.String title,
                                             java.lang.String style)
        Converts the given markup to HTML, using the given title and style for the HTML.
        Parameters:
        markup - the markup to convert
        title - the title to use in the HTML
        style - the CSS styles to include in the HTML
        Returns:
        the HTML equivalent of the markup
      • handleUnknownTag

        protected java.lang.String handleUnknownTag​(java.lang.String tagnameLowercase,
                                                    java.lang.String tagnameOriginalCase)
        Description copied from class: MarkupRenderer
        This method is called when a tag is encountered that does not match any existing defined or built-in tag. Subclasses may override it as a simple way to extend the behaviour of this class.

        If the method returns a string, that string will be interpreted exactly as if it had appeared instead of the unknown tag. It may include both text and tags.

        If the method does not have a suitable replacement for the unknown tag, it should return null.

        The base class parses tags of the form <u+xxxx> to insert Unicode characters from their hexidecimal code and parses <image> tags to insert images into the text stream. To remove these behaviours, override and return null. To extend them, return the value of the superclass implementation once you have decided you do not want to handle the tag yourself.

        Overrides:
        handleUnknownTag in class MarkupRenderer
      • setDPIForInlineImages

        public void setDPIForInlineImages​(double dpi)
      • getDPIForInlineImages

        public double getDPIForInlineImages()
      • selectPunctuation

        protected char selectPunctuation​(char curr,
                                         java.lang.StringBuilder writtenText)
        The superclass doesn't handle our special HTML encoding characters, so we must override this.
        Overrides:
        selectPunctuation in class MarkupRenderer
      • breakIntoParagraphs

        protected java.lang.String[] breakIntoParagraphs​(java.lang.String source)
        Breaks a source string into an array of individual lines. Unlike the rendering version, we don't want to split out headline tags as a special case because the HTML agent should be in charge of that.
        Overrides:
        breakIntoParagraphs in class MarkupRenderer