Various fixes for the HTML plugin.
* recreate the converter bean for each file to avoid multiple files causing wierdness to occur on the handling of headings etc * added more test cases which used to highlight some issues, such as a nested <code> element inside some text markup git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@114136 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
aba19dd7ae
commit
e06898479c
8 files changed
+107
-21
No files matched your search
@@ -1,3 +1,5 @@
|
||||
target
|
||||
maven.log
|
||||
velocity.log
|
||||
bin
|
||||
.classpath
|
||||
@@ -24,9 +24,6 @@
|
||||
|
||||
<j:set var="outputencoding" value="${maven.docs.outputencoding}"/>
|
||||
|
||||
<!-- tool for converting HTML into XDoc -->
|
||||
<j:useBean class="org.apache.maven.html2xdoc.Html2XdocBean" var="htmlTool"/>
|
||||
|
||||
<!-- mapper for determining output file name -->
|
||||
<j:new var="mapper" className="org.apache.maven.util.CaseInsensitiveGlobPatternMapper"/>
|
||||
|
||||
@@ -56,6 +53,9 @@
|
||||
|
||||
<j:forEach var="file" items="${docFiles.iterator()}">
|
||||
|
||||
<!-- tool for converting HTML into XDoc -->
|
||||
<j:useBean class="org.apache.maven.html2xdoc.Html2XdocBean" var="htmlTool"/>
|
||||
|
||||
<util:replace var="inDirForward" oldChar="\" newChar="/" value="${file.parent}"/>
|
||||
<j:set var="outDir" value="${dirMapper.mapFileName(inDirForward).0}"/>
|
||||
<ant:mkdir dir="${outDir}"/>
|
||||
|
||||
@@ -295,8 +295,22 @@ public class Html2XdocBean {
|
||||
* @param node the node to add
|
||||
*/
|
||||
private void addNode(Node node) {
|
||||
currentNode.add(cloneNode(node));
|
||||
currentParaNode = null;
|
||||
if (currentParaNode != null && ! shouldBreakPara(node)) {
|
||||
currentParaNode.add(cloneNode(node));
|
||||
}
|
||||
else {
|
||||
currentNode.add(cloneNode(node));
|
||||
currentParaNode = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the paragraph should be split, such as for a br or p
|
||||
* tag
|
||||
*/
|
||||
protected boolean shouldBreakPara(Node node) {
|
||||
String name = node.getName();
|
||||
return name.equals("p") || name.equals("br");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,26 +65,18 @@ package org.apache.maven.html2xdoc;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.dom4j.CharacterData;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentFactory;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.Node;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
import org.cyberneko.html.parsers.SAXParser;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import org.cyberneko.html.parsers.SAXParser;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
/**
|
||||
* A test harness for the HTML to XDOC converter
|
||||
*
|
||||
@@ -92,6 +84,8 @@ import junit.textui.TestRunner;
|
||||
*/
|
||||
public class TestHtml2Xdoc extends TestCase {
|
||||
|
||||
protected boolean verbose = false;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
TestRunner.run( suite() );
|
||||
}
|
||||
@@ -107,11 +101,14 @@ public class TestHtml2Xdoc extends TestCase {
|
||||
// Test cases
|
||||
//-------------------------------------------------------------------------
|
||||
public void testOne() throws Exception {
|
||||
assertConversion("codeinpara.html", "codeinpara.xml");
|
||||
assertConversion("input1.html", "output1.xml");
|
||||
assertConversion("h1h2.html", "h1h2.xml");
|
||||
assertConversion("h3h4.html", "h1h2.xml");
|
||||
assertConversion("h2h3.html", "h1h2.xml");
|
||||
assertConversion("h2h4.html", "h1h2.xml");
|
||||
assertConversion("h3h4.html", "h1h2.xml");
|
||||
assertConversion("link.html", "link.xml");
|
||||
assertConversion("comment.html", "comment.xml");
|
||||
assertConversion("comment.html", "comment.xml");
|
||||
}
|
||||
|
||||
// Implementation methods
|
||||
@@ -119,9 +116,19 @@ public class TestHtml2Xdoc extends TestCase {
|
||||
protected void assertConversion(String input, String output) throws Exception {
|
||||
Html2XdocBean converter = createConverter();
|
||||
Document inputDoc = parseHtml(input);
|
||||
|
||||
|
||||
Document expectedDoc = parse(output);
|
||||
|
||||
Document actualDoc = converter.convert(inputDoc);
|
||||
|
||||
if (verbose) {
|
||||
System.out.println("Comparing: " + input + " to: " + output);
|
||||
System.out.println("Parsed: " + inputDoc.asXML());
|
||||
System.out.println("Generated: " + actualDoc.asXML());
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
assertEqual("Output for: " + input + " does not match: " + output, expectedDoc, actualDoc);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
|
||||
<title>A title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h3>Title</h3>
|
||||
Some text <code>some code</code> more text
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
<document>
|
||||
<properties>
|
||||
<title>A title</title>
|
||||
</properties>
|
||||
<body>
|
||||
<section name="Title">
|
||||
<p>Some text <code>some code</code> more text
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
|
||||
<title>A title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>A section title</h2>
|
||||
|
||||
Some text
|
||||
<br/>
|
||||
More text
|
||||
|
||||
<h3>a subsection</h3>
|
||||
|
||||
This is a subsection. It only has this.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
|
||||
<title>A title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>A section title</h2>
|
||||
|
||||
Some text
|
||||
<br/>
|
||||
More text
|
||||
|
||||
<h4>a subsection</h4>
|
||||
|
||||
This is a subsection. It only has this.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user