Author: jvanzyl
Date: Thu Dec 14 15:41:09 2006
New Revision: 487395
URL: http://svn.apache.org/viewvc?view=rev&rev=487395
Log:
DOXIA-81: The Xhtml parser called pageBreak instead of lineBreak on <br />
elements.
Submitted by: Eric Redmond
Modified:
maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
Modified:
maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
URL:
http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java?view=diff&rev=487395&r1=487394&r2=487395
==============================================================================
---
maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
(original)
+++
maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
Thu Dec 14 15:41:09 2006
@@ -16,15 +16,15 @@
* limitations under the License.
*/
+import java.io.Reader;
+import java.util.Stack;
+
import org.apache.maven.doxia.parser.ParseException;
import org.apache.maven.doxia.parser.Parser;
import org.apache.maven.doxia.sink.Sink;
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
-import java.io.Reader;
-import java.util.Stack;
-
/**
* Parse an xdoc model and emit events into the specified doxia
* Sink.
@@ -181,7 +181,7 @@
}
else if ( parser.getName().equals( "br" ) )
{
- sink.pageBreak();
+ sink.lineBreak();
}
else if ( parser.getName().equals( "hr" ) )
{
@@ -200,13 +200,13 @@
if ( title != null )
{
sink.figureCaption();
- sink.text( title );
+ text( sink, title );
sink.figureCaption_();
}
else if ( alt != null )
{
sink.figureCaption();
- sink.text( alt );
+ text( sink, alt );
sink.figureCaption_();
}
sink.figure_();
@@ -329,11 +329,37 @@
}
else if ( eventType == XmlPullParser.TEXT )
{
- sink.text( parser.getText() );
+ text( sink, parser.getText() );
}
eventType = parser.next();
}
+ }
+
+ /**
+ * Sends the text to the sink, utilizing the nonBreakingspace of the sink.
+ * @param sink
+ * @param text
+ */
+ private static void text( Sink sink, String text )
+ {
+ if( text.startsWith( " " ) )
+ {
+ sink.nonBreakingSpace();
+ }
+ String[] s = text.split( " " );
+ for( int i = 0; i < s.length; i++ )
+ {
+ sink.text( s[i] );
+ if( i + 1 < s.length )
+ {
+ sink.nonBreakingSpace();
+ }
+ }
+ if( text.endsWith( " " ) )
+ {
+ sink.nonBreakingSpace();
+ }
}
private void closeSubordinatedSections( String level, Sink sink )