Index: doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java =================================================================== --- doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java (revision 628460) +++ doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java (working copy) @@ -567,15 +567,26 @@ { String text = parser.getText(); - if ( StringUtils.isNotEmpty( text.trim() ) ) + /* + * NOTE: Don't do any whitespace trimming here. Whitespace normalization has already been performed by the + * parser so any whitespace that makes it here is significant. + */ + if ( StringUtils.isNotEmpty( text ) ) { - // emit separate text events for different lines - String[] lines = StringUtils.split( text, EOL ); + // Emit separate text events for different lines, e.g. the input "\nLine1\n\nLine2\n\n" should deliver the + // event sequence "\n", "Line1\n", "\n", "Line2\n", "\n". In other words, the concatenation of the text + // events must deliver the input sequence. + // (according to section 2.11 of the XML spec, parsers must normalize line breaks to "\n") + String[] lines = text.split( "\n", -1 ); - for ( int i = 0; i < lines.length; i++ ) + for ( int i = 0; i < lines.length - 1; i++ ) { - sink.text( lines[i] ); + sink.text( lines[i] + EOL ); } + if ( lines[lines.length - 1].length() > 0 ) + { + sink.text( lines[lines.length - 1] ); + } } }