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/11/22 10:27:23 UTC
svn commit: r597348 - 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: Thu Nov 22 01:27:22 2007
New Revision: 597348
URL: http://svn.apache.org/viewvc?rev=597348&view=rev
Log:
[DOXIA-171] add {quote, tip, note, info} macros
Submitted by: Dave Syer
Added:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/DefinitionListBlock.java (with props)
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/DefinitionListBlockParser.java (with props)
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/note-tip-info.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/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/code.confluence
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=597348&r1=597347&r2=597348&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 Thu Nov 22 01:27:22 2007
@@ -26,6 +26,7 @@
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.DefinitionListBlockParser;
import org.apache.maven.doxia.module.confluence.parser.FigureBlockParser;
import org.apache.maven.doxia.module.confluence.parser.HorizontalRuleBlockParser;
import org.apache.maven.doxia.module.confluence.parser.ParagraphBlockParser;
@@ -58,6 +59,7 @@
BlockParser headingParser = new SectionBlockParser();
BlockParser figureParser = new FigureBlockParser();
BlockParser verbatimParser = new VerbatimBlockParser();
+ BlockParser definitionParser = new DefinitionListBlockParser();
BlockParser horizontalRuleParser = new HorizontalRuleBlockParser();
BlockParser listParser = new ListBlockParser();
BlockParser tableParser = new TableBlockParser();
@@ -66,8 +68,8 @@
BlockParser paragraphParser = new ParagraphBlockParser( subparsers );
parsers =
- new BlockParser[] { headingParser, figureParser, verbatimParser, horizontalRuleParser, listParser,
- tableParser, paragraphParser };
+ new BlockParser[] { headingParser, figureParser, verbatimParser, definitionParser, horizontalRuleParser,
+ listParser, tableParser, paragraphParser };
}
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/DefinitionListBlock.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/DefinitionListBlock.java?rev=597348&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/DefinitionListBlock.java (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/DefinitionListBlock.java Thu Nov 22 01:27:22 2007
@@ -0,0 +1,65 @@
+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.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.doxia.sink.Sink;
+import org.codehaus.plexus.util.StringUtils;
+
+public class DefinitionListBlock
+ implements Block
+{
+
+ private String title;
+
+ private List text;
+
+ public DefinitionListBlock( String title, String text )
+ {
+ this.title = title;
+ this.text = new ChildBlocksBuilder( text ).getBlocks();
+ }
+
+ public void traverse( Sink sink )
+ {
+ sink.definitionList();
+
+ if ( !StringUtils.isEmpty( title ) )
+ {
+ sink.definedTerm();
+ sink.text( title );
+ sink.definedTerm_();
+ }
+
+ sink.definition();
+
+ for ( Iterator iterator = text.iterator(); iterator.hasNext(); )
+ {
+ Block block = (Block) iterator.next();
+ block.traverse( sink );
+ }
+
+ sink.definition_();
+ sink.definitionList_();
+ }
+
+}
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/DefinitionListBlock.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/DefinitionListBlock.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/DefinitionListBlockParser.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/DefinitionListBlockParser.java?rev=597348&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/DefinitionListBlockParser.java (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/DefinitionListBlockParser.java Thu Nov 22 01:27:22 2007
@@ -0,0 +1,87 @@
+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.parser.ParseException;
+import org.apache.maven.doxia.util.ByLineSource;
+
+/**
+ * @author Dave Syer
+ * @version $Id$
+ */
+public class DefinitionListBlockParser
+ implements BlockParser
+{
+ static String LS = System.getProperty( "line.separator" );
+
+ public boolean accept( String line, ByLineSource source )
+ {
+ return ( line.startsWith( "{note" ) || line.startsWith( "{tip" )
+ || line.startsWith( "{info" ) || line.startsWith( "{quote" ) );
+ }
+
+ public Block visit( String line, ByLineSource source )
+ throws ParseException
+ {
+ StringBuffer text = new StringBuffer();
+ StringBuffer title = new StringBuffer();
+
+ int index = line.indexOf( "title=" );
+
+ if ( index >= 0 )
+ {
+ line = line.substring( index + 6 );
+
+ while ( !( line.indexOf( "}" ) >= 0 ) && line != null )
+ {
+ append( title, line );
+ line = source.getNextLine();
+ }
+
+ if ( line != null )
+ {
+ append( title, line.substring( 0, line.indexOf( "}" ) ) );
+ }
+ }
+
+ while ( ( line = source.getNextLine() ) != null )
+ {
+ if ( line.startsWith( "{note" ) || line.startsWith( "{tip" )
+ || line.startsWith( "{info" ) || line.startsWith( "{quote" ) )
+ {
+ break;
+ }
+
+ append( text, line );
+ }
+
+ return new DefinitionListBlock( title.toString(), text.toString() );
+ }
+
+ private void append( StringBuffer title, String line )
+ {
+ if ( title.length() > 0 )
+ {
+ title.append( " " );
+ }
+
+ title.append( line.trim() );
+ }
+}
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/DefinitionListBlockParser.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/DefinitionListBlockParser.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
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=597348&r1=597347&r2=597348&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 Thu Nov 22 01:27:22 2007
@@ -313,6 +313,27 @@
assertEquals( 3, result.split( "end:monospaced\n" ).length );
}
+ /** @throws Exception */
+ public void testNoteInfoTipQuote()
+ throws Exception
+ {
+ String result = locateAndParseTestSourceFile( "note-tip-info" );
+
+ assertContainsLines( result, "begin:definedTerm\ntext: Be Careful\nend:definedTerm\n" );
+ assertContainsLines( result, "begin:definition\ntext: The body of the note here..\nend:definition" );
+ assertContainsLines( result, "begin:definedTerm\ntext: Guess What?\nend:definedTerm\n" );
+ assertContainsLines( result, "begin:definition\ntext: The body of the tip here..\nend:definition" );
+ assertContainsLines( result, "begin:definedTerm\ntext: Some Info\nend:definedTerm\n" );
+ assertContainsLines( result, "begin:definition\ntext: The body of the info here..\nend:definition" );
+ assertContainsLines( result, "begin:definedTerm\ntext: Simon Says\nend:definedTerm\n" );
+ assertContainsLines( result, "begin:definition\ntext: The body of the \nbegin:bold\ntext: quote\nend:bold" );
+
+ // 5 paragraphs in the input...
+ assertEquals( 6, result.split( "end:paragraph\n" ).length );
+ // 4 dinitionList in the input...
+ assertEquals( 5, result.split( "end:definitionList\n" ).length );
+ }
+
private void assertContainsLines( String message, String result, String lines )
{
lines = StringUtils.replace( lines, "\n", EOL );
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/code.confluence
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/code.confluence?rev=597348&r1=597347&r2=597348&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/code.confluence (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/code.confluence Thu Nov 22 01:27:22 2007
@@ -18,4 +18,4 @@
}
}
{code}
-in the same paragraph (this doesn't work right now DOXIA-181).
\ No newline at end of file
+in the same paragraph (this didn't work until DOXIA-181).
\ No newline at end of file
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/note-tip-info.confluence
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/note-tip-info.confluence?rev=597348&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/note-tip-info.confluence (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/resources/note-tip-info.confluence Thu Nov 22 01:27:22 2007
@@ -0,0 +1,27 @@
+Simple paragraph.
+
+{note:title=Be Careful}
+The body of the note here..
+{note}
+
+Tip
+
+{tip:title=Guess What?}
+The body of the tip here..
+{tip}
+
+Info
+
+{info:title=Some
+Info}
+The body of the info here..
+{info}
+
+Quote
+
+{quote:title=Simon Says}
+The body of the *quote* here..
+{quote}
+
+(In all cases there is no way to reverse the Doxia output
+back to confluence because they are all rendered as a defitionList.)
\ No newline at end of file