[Fix] Improve math parsing validation#6030
Conversation
|
After doing some tests with pandoc, there's some inconsistent behavior. Newlines after the opening delimiter invalidate the inline math, but newlines before the closing delimiter do not. For example: Invalid: Valid: Maybe this is a pandoc bug? I feel like the newline before the closing delimiter should also be invalid. |
|
@tarleb Do you have more insight on this behavior? I think it makes sense to align the Zettlr parser as much as possible to the Pandoc behavior. |
|
Huh, interesting. That's probably a bug, as newlines before the closing |
|
FWIW I opened an issue here jgm/pandoc#11311 |
63360a8 to
c01cc07
Compare
c01cc07 to
7eafaa7
Compare
|
The pandoc issue has been cleared up! This implementation now matches the pandoc output (once a new version is released) |
nathanlesage
left a comment
There was a problem hiding this comment.
Just had a question, because the logic you've used seems a bit more involved, and just want to make sure I understand it!
|
Found a discrepancy between Pandoc and Zettlr:
|
The same happens with spaces around the delimiters. I think handling this case will actually make the parsing simpler, but it's going to be a significant refactor. I have an idea though and should have something up in a bit |
|
Ok, I think the solution was actually much simpler, no refactoring needed. This handles the edge case you presented. I think this is good to merge on my end, |
nathanlesage
left a comment
There was a problem hiding this comment.
I think this is good -- merging!
Description
This PR fixes two issues with inline single-delimiter math parsing I experienced while drafting a snippet in the main editor:
When a line contains a dollar sign, and the next line starts with a dollar sign, the content between is interpreted as math text.
When the closing delimiter is followed by a digit, the content is still interpreted as math despite the delimiter being invalid, according to pandoc docs.
It also better aligns the block math parser with pandoc so that blank lines are no longer valid within math blocks.
Changes
The whitespace tests were moved so that the tests are only performed when needed. This reduces unnecessary calculations.
The following changes are from what I understand of the pandoc docs on the delimiters:
The whitespace checks were refactored to a regex test for any whitespace character using
\s. I changed this because I interpreted the pandoc docs,must have a non-space character, to mean any whitespace.An additional test was added for closing delimiters to ensure they are not followed by a digit.
The whitespace and following-digit tests are ignored if the delimiter is for display math,
$$, which do not have limitations on preceding or following characters.The math block parser had an additional check added to make sure that no lines within the block are blank.
Additional information
Tested on: macOS 26