This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch doxia-1.x
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git


The following commit(s) were added to refs/heads/doxia-1.x by this push:
     new 5d364e09 [DOXIA-617] support yaml metadata
5d364e09 is described below

commit 5d364e097968b01e30ddb74f2ad9259204be7a26
Author: Hervé Boutemy <[email protected]>
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 a066c508..b4fd58ca 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
@@ -189,6 +189,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 11e4da53..35b3799f 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
@@ -300,7 +300,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();
 
         assertEquals( it, "head", "title", "text", "text", "text", "title_", 
"author", "text", "author_", "date", "text", "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 <[email protected]>
+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

Reply via email to