Index: src/main/java/org/apache/maven/doxia/module/confluence/parser/ChildBlocksBuilder.java =================================================================== --- src/main/java/org/apache/maven/doxia/module/confluence/parser/ChildBlocksBuilder.java (revision 589378) +++ src/main/java/org/apache/maven/doxia/module/confluence/parser/ChildBlocksBuilder.java (working copy) @@ -66,8 +66,7 @@ } else { - blocks.add( new TextBlock( text.toString() ) ); - text = new StringBuffer(); + text = addTextBlockIfNecessary( blocks, text ); insideBold = true; } @@ -81,16 +80,14 @@ } else { - blocks.add( new TextBlock( text.toString() ) ); - text = new StringBuffer(); + text = addTextBlockIfNecessary( blocks, text ); insideItalic = true; } break; case '[': insideLink = true; - blocks.add( new TextBlock( text.toString() ) ); - text = new StringBuffer(); + text = addTextBlockIfNecessary( blocks, text ); break; case ']': if ( insideLink ) @@ -113,16 +110,12 @@ break; case '{': - if ( input.charAt( i + 1 ) == '{' ) + if ( input.charAt( i + 1 ) == '{' ) // it's monospaced { i++; - blocks.add( new TextBlock( text.toString() ) ); - text = new StringBuffer(); } - else - { - text.append( c ); - } + // else it's a confluence macro... + text = addTextBlockIfNecessary( blocks, text ); break; case '}': @@ -138,7 +131,16 @@ } else { - text.append( c ); + String name = text.toString(); + if ( name.startsWith( "anchor:" ) ) + { + blocks.add( new AnchorBlock( name.substring( "anchor:".length() ) ) ); + } + else + { + blocks.add( new TextBlock( "{" + name + "}" ) ); + } + text = new StringBuffer(); } break; @@ -149,8 +151,7 @@ if ( input.charAt( i + 1 ) == '\\' ) { i++; - blocks.add( new TextBlock( text.toString() ) ); - text = new StringBuffer(); + text = addTextBlockIfNecessary( blocks, text ); blocks.add( new LinebreakBlock() ); } else @@ -172,4 +173,14 @@ return blocks; } + + private StringBuffer addTextBlockIfNecessary( List blocks, StringBuffer text ) + { + if ( text.length() == 0 ) + { + return text; + } + blocks.add( new TextBlock( text.toString() ) ); + return new StringBuffer(); + } } Index: src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java =================================================================== --- src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (revision 589378) +++ src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (working copy) @@ -171,6 +171,28 @@ assertEquals( 6, result.split( "end:listItem\n" ).length ); } + /** @throws Exception */ + public void testAnchor() + throws Exception + { + String result = locateAndParseTestSourceFile( "anchor" ); + + assertContainsLines( result, "begin:paragraph\nbegin:anchor, name: start\nend:anchor" ); + assertContainsLines( result, "begin:anchor, name: middle\nend:anchor" ); + assertContainsLines( result, "begin:paragraph\ntext: Simple paragraph\nbegin:anchor, name: end\nend:anchor" ); + // 3 anchors in the input... + assertEquals( 4, result.split( "end:anchor\n" ).length ); + } + + /** @throws Exception */ + public void testUnknownMacro() + throws Exception + { + String result = locateAndParseTestSourceFile( "unknown-macro" ); + + assertContainsLines( result, "begin:paragraph\ntext: {unknown:start}" ); + } + private void assertContainsLines( String message, String result, String lines ) { lines = StringUtils.replace( lines, "\n", EOL ); Index: src/test/resources/anchor.confluence =================================================================== --- src/test/resources/anchor.confluence (revision 0) +++ src/test/resources/anchor.confluence (revision 0) @@ -0,0 +1,7 @@ +h1. Section Title + +{anchor:start}Simple paragraph. + +Simple paragraph{anchor:end}. + +Simple {anchor:middle} paragraph. Index: src/test/resources/unknown-macro.confluence =================================================================== --- src/test/resources/unknown-macro.confluence (revision 0) +++ src/test/resources/unknown-macro.confluence (revision 0) @@ -0,0 +1,5 @@ +{unknown:start}Simple paragraph. + +Simple paragraph{unknown:end}. + +Simple {unknown:middle} paragraph.