Skip to content

Commit

Permalink
issue #235 - fix problem with indented macro
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Dec 11, 2020
1 parent 4381bc9 commit d4f9253
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static String escapeMarkdownText( Node node, String text ) {
return MarkdownVisitorHelper.escapeMarkdownText(text);
}

private final static Pattern isHTMLCommentPattern = Pattern.compile( "^<!--(?:[\\s]*)(.+)-->$", Pattern.DOTALL );
private final static Pattern isHTMLCommentPattern = Pattern.compile( "^([\\s]*)<!--(?:[\\s]*)(.+)-->$", Pattern.DOTALL );

/**
*
Expand Down Expand Up @@ -310,14 +310,17 @@ public void visit(HtmlBlock node) {
final String literal = node.getLiteral();

final Matcher m = parseHTMLComment(literal);
if( m.matches() && isConfluenceMacro( m.group(1) ) ) {
if( m.matches() && isConfluenceMacro( m.group(2) ) ) {
processChildren(node)
.post(m.group(1)).process();
.pre(m.group(1))
.post(m.group(2))
.process();
}
else {
processChildren(node)
.pre("{html}\n%s\n", literal)
.post("{html}").process();
.post("{html}")
.process();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.bsc.makdown.commonmark
import org.bsc.confluence.model.Site
import org.bsc.markdown.commonmark.CommonmarkConfluenceWikiVisitor.parseHTMLComment
import org.junit.Test
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import java.nio.file.Paths
Expand All @@ -20,8 +21,15 @@ class Issue235Test {
val singleLineMatcher = parseHTMLComment("<!-- {xxxxxxx:yyyyyy} -->")

assertTrue( singleLineMatcher.matches() )
assertEquals( 1, singleLineMatcher.groupCount() )
assertEquals( "{xxxxxxx:yyyyyy}", singleLineMatcher.group(1).trimEnd() )
assertEquals( 2, singleLineMatcher.groupCount() )
assertEquals( "{xxxxxxx:yyyyyy}", singleLineMatcher.group(2).trimEnd() )

val singleLineMatcherWithPrefixSpaces = parseHTMLComment(" <!-- {xxxxxxx:yyyyyy} -->")

assertTrue( singleLineMatcherWithPrefixSpaces.matches() )
assertEquals( 2, singleLineMatcherWithPrefixSpaces.groupCount() )
assertEquals( " ", singleLineMatcherWithPrefixSpaces.group(1) )
assertEquals( "{xxxxxxx:yyyyyy}", singleLineMatcherWithPrefixSpaces.group(2).trimEnd() )

val multiLineMatcher = parseHTMLComment("""<!--
Expand All @@ -31,13 +39,13 @@ class Issue235Test {
""".trimIndent())

assertTrue( multiLineMatcher.matches() )
assertEquals( 1, multiLineMatcher.groupCount() )
assertEquals( "{xxxxxxx:yyyyyy}", multiLineMatcher.group(1).trimEnd() )
assertEquals( 2, multiLineMatcher.groupCount() )
assertEquals( "{xxxxxxx:yyyyyy}", multiLineMatcher.group(2).trimEnd() )

}

@Test
fun parseMacros() {
fun `parse generic macros`() {
val content = parseResource( this.javaClass, "issue235", this.site )

assertEquals("""
Expand All @@ -53,4 +61,20 @@ class Issue235Test {
""".trimIndent(), content )
}

@Test
fun `parse specific macros`() {
val content = parseResource( this.javaClass, "macro", this.site )
assertEquals("""
{toc}
h1. This is table of content
{toc:minLevel=2}
{toc:type=flat|separator=pipe:minLevel=2}
* Menu
** Menu item1
** Menu item2
* Related pages
{children:depth=1}
""".trimIndent(), content )
}
}

This file was deleted.

7 changes: 7 additions & 0 deletions processor-commonmark/src/test/resources/macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@

<!-- {toc:type=flat|separator=pipe:minLevel=2} -->

* Menu
* Menu item1
* Menu item2
* Related pages
<!--
{children:depth=1}
-->

0 comments on commit d4f9253

Please sign in to comment.