Conversation
137fc23 to
bfe2c5a
Compare
bfe2c5a to
f8f7684
Compare
|
cc @robinst |
commonmark/src/main/java/org/commonmark/internal/DocumentParser.java
Outdated
Show resolved
Hide resolved
robinst
left a comment
There was a problem hiding this comment.
Changes to DocumentParser, Parser, ParserTest LGTM, with some minor comments to address.
The visitor changes: Can you take them out of this PR? I'm not sure I want to include this by default on every visitor, and it's something that's pretty straightforward to add in subclasses (overriding the protected visitChildren method).
| } | ||
|
|
||
| /** | ||
| * Limit how many non-document block parsers may be open at once while parsing. |
There was a problem hiding this comment.
The top-level block parser is really an implementation detail, no need to mention it prominently:
| * Limit how many non-document block parsers may be open at once while parsing. | |
| * Limit how many block parsers may be open at once while parsing. |
| } | ||
|
|
||
| private String renderText(Node node) { | ||
| return TextContentRenderer.builder().build().render(node).trim(); |
There was a problem hiding this comment.
Let's use a MarkdownRenderer instead (TextContentRenderer is an arbitrary plain text format, we don't want to rely on it for tests):
| return TextContentRenderer.builder().build().render(node).trim(); | |
| return MarkdownRenderer.builder().build().render(node).trim(); |
| node.accept(this); | ||
| } finally { | ||
| currentDepth--; | ||
| } |
There was a problem hiding this comment.
Incrementing and decrementing should probably be done outside the while loop, just once?
Why
I want to limit the max depth of node traversal.
What
Apply an optional limit to the depth of node parsing.
We make a conscious design choice to drop nodes that are too deep, instead of failing fast.
We apply the limit when constructing the AST, by dropping deeper node generation (we collapse it into plain text).
When visiting the AST, we apply a depth limit again and drop deep nodes altogether.
The two depths correspond to different meaning, and aren't semantically the same.