Index: C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/parser/LinebreakParserTest.java
===================================================================
--- C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/parser/LinebreakParserTest.java (revision 0)
+++ C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/parser/LinebreakParserTest.java (revision 0)
@@ -0,0 +1,75 @@
+package org.apache.maven.doxia.module.confluence.parser;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.Reader;
+import java.io.StringWriter;
+
+import org.apache.maven.doxia.module.confluence.ConfluenceParserTest;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.TextSink;
+
+/**
+ * Test class for ConfluenceParser.
+ */
+public class LinebreakParserTest
+ extends ConfluenceParserTest
+{
+
+ private String lineBreak;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ StringWriter output = new StringWriter();
+ Sink sink = new TextSink( output );
+ sink.lineBreak();
+ lineBreak = output.toString();
+ }
+
+ /** @throws Exception */
+ public void testLineBreak()
+ throws Exception
+ {
+ StringWriter output = null;
+ Reader reader = null;
+
+ try
+ {
+ output = new StringWriter();
+ reader = getTestReader( "test/linebreak", outputExtension() );
+
+ Sink sink = new TextSink( output );
+ createParser().parse( reader, sink );
+ // System.err.println( output );
+
+ assertTrue( output.toString().indexOf( "Line" + EOL + lineBreak ) != -1 );
+ assertTrue( output.toString().indexOf( "with 2" + EOL + lineBreak ) != -1 );
+ assertTrue( output.toString().indexOf( "inline" + EOL + lineBreak ) != -1 );
+ }
+ finally
+ {
+ output.close();
+ reader.close();
+ }
+ }
+
+}
Index: C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/parser/SectionBlockParserTest.java
===================================================================
--- C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/parser/SectionBlockParserTest.java (revision 0)
+++ C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/parser/SectionBlockParserTest.java (revision 0)
@@ -0,0 +1,67 @@
+package org.apache.maven.doxia.module.confluence.parser;
+
+import java.io.Reader;
+import java.io.StringWriter;
+
+import org.apache.maven.doxia.module.confluence.ConfluenceParserTest;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.TextSink;
+
+public class SectionBlockParserTest
+ extends ConfluenceParserTest
+{
+
+ public void testSupportedSectionTitles()
+ throws Exception
+ {
+ StringWriter output = null;
+ Reader reader = null;
+
+ try
+ {
+ output = new StringWriter();
+ reader = getTestReader( "test/section", outputExtension() );
+
+ Sink sink = new TextSink( output );
+ createParser().parse( reader, sink );
+ System.err.println( output );
+
+ for ( int i = 1; i <= 5; i++ )
+ {
+ assertTrue( "Could not locate section " + i + " title",
+ output.toString().indexOf( "sectionTitle" + i + EOL + "text: " + "Section" + i ) != -1 );
+ }
+ }
+ finally
+ {
+ output.close();
+ reader.close();
+ }
+ }
+
+ public void testSectionTitleWithLeadingSpace()
+ throws Exception
+ {
+ StringWriter output = null;
+ Reader reader = null;
+
+ try
+ {
+ output = new StringWriter();
+ reader = getTestReader( "test/section", outputExtension() );
+
+ Sink sink = new TextSink( output );
+ createParser().parse( reader, sink );
+ System.err.println( output );
+
+ assertFalse(
+ "Section title has leading space",
+ output.toString().indexOf( "sectionTitle1" + EOL + "text: " + " TitleWithLeadingSpace" ) != -1 );
+ }
+ finally
+ {
+ output.close();
+ reader.close();
+ }
+ }
+}
Index: C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
===================================================================
--- C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (revision 586868)
+++ C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (working copy)
@@ -19,6 +19,7 @@
* under the License.
*/
+import org.apache.maven.doxia.markup.Markup;
import org.apache.maven.doxia.parser.AbstractParserTest;
import org.apache.maven.doxia.parser.Parser;
@@ -27,6 +28,7 @@
*/
public class ConfluenceParserTest extends AbstractParserTest
{
+ protected static final String EOL = Markup.EOL;
private ConfluenceParser parser;
/** {@inheritDoc} */
Index: C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/resources/test/section.confluence
===================================================================
--- C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/resources/test/section.confluence (revision 0)
+++ C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/resources/test/section.confluence (revision 0)
@@ -0,0 +1,9 @@
+h1. Section1
+
+h2. Section2
+h3. Section3
+
+h4. Section4
+h5. Section5
+
+h1. TitleWithLeadingSpace
Index: C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/resources/test/linebreak.confluence
===================================================================
--- C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/resources/test/linebreak.confluence (revision 0)
+++ C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/test/resources/test/linebreak.confluence (revision 0)
@@ -0,0 +1,5 @@
+Line\\
+break.
+
+Line\\with 2\\inline\\
+Breaks.
\ No newline at end of file
Index: C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SectionBlockParser.java
===================================================================
--- C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SectionBlockParser.java (revision 586868)
+++ C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/SectionBlockParser.java (working copy)
@@ -60,7 +60,7 @@
{
int level = Integer.parseInt( Character.toString( line.charAt( 1 ) ) );
- String title = line.substring( 3 );
+ String title = line.substring( 3 ).trim();
return new SectionBlock( title, level );
}
Index: C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ParagraphBlockParser.java
===================================================================
--- C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ParagraphBlockParser.java (revision 586868)
+++ C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ParagraphBlockParser.java (working copy)
@@ -20,16 +20,17 @@
*/
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
-import java.util.Arrays;
+import org.apache.maven.doxia.parser.ParseException;
import org.apache.maven.doxia.util.ByLineSource;
-import org.apache.maven.doxia.parser.ParseException;
import org.codehaus.plexus.util.StringUtils;
public class ParagraphBlockParser
implements BlockParser
{
+
public boolean accept( String line, ByLineSource source )
{
return true;
@@ -48,6 +49,7 @@
do
{
+
if ( line.trim().length() == 0 )
{
break;
@@ -63,7 +65,7 @@
if ( insideBold )
{
TextBlock tb = new TextBlock( text.toString() );
- blocks.add( new BoldBlock( Arrays.asList( new Block[]{tb} ) ) );
+ blocks.add( new BoldBlock( Arrays.asList( new Block[] { tb } ) ) );
text = new StringBuffer();
}
else
@@ -78,7 +80,7 @@
if ( insideItalic )
{
TextBlock tb = new TextBlock( text.toString() );
- blocks.add( new ItalicBlock( Arrays.asList( new Block[]{tb} ) ) );
+ blocks.add( new ItalicBlock( Arrays.asList( new Block[] { tb } ) ) );
text = new StringBuffer();
}
else
@@ -129,13 +131,13 @@
break;
case '}':
- //System.out.println( "line = " + line );
+ // System.out.println( "line = " + line );
if ( line.charAt( i + 1 ) == '}' )
{
i++;
TextBlock tb = new TextBlock( text.toString() );
- blocks.add( new MonospaceBlock( Arrays.asList( new Block[]{tb} ) ) );
+ blocks.add( new MonospaceBlock( Arrays.asList( new Block[] { tb } ) ) );
text = new StringBuffer();
}
else
@@ -144,19 +146,39 @@
}
break;
+ case '\\':
+
+ // System.out.println( "line = " + line );
+
+ if ( line.charAt( i + 1 ) == '\\' )
+ {
+ i++;
+ blocks.add( new TextBlock( text.toString() ) );
+ text = new StringBuffer();
+ blocks.add( new LinebreakBlock() );
+ }
+ else
+ {
+ text.append( line.charAt( i + 1 ) );
+ }
+
+ break;
default:
text.append( c );
}
}
}
- // TODO: instead of just flying along we should probably test new lines in the other parsers
- // to make sure there aren't things that should be handled by other parsers. For example, right
+ // TODO: instead of just flying along we should probably test new lines
+ // in the other parsers
+ // to make sure there aren't things that should be handled by other
+ // parsers. For example, right
// now:
// Blah blah blah blah
// # one
// # two
//
- // Will not get processed correctly. This parser will try to deal with it when it should be handled
+ // Will not get processed correctly. This parser will try to deal with
+ // it when it should be handled
// by the list parser.
while ( ( line = source.getNextLine() ) != null );
Index: C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/ConfluenceParser.java
===================================================================
--- C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/ConfluenceParser.java (revision 586868)
+++ C:/Dave/dev/crap/doxia/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/ConfluenceParser.java (working copy)
@@ -19,25 +19,25 @@
* under the License.
*/
-import org.apache.maven.doxia.util.ByLineReaderSource;
-import org.apache.maven.doxia.util.ByLineSource;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.maven.doxia.module.confluence.parser.Block;
import org.apache.maven.doxia.module.confluence.parser.BlockParser;
+import org.apache.maven.doxia.module.confluence.parser.HorizontalRuleBlockParser;
+import org.apache.maven.doxia.module.confluence.parser.ParagraphBlockParser;
import org.apache.maven.doxia.module.confluence.parser.SectionBlockParser;
-import org.apache.maven.doxia.module.confluence.parser.ParagraphBlockParser;
import org.apache.maven.doxia.module.confluence.parser.VerbatimBlockParser;
-import org.apache.maven.doxia.module.confluence.parser.HorizontalRuleBlockParser;
+import org.apache.maven.doxia.module.confluence.parser.list.ListBlockParser;
import org.apache.maven.doxia.module.confluence.parser.table.TableBlockParser;
-import org.apache.maven.doxia.module.confluence.parser.list.ListBlockParser;
import org.apache.maven.doxia.parser.AbstractTextParser;
import org.apache.maven.doxia.parser.ParseException;
import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.util.ByLineReaderSource;
+import org.apache.maven.doxia.util.ByLineSource;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
/**
* Parse the Confluence.
* See
@@ -50,6 +50,7 @@
public class ConfluenceParser
extends AbstractTextParser
{
+
private BlockParser[] parsers;
public ConfluenceParser()
@@ -66,7 +67,6 @@
}
//TODO: (empty line) Produces a new paragraph
- //TODO: \\ Creates a line break. Not often needed, most of the time Confluence will guess new lines for you appropriately.
//TODO: better support for anchors
public List parse( ByLineSource source )
@@ -140,7 +140,7 @@
}
sink.head();
-
+
sink.head_();
sink.body();