Skip to content

Commit

Permalink
[DOXIA-617] support yaml metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Jan 4, 2023
1 parent a1ad9b5 commit 5d364e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ CharSequence toHtml( Reader source )
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,24 @@ public void testNumberedListSinkEvent()
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_",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: A Title & a 'Test'
author: Somebody 'Nickname' Great <somebody@somewhere.org>
date: 2013 © Copyleft
keywords: maven,doxia,markdown
---

# The document with look-alike header

copyright: none

## A subheading

Some more text

0 comments on commit 5d364e0

Please sign in to comment.