You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by lt...@apache.org on 2007/10/26 11:13:57 UTC
svn commit: r588573 - in
/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src:
main/java/org/apache/maven/doxia/module/confluence/
main/java/org/apache/maven/doxia/module/confluence/parser/
test/java/org/apache/maven/doxia/module/confluen...
Author: ltheussl
Date: Fri Oct 26 02:13:56 2007
New Revision: 588573
URL: http://svn.apache.org/viewvc?rev=588573&view=rev
Log:
DOXIA-169: fix line breaks. Thanks to Dave Syer.
Added:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinebreakBlock.java (with props)
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/linebreak.confluence
Modified:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/ConfluenceParser.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ParagraphBlockParser.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/ConfluenceParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/ConfluenceParser.java?rev=588573&r1=588572&r2=588573&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/ConfluenceParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/ConfluenceParser.java Fri Oct 26 02:13:56 2007
@@ -19,24 +19,24 @@
* 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.SectionBlockParser;
+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.VerbatimBlockParser;
-import org.apache.maven.doxia.module.confluence.parser.HorizontalRuleBlockParser;
-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.module.confluence.parser.table.TableBlockParser;
import org.apache.maven.doxia.parser.AbstractTextParser;
import org.apache.maven.doxia.parser.ParseException;
import org.apache.maven.doxia.sink.Sink;
-
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import org.apache.maven.doxia.util.ByLineReaderSource;
+import org.apache.maven.doxia.util.ByLineSource;
/**
* Parse the <a href="http://www.atlassian.com/software/confluence/">Confluence</a>.
@@ -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 )
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinebreakBlock.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinebreakBlock.java?rev=588573&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinebreakBlock.java (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinebreakBlock.java Fri Oct 26 02:13:56 2007
@@ -0,0 +1,35 @@
+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 org.apache.maven.doxia.sink.Sink;
+
+/**
+ * @author Dave Syer
+ * @since 1.0
+ */
+public class LinebreakBlock
+ implements Block
+{
+ public void traverse( Sink sink )
+ {
+ sink.lineBreak();
+ }
+}
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinebreakBlock.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/LinebreakBlock.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ParagraphBlockParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ParagraphBlockParser.java?rev=588573&r1=588572&r2=588573&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ParagraphBlockParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/ParagraphBlockParser.java Fri Oct 26 02:13:56 2007
@@ -20,16 +20,17 @@
*/
import java.util.ArrayList;
-import java.util.List;
import java.util.Arrays;
+import java.util.List;
-import org.apache.maven.doxia.util.ByLineSource;
import org.apache.maven.doxia.parser.ParseException;
+import org.apache.maven.doxia.util.ByLineSource;
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 );
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java?rev=588573&r1=588572&r2=588573&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java Fri Oct 26 02:13:56 2007
@@ -19,13 +19,20 @@
* under the License.
*/
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+
import org.apache.maven.doxia.parser.AbstractParserTest;
import org.apache.maven.doxia.parser.Parser;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.TextSink;
/**
* Test class for ConfluenceParser.
*/
-public class ConfluenceParserTest extends AbstractParserTest
+public class ConfluenceParserTest
+ extends AbstractParserTest
{
private ConfluenceParser parser;
@@ -49,5 +56,51 @@
{
return "confluence";
}
+
+ /** @throws Exception */
+ public void testLineBreak()
+ throws Exception
+ {
+ String lineBreak = getLineBreakString();
+
+ StringWriter output = null;
+ Reader reader = null;
+ Writer writer = null;
+
+ try
+ {
+ output = new StringWriter();
+ reader = getTestReader( "linebreak", outputExtension() );
+ writer = getTestWriter( "linebreak", "txt" );
+
+ Sink sink = new TextSink( output );
+ createParser().parse( reader, sink );
+
+ // write to file
+ String expected = output.toString();
+ writer.write( expected );
+ writer.flush();
+
+ assertTrue( expected.indexOf( "Line" + EOL + lineBreak ) != -1 );
+ assertTrue( expected.indexOf( "with 2" + EOL + lineBreak ) != -1 );
+ assertTrue( expected.indexOf( "inline" + EOL + lineBreak ) != -1 );
+ }
+ finally
+ {
+ output.close();
+ reader.close();
+ writer.close();
+ }
+ }
+
+ private String getLineBreakString()
+ {
+ StringWriter output = new StringWriter();
+ Sink sink = new TextSink( output );
+ sink.lineBreak();
+
+ return output.toString();
+ }
+
}
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/linebreak.confluence
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/linebreak.confluence?rev=588573&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/linebreak.confluence (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/linebreak.confluence Fri Oct 26 02:13:56 2007
@@ -0,0 +1,5 @@
+Line\\
+break.
+
+Line\\with 2\\inline\\
+Breaks.
\ No newline at end of file