fixed bug where headings contained elements (<span> or <a>) containing the text which resulted in headings with no text
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@114137 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -250,10 +250,30 @@ public class Html2XdocBean {
|
||||
} else {
|
||||
currentNode = currentSectionNode.addElement("subsection");
|
||||
}
|
||||
currentNode.addAttribute("name", node.getText());
|
||||
currentNode.addAttribute("name", getSectionText(node));
|
||||
currentParaNode = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the section text for the given node. If the node
|
||||
* contains an embedded element (such as an <a> element)
|
||||
* then return its text
|
||||
*/
|
||||
protected String getSectionText(Node node) {
|
||||
String text = node.getText().trim();
|
||||
if (text.length() <= 0 && node instanceof Element) {
|
||||
Element element = (Element) node;
|
||||
|
||||
// maybe we contain a hypertext link
|
||||
List childElements = element.elements();
|
||||
if (! childElements.isEmpty()) {
|
||||
Node child = (Node) childElements.get(0);
|
||||
return child.getText();
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a new section is needed which is based on whether
|
||||
* the node's a heading level and equal to or less than the current
|
||||
|
||||
@@ -101,6 +101,7 @@ public class TestHtml2Xdoc extends TestCase {
|
||||
// Test cases
|
||||
//-------------------------------------------------------------------------
|
||||
public void testOne() throws Exception {
|
||||
assertConversion("linkInHeading.html", "linkInHeading.xml");
|
||||
assertConversion("codeinpara.html", "codeinpara.xml");
|
||||
assertConversion("input1.html", "output1.xml");
|
||||
assertConversion("h1h2.html", "h1h2.xml");
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<!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>
|
||||
<a name="foo">the real title</a></h3>
|
||||
Some text
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
<document>
|
||||
<properties>
|
||||
<title>A title</title>
|
||||
</properties>
|
||||
<body>
|
||||
<section name="the real title">
|
||||
<p>Some text
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
Reference in New Issue
Block a user