Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing nested lists with HTMLWorker #288

Closed
rammetzger opened this issue Oct 18, 2019 · 2 comments
Closed

Parsing nested lists with HTMLWorker #288

rammetzger opened this issue Oct 18, 2019 · 2 comments

Comments

@rammetzger
Copy link

The HTMLWorker.parseToList() method has a bug when parsing nested lists, e.g.

<ol>
	<li>Element-1
		<ol>
			<li>Element-1-1</li>
			<li>Element-1-2</li>
		</ol>
	</li>
	<li>Element-2
		<ol>
			<li>Element-2-1</li>
			<li>Element-2-2</li>
		</ol>
	</li>
</ol>

As a result, only the first-level elements are returned: ['Element-1', 'Element-2'].

The bug is in the HTMLWorker.endElement() method:

542: 	if (tag.equals(HtmlTags.UNORDEREDLIST)
543:		|| tag.equals(HtmlTags.ORDEREDLIST)) {
...
558:	((TextElementArray) stack.peek()).add((Element) obj);

For nested lists, variable 'obj' is of type 'com.lowagie.text.List', but it is casted to type 'Element'. Therefore the method 'add(Element o)' is called, but this method does not handle lists.
The proper method is 'add(List nested)' in class 'com.lowagie.text.List'. So the above code should look like this:

558:	{
559:		Object peek = stack.peek();
560:		if (peek instanceof com.lowagie.text.List && obj instanceof com.lowagie.text.List) {
561:			((com.lowagie.text.List) peek).add((com.lowagie.text.List) obj);
562:		}
563:		else 
564:		{
565:			((TextElementArray) peek).add((Element) obj);
566:		}                  
567:	}

Please fix this bug so we can use the official version again. Thank you in advance.

Best regards
Michael

@sixdouglas
Copy link
Contributor

@rammetzger can you check my PR and tell me what would be the expected result?

@andreasrosdal
Copy link
Contributor

This has been merged to the master branch now.
@rammetzger @sixdouglas Can you please confirm that this is working as expected now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants