Class MarkdownParser
java.lang.Object
org.apache.maven.doxia.parser.AbstractParser
org.apache.maven.doxia.parser.AbstractTextParser
org.apache.maven.doxia.module.markdown.MarkdownParser
- All Implemented Interfaces:
MacroExecutor, Markup, TextMarkup, Parser
@Singleton
@Named("markdown")
public class MarkdownParser
extends AbstractTextParser
implements TextMarkup
Implementation of Parser for Markdown documents.
Defers effective parsing to the flexmark-java library, which generates HTML content then delegates parsing of this content to a slightly modified Doxia Xhtml5 parser. (before 1.8, the PegDown library was used)
- Since:
- 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInternal parser for HTML generated by the Markdown library. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.vladsch.flexmark.html.HtmlRendererFlexmark's HTML renderer (its output will be re-parsed and converted to Sink events)private static final com.vladsch.flexmark.parser.ParserFlexmark's Markdown Metadata parserprivate static final com.vladsch.flexmark.parser.ParserFlexmark's Markdown parser (one static instance fits all)private static final PatternRegex that captures the key and value of a multimarkdown-style metadata entry.private static final PatternRegex that identifies a multimarkdown-style metadata section at the start of the document In order to ensure that we have minimal risk of false positives when slurping metadata sections, the first key in the metadata section must be one of these standard keys or else the entire metadata section is ignored.The parser of the HTML produced by Flexmark, that we will use to convert this HTML to Sink eventsprivate static final PatternMatches a self-closing HTML tag, e.g.Fields inherited from interface Markup
COLON, EOL, EQUAL, GREATER_THAN, LEFT_CURLY_BRACKET, LEFT_SQUARE_BRACKET, LESS_THAN, MINUS, PLUS, QUOTE, RIGHT_CURLY_BRACKET, RIGHT_SQUARE_BRACKET, SEMICOLON, SLASH, SPACE, STARFields inherited from interface Parser
TXT_TYPE, UNKNOWN_TYPE, XML_TYPEFields inherited from interface TextMarkup
PIPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringRaw HTML embedded in a Markdown source (e.g.(package private) static StringnormalizeMultilineValue(String value) voidParses the given source model and emits Doxia events into the given sink.private booleanprocessMetadataForHtml(StringBuilder html, StringBuilder source) (package private) Stringuses flexmark-java library to parse content and generate HTML output.private Stringprivate booleanwriteHtmlMetadata(StringBuilder html, String key, List<String> values) private booleanwriteHtmlMetadata(StringBuilder html, Map<String, List<String>> data) Methods inherited from class AbstractTextParser
getTypeMethods inherited from class AbstractParser
addSinkWrapperFactory, doxiaVersion, executeMacro, getBasedir, getMacroManager, getSinkWrapperFactories, getWrappedSink, init, isEmitAnchorsForIndexableEntries, isEmitComments, isSecondParsing, parse, parse, parse, setEmitAnchorsForIndexableEntries, setEmitComments, setMacroExecutor, setSecondParsing
-
Field Details
-
METADATA_SECTION_PATTERN
Regex that identifies a multimarkdown-style metadata section at the start of the document In order to ensure that we have minimal risk of false positives when slurping metadata sections, the first key in the metadata section must be one of these standard keys or else the entire metadata section is ignored.- See Also:
-
METADATA_ENTRY_PATTERN
Regex that captures the key and value of a multimarkdown-style metadata entry. Group 1 captures the key, group 2 captures the value. Multivalues are not supported in the syntax! Multiline values need to be normalized- See Also:
-
SELF_CLOSING_HTML_TAG
Matches a self-closing HTML tag, e.g.<object type="image/svg+xml" data="x.svg"/>. Group 1 is the tag name, group 2 is the raw attribute string. Quoted attribute values are matched as a whole so a/inside one (e.g. adata="a/b"attribute) is not mistaken for the closing slash. -
parser
The parser of the HTML produced by Flexmark, that we will use to convert this HTML to Sink events -
FLEXMARK_PARSER
private static final com.vladsch.flexmark.parser.Parser FLEXMARK_PARSERFlexmark's Markdown parser (one static instance fits all) -
FLEXMARK_METADATA_PARSER
private static final com.vladsch.flexmark.parser.Parser FLEXMARK_METADATA_PARSERFlexmark's Markdown Metadata parser -
FLEXMARK_HTML_RENDERER
private static final com.vladsch.flexmark.html.HtmlRenderer FLEXMARK_HTML_RENDERERFlexmark's HTML renderer (its output will be re-parsed and converted to Sink events)
-
-
Constructor Details
-
MarkdownParser
public MarkdownParser()
-
-
Method Details
-
parse
Description copied from interface:ParserParses the given source model and emits Doxia events into the given sink.- Specified by:
parsein interfaceParser- Parameters:
source- not null reader that provides the source document.sink- A sink that consumes the Doxia events.reference- a string identifying the source (for file based documents the source file path)- Throws:
ParseException- if the model could not be parsed.
-
processMetadataForHtml
-
normalizeMultilineValue
-
writeHtmlMetadata
-
writeHtmlMetadata
-
toXhtml
uses flexmark-java library to parse content and generate HTML output.- Parameters:
source- the Markdown source- Returns:
- HTML content generated by flexmark-java
- Throws:
IOException- passed through
-
toXhtml
-
closeSelfClosingNonVoidHtmlTags
Raw HTML embedded in a Markdown source (e.g.<object type="image/svg+xml" data="x.svg"/>) is passed through untouched by flexmark. HTML5 has no such thing as a self-closing tag outside the fixed list of void elements (br, img, hr, ...): for every other element the trailing slash is simply ignored, so<object .../>is an open tag with no matching close. Left as-is,Jsoup.parse(String)then nests all following content inside that dangling<object>, and the eventual close tag is emitted only once the surrounding block ends - silently hiding everything in between (browsers treat it as<object>fallback content). Close such tags explicitly before jsoup ever sees them, so the element does not swallow its siblings.- Parameters:
html- the HTML generated by rendering the Markdown document- Returns:
- the same HTML with self-closing non-void tags rewritten to an explicit open/close pair
-