michael-o commented on a change in pull request #49:
URL: https://github.com/apache/maven-doxia/pull/49#discussion_r549815838
##########
File path:
doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java
##########
@@ -74,48 +80,103 @@
/**
* 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.
*/
- private static final String MULTI_MARKDOWN_METADATA_SECTION =
-
"^(((?:[^\\s:][^:]*):(?:.*(?:\r?\n\\p{Blank}+[^\\s].*)*\r?\n))+)(?:\\s*\r?\n)";
+ private static final Pattern METADATA_SECTION_PATTERN = Pattern.compile(
+ "\\A^\\s*"
+ +
"(?:title|author|date|address|affiliation|copyright|email|keywords|language|phone|subtitle)"
+ + "\\h*:\\h*\\V*\\h*$\\v+"
+ + "(?:^\\h*[^:\\v]+\\h*:\\h*\\V*\\h*$\\v+)*",
+ Pattern.MULTILINE | Pattern.CASE_INSENSITIVE );
/**
* Regex that captures the key and value of a multimarkdown-style metadata
entry.
*/
- private static final String MULTI_MARKDOWN_METADATA_ENTRY =
- "([^\\s:][^:]*):(.*(?:\r?\n\\p{Blank}+[^\\s].*)*)\r?\n";
-
- /**
- * 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 static final String[] STANDARD_METADATA_KEYS =
- { "title", "author", "date", "address", "affiliation", "copyright",
"email", "keywords", "language", "phone",
- "subtitle" };
+ private static final Pattern METADATA_ENTRY_PATTERN = Pattern.compile(
+ "^\\h*([^:\\v]+?)\\h*:\\h*(\\V*)\\h*$",
+ Pattern.MULTILINE );
/**
* <p>getType.</p>
*
* @return a int.
*/
+ @Override
public int getType()
{
return TXT_TYPE;
}
+ /**
+ * The parser of the HTML produced by Flexmark, that we will
+ * use to convert this HTML to Sink events
+ */
@Requirement
private MarkdownHtmlParser parser;
+ /**
+ * Flexmark's Markdown parser (one static instance fits all)
+ */
+ private static final com.vladsch.flexmark.parser.Parser FLEXMARK_PARSER;
+
+ /**
+ * Flexmark's HTML renderer (its output will be re-parsed and converted to
Sink events)
+ */
+ private static final HtmlRenderer FLEXMARK_HTML_RENDERER;
+
+ // Initialize the Flexmark parser and renderer, once and for all
+ static
+ {
+ MutableDataSet flexmarkOptions = new MutableDataSet();
+
+ // Emulate Pegdown's behavior
+ flexmarkOptions.setFrom( ParserEmulationProfile.PEGDOWN );
+
+ // Enable the extensions that we used to have in Pegdown
+ flexmarkOptions.set( com.vladsch.flexmark.parser.Parser.EXTENSIONS,
Arrays.asList(
+ EscapedCharacterExtension.create(),
+ AbbreviationExtension.create(),
+ AutolinkExtension.create(),
+ DefinitionExtension.create(),
+ TypographicExtension.create(),
+ TablesExtension.create(),
+ WikiLinkExtension.create(),
+ StrikethroughExtension.create()
+ ) );
+
+ // Disable wrong apostrophe replacement
+ flexmarkOptions.set( TypographicExtension.SINGLE_QUOTE_UNMATCHED,
"'" );
Review comment:
Let's finish this first and then put 542 on top.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]