You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2023/01/04 15:40:28 UTC
[maven-doxia] branch master updated: [DOXIA-617] support yaml metadata
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git
The following commit(s) were added to refs/heads/master by this push:
new d2f824ed [DOXIA-617] support yaml metadata
d2f824ed is described below
commit d2f824edef821dabf8ca6f27941750953b7f4ed6
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Thu Dec 22 08:12:41 2022 +0100
[DOXIA-617] support yaml metadata
---
.../maven/doxia/module/markdown/MarkdownParser.java | 7 +++++++
.../doxia/module/markdown/MarkdownParserTest.java | 19 ++++++++++++++++++-
.../src/test/resources/metadata-yaml.md | 14 ++++++++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java b/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java
index 99676dd0..5f161165 100644
--- a/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java
+++ b/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java
@@ -185,6 +185,13 @@ public class MarkdownParser
html.append( "<html>" );
html.append( "<head>" );
+ // detect yaml style metadata
+ if ( text.startsWith( "---" ) )
+ {
+ // remove the enclosing --- to get back to classical metadata
+ text = text.replaceFirst( "---", "" ).replaceFirst( "---", "" );
+ }
+
// First, we interpret the "metadata" section of the document and add the corresponding HTML headers
Matcher metadataMatcher = METADATA_SECTION_PATTERN.matcher( text );
boolean haveTitle = false;
diff --git a/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java b/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java
index 7887f0bd..efcab9a0 100644
--- a/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java
+++ b/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java
@@ -311,7 +311,24 @@ public class MarkdownParserTest
public void testMetadataSinkEvent()
throws Exception
{
- List<SinkEventElement> eventList = parseFileToEventTestingSink( "metadata" ).getEventList();
+ testMetadataSinkEvent( "metadata" );
+ }
+
+ /**
+ * Assert the metadata is passed through when parsing "metadata-yaml.md".
+ *
+ * @throws Exception if the event list is not correct when parsing the document
+ */
+ public void testMetadataYamlSinkEvent()
+ throws Exception
+ {
+ testMetadataSinkEvent( "metadata-yaml" );
+ }
+
+ private void testMetadataSinkEvent( String doc )
+ throws Exception
+ {
+ List<SinkEventElement> eventList = parseFileToEventTestingSink( doc ).getEventList();
Iterator<SinkEventElement> it = eventList.iterator();
assertSinkEquals( it, "head", "title", "text", "text", "text", "title_", "author", "text", "author_", "date",
diff --git a/doxia-modules/doxia-module-markdown/src/test/resources/metadata-yaml.md b/doxia-modules/doxia-module-markdown/src/test/resources/metadata-yaml.md
new file mode 100644
index 00000000..406c74ff
--- /dev/null
+++ b/doxia-modules/doxia-module-markdown/src/test/resources/metadata-yaml.md
@@ -0,0 +1,14 @@
+---
+title: A Title & a 'Test'
+author: Somebody 'Nickname' Great <so...@somewhere.org>
+date: 2013 © Copyleft
+keywords: maven,doxia,markdown
+---
+
+# The document with look-alike header
+
+copyright: none
+
+## A subheading
+
+Some more text
\ No newline at end of file