Skip to content

Keep partially consumed tab when an HTML block starts or continues in a block quote - #462

Open
Shaisolaris wants to merge 1 commit into
commonmark:mainfrom
Shaisolaris:fix-html-block-partial-tab
Open

Shaisolaris wants to merge 1 commit into
commonmark:mainfrom
Shaisolaris:fix-html-block-partial-tab

Conversation

@Shaisolaris

Copy link
Copy Markdown

When a tab after > is only partly used up by the block quote marker, the rest of the tab is supposed to become spaces in the content, as it already does for paragraphs and indented code. For HTML blocks it is lost and the raw tab ends up in the output:

Input commonmark-java cmark / commonmark.js
>\t<div> <blockquote>\n\t<div>\n</blockquote>\n <blockquote>\n <div>\n</blockquote>\n
> <div>\n>\tfoo ...<div>\n\tfoo\n... ...<div>\n foo\n...

HtmlBlockParser starts and continues with atIndex(state.getIndex()), meaning "stay where we are". DocumentParser.setNewIndex() always clears columnIsInTab, even when the index does not move, so addLine() no longer expands the remaining tab columns. The fix returns early from setNewIndex() when the new index equals the current one, which leaves the partial tab state alone.

Tests: two cases in SpecialInputTest, with expected output taken from cmark (cmarkgfm, unsafe mode) and commonmark.js 0.31, which agree. They fail on main and pass with the change. mvn test across all modules passes (1959 tests, including the spec tests), and spotless:check is clean.

I found this by comparing commonmark-java with commonmark.js on random inputs. Two other differences turned up that I have not touched here: trailing blank lines at the end of an unclosed HTML comment block, and info strings containing a tab.

This branch has not been deployed

No deployments
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 this pull request may close these issues.

1 participant