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

Inconsistent TextCollectingVisitor behaviour with code blocks #574

Closed
roxspring opened this issue May 15, 2023 · 1 comment · Fixed by #575
Closed

Inconsistent TextCollectingVisitor behaviour with code blocks #574

roxspring opened this issue May 15, 2023 · 1 comment · Fixed by #575

Comments

@roxspring
Copy link
Contributor

The TextCollectingVisitor appears to have inconsistent behaviour with IndentedCodeBlock vs FencedCodeBlock.
The former doesn't have its text collected at all while the latter does but drops line breaks before hand.

To reproduce, run the following code using version 0.64.4:

final String markdown = "" +
    "Introductory para:\n" +
    "\n" +
    "```\n" +
    "Fenced\n" +
    "```\n" +
    "\n" +
    "    Indented\n" +
    "\n";
String text = new TextCollectingVisitor().collectAndGetText(Parser.builder().build().parse(markdown));
System.out.println(text);

The surprising result of this is to print out the following, notably with Fenced coalesced onto the previous line and Indented omitted entirely:

Introductory para:Fenced

I would expect that the TextCollectingVisitor would both pieces of text, with newlines intact:

Introductory para:

Fenced

Indented
@roxspring
Copy link
Contributor Author

A cursory play with the debugger makes me wonder whether FencedCodeBlock ought to implement BlankLineBreakNode so that out.appendEol() gets called at the start of each occurrence?

It appears that IndentedCodeBlock doesn't play nicely because it handles content directly rather than via child Text nodes. Maybe that implies that IndentedCodeBlock should implement TextContainer? I'm guessing transitioning to using Text child nodes is a big change.

Happy to open a PR or two to address these, but might need some guidance as to the right solutions first!

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

Successfully merging a pull request may close this issue.

1 participant