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:
Markup,TextMarkup,Parser
@Singleton @Named("markdown") public class MarkdownParser extends AbstractTextParser implements TextMarkupImplementation of
Parserfor 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 Classes Modifier and Type Class Description static classMarkdownParser.MarkdownHtmlParserInternal parser for HTML generated by the Markdown library.
-
Field Summary
Fields Modifier and Type Field Description private static com.vladsch.flexmark.html.HtmlRendererFLEXMARK_HTML_RENDERERFlexmark's HTML renderer (its output will be re-parsed and converted to Sink events)private static com.vladsch.flexmark.parser.ParserFLEXMARK_METADATA_PARSERFlexmark's Markdown Metadata parserprivate static com.vladsch.flexmark.parser.ParserFLEXMARK_PARSERFlexmark's Markdown parser (one static instance fits all)private static java.util.regex.PatternMETADATA_ENTRY_PATTERNRegex that captures the key and value of a multimarkdown-style metadata entry.private static java.util.regex.PatternMETADATA_SECTION_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.private MarkdownParser.MarkdownHtmlParserparserThe parser of the HTML produced by Flexmark, that we will use to convert this HTML to Sink events-
Fields inherited from interface org.apache.maven.doxia.markup.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, STAR
-
Fields inherited from interface org.apache.maven.doxia.parser.Parser
TXT_TYPE, UNKNOWN_TYPE, XML_TYPE
-
Fields inherited from interface org.apache.maven.doxia.markup.TextMarkup
PIPE
-
-
Constructor Summary
Constructors Constructor Description MarkdownParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static java.lang.StringnormalizeMultilineValue(java.lang.String value)voidparse(java.io.Reader source, Sink sink, java.lang.String reference)Parses the given source model and emits Doxia events into the given sink.private booleanprocessMetadataForHtml(java.lang.StringBuilder html, java.lang.StringBuilder source)(package private) java.lang.StringtoHtml(java.io.Reader source)uses flexmark-java library to parse content and generate HTML output.private booleanwriteHtmlMetadata(java.lang.StringBuilder html, java.lang.String key, java.util.List<java.lang.String> values)private booleanwriteHtmlMetadata(java.lang.StringBuilder html, java.util.Map<java.lang.String,java.util.List<java.lang.String>> data)-
Methods inherited from class org.apache.maven.doxia.parser.AbstractTextParser
getType
-
Methods inherited from class org.apache.maven.doxia.parser.AbstractParser
addSinkWrapperFactory, doxiaVersion, executeMacro, getBasedir, getMacroManager, getSinkWrapperFactories, getWrappedSink, init, isEmitAnchorsForIndexableEntries, isEmitComments, isSecondParsing, parse, parse, parse, setEmitAnchorsForIndexableEntries, setEmitComments, setSecondParsing
-
-
-
-
Field Detail
-
METADATA_SECTION_PATTERN
private static final java.util.regex.Pattern 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:
- Multimarkdown Metadata
-
METADATA_ENTRY_PATTERN
private static final java.util.regex.Pattern 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:
- Multimarkdown Metadata
-
parser
@Inject private MarkdownParser.MarkdownHtmlParser 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_PARSER
Flexmark's Markdown parser (one static instance fits all)
-
FLEXMARK_METADATA_PARSER
private static final com.vladsch.flexmark.parser.Parser FLEXMARK_METADATA_PARSER
Flexmark's Markdown Metadata parser
-
FLEXMARK_HTML_RENDERER
private static final com.vladsch.flexmark.html.HtmlRenderer FLEXMARK_HTML_RENDERER
Flexmark's HTML renderer (its output will be re-parsed and converted to Sink events)
-
-
Method Detail
-
parse
public void parse(java.io.Reader source, Sink sink, java.lang.String reference) throws ParseExceptionParses 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. You could usenewReadermethods fromReaderFactory.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
private boolean processMetadataForHtml(java.lang.StringBuilder html, java.lang.StringBuilder source)
-
normalizeMultilineValue
static java.lang.String normalizeMultilineValue(java.lang.String value)
-
writeHtmlMetadata
private boolean writeHtmlMetadata(java.lang.StringBuilder html, java.util.Map<java.lang.String,java.util.List<java.lang.String>> data)
-
writeHtmlMetadata
private boolean writeHtmlMetadata(java.lang.StringBuilder html, java.lang.String key, java.util.List<java.lang.String> values)
-
toHtml
java.lang.String toHtml(java.io.Reader source) throws java.io.IOExceptionuses flexmark-java library to parse content and generate HTML output.- Parameters:
source- the Markdown source- Returns:
- HTML content generated by flexmark-java
- Throws:
java.io.IOException- passed through
-
-