Class MarkupToHTMLConverter
- java.lang.Object
-
- ca.cgjennings.layout.MarkupRenderer
-
- ca.cgjennings.layout.MarkupToHTMLConverter
-
public class MarkupToHTMLConverter extends MarkupRenderer
Converts markup written for aMarkupRenderer
into simple HTML. It works by taking advantage of the customizability ofMarkupRenderer
'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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ca.cgjennings.layout.MarkupRenderer
MarkupRenderer.StyledParagraph
-
-
Field Summary
Fields Modifier and Type Field Description static double
dpiForInlineImages
-
Fields inherited from class ca.cgjennings.layout.MarkupRenderer
currentAutoclose, currentHeadlineStatus, currentIndex, currentJustification, currentParametricTag, currentPositionInUntaggedText, currentPunctuationReplacement, currentSourceLine, currentTag, currentTagEndingIndex, currentTagNoCase, currentTagStartingIndex, currentTightness, currentVerticalJustification, DEBUG, finishedStyles, FIT_BOTH, FIT_NONE, FIT_SCALE_TEXT, FIT_TIGHTEN_LINE_SPACING, LAYOUT_BOTTOM, LAYOUT_CENTER, LAYOUT_JUSTIFY, LAYOUT_LEFT, LAYOUT_MIDDLE, LAYOUT_RIGHT, LAYOUT_TOP, openQuotes, styleStackMap, textHasWhitespace, USE_FAST_LINE_BREAKER, USE_PATCHED_LINE_BREAKER
-
-
Constructor Summary
Constructors Constructor Description MarkupToHTMLConverter()
Creates a new converter with default settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected TextStyle
adjustStyleForContext(TextStyle style)
protected java.lang.String[]
breakIntoParagraphs(java.lang.String source)
Breaks a source string into an array of individual lines.protected void
createDefaultParametricStyleMap()
Add default parametric style tags.protected void
createDefaultReplacementMap()
Add default entries to the set of replacements.protected void
createDefaultStyleMap()
Add default non-parametric style tags.double
getDPIForInlineImages()
protected java.lang.String
handleUnknownTag(java.lang.String tagnameLowercase, java.lang.String tagnameOriginalCase)
This method is called when a tag is encountered that does not match any existing defined or built-in tag.java.lang.String
markupToHTML(java.lang.String markup)
Converts the given markup to HTML.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.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.protected char
selectPunctuation(char curr, java.lang.StringBuilder writtenText)
The superclass doesn't handle our special HTML encoding characters, so we must override this.void
setDPIForInlineImages(double dpi)
-
Methods inherited from class ca.cgjennings.layout.MarkupRenderer
addLibrary, appendSegments, convertTagsToLinebreaks, createStyledParagraph, createStyledText, draw, drawAsSingleLine, findReplacementForTag, getAlignment, getAutoclose, getBaseFile, getDefaultExpansionLimit, getDefaultStyle, getEvaluatorFactory, getExpansionLimit, getHeadlineAlignment, getLineTightness, getMarkBadBox, getMarkupText, getPageShape, getParametricStyleForTag, getReplacementForTag, getScalingFractionalLimit, getScalingLimit, getStyledText, getStyleForTag, getTabWidth, getTabWidths, getTagParameters, getTextFitting, getTightnessLimit, invalidateLayoutCache, layout, measure, parseLibrary, parseMeasurement, removeAllTags, removeTag, renderText, replaceMacroParameters, replaceTagWith, replaceTagWithErrorMessage, resetPunctuationSelectorState, setAlignment, setAutoclose, setBaseFile, setDefaultExpansionLimit, setDefaultStyle, setDefinitionForTag, setEvaluatorFactory, setExpansionLimit, setHeadlineAlignment, setLineTightness, setMarkBadBox, setMarkupText, setPageShape, setParametricStyleForTag, setReplacementForTag, setScalingFractionalLimit, setScalingLimit, setStyleForTag, setTabWidth, setTabWidths, setTextFitting, setTightnessLimit, toString
-
-
-
-
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 converttitle
- 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 converttitle
- the title to use in the HTMLstyle
- 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 classMarkupRenderer
-
setDPIForInlineImages
public void setDPIForInlineImages(double dpi)
-
getDPIForInlineImages
public double getDPIForInlineImages()
-
createDefaultStyleMap
protected void createDefaultStyleMap()
Description copied from class:MarkupRenderer
Add default non-parametric style tags.- Overrides:
createDefaultStyleMap
in classMarkupRenderer
-
createDefaultParametricStyleMap
protected void createDefaultParametricStyleMap()
Description copied from class:MarkupRenderer
Add default parametric style tags.- Overrides:
createDefaultParametricStyleMap
in classMarkupRenderer
-
createDefaultReplacementMap
protected void createDefaultReplacementMap()
Add default entries to the set of replacements.- Overrides:
createDefaultReplacementMap
in classMarkupRenderer
-
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 classMarkupRenderer
-
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 classMarkupRenderer
-
adjustStyleForContext
protected TextStyle adjustStyleForContext(TextStyle style)
- Overrides:
adjustStyleForContext
in classMarkupRenderer
-
-