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

dollarmath: Add allow_blank_lines option #46

Merged
merged 11 commits into from
Mar 6, 2023

Conversation

eric-wieser
Copy link
Contributor

@eric-wieser eric-wieser commented Jun 29, 2022

Closes #45 behind a non-default allow_blank_lines=False flag.

Note this means that the default behavior of the javascript and python implementations has diverged.

@welcome
Copy link

welcome bot commented Jun 29, 2022

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out EBP's Code of Conduct and our Contributing Guide, as this will greatly help the review process.

Welcome to the EBP community! 🎉

@eric-wieser
Copy link
Contributor Author

I think a maintainer (@chrisjsewell?) has to click some sort of approval button in order for CI to run, to verify that I'm not mining cryptocurrency in this PR?

@@ -302,15 +302,14 @@ def _math_block_dollar(
start = state.bMarks[nextLine] + state.tShift[nextLine]
end = state.eMarks[nextLine]

if end - start < 2:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should stay (but break not continue) to safeguard against any index errors

Copy link
Contributor Author

@eric-wieser eric-wieser Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't exist any more in the javascript version, why would you want to keep it in the Python version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because JavaScript does not act the same as Python; if you index a JavaScript array with "bad indexes" it will simply return null, whereas in python it will raise an indexerror.
There has been multiple bug fixed for this in markdown-it-py

Copy link
Contributor Author

@eric-wieser eric-wieser Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only indexing that takes place is state.src[start:end], and that will never give an IndexError. If start=end then it will return "", but that's absolutely fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rowanc1: what can we do to progress here?

@eric-wieser
Copy link
Contributor Author

@chrisjsewell: this is what I am referring to:

image

@codecov
Copy link

codecov bot commented Jul 3, 2022

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.05 🎉

Comparison is base (be14587) 92.84% compared to head (65d763a) 92.90%.

❗ Current head 65d763a differs from pull request most recent head 5412706. Consider uploading reports for the commit 5412706 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #46      +/-   ##
==========================================
+ Coverage   92.84%   92.90%   +0.05%     
==========================================
  Files          30       30              
  Lines        1748     1748              
==========================================
+ Hits         1623     1624       +1     
+ Misses        125      124       -1     
Flag Coverage Δ
pytests 92.90% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mdit_py_plugins/dollarmath/index.py 91.07% <100.00%> (+0.59%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@eric-wieser
Copy link
Contributor Author

I assume the CI failure due to a bad interaction between click and black is bogus? Thanks for triggering the CI run.

@eric-wieser
Copy link
Contributor Author

Can I do anything to help this to go through?

@chrisjsewell
Copy link
Member

chrisjsewell commented Mar 3, 2023

Can I do anything to help this to go through?

I feel this behaviour needs to be under a options flag, (a) because it is a breaking change and (b) because

This matches the behavior of LaTeX (and of the stackexchange and github markdown parsers), and prevents runaway parsing if a $$ is opened but not closed.

I would suggest this is not always the desired behaviour in MyST
Firstly because in MyST they are partially intended to be a shorthand for: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-math, which can have blank lines (and quite probably there is already people using this feature),
and (b) "runaway parsing" is actually a feature of Markdown not a bug, both fence blocks https://spec.commonmark.org/0.30/#example-126, and (extended) markdown div blocks https://htmlpreview.github.io/?https://github.com/jgm/djot/blob/master/doc/syntax.html#div are both "runaway" (and there are design reasons for this)

@chrisjsewell
Copy link
Member

I think there is also a potentially critical difference between block level $$ and inline $$;
inline $$ already does not allow blank lines

@eric-wieser
Copy link
Contributor Author

Does this mean you would advocate for the change to be reverted on the javascript side?

@chrisjsewell
Copy link
Member

Does this mean you would advocate for the change to be reverted on the javascript side?

Oh I'm not touching lol. Just let's add it in here as a feature flag, and I think that's a good compromise

@eric-wieser
Copy link
Contributor Author

I would suggest this is not always the desired behaviour in MyST Firstly because in MyST they are partially intended to be a shorthand for: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-math, which can have blank lines (and quite probably there is already people using this feature)

The semantics of .. math:: is to auto-insert an align environment when multiple lines are provided. This is pretty non-standard for a latex parser, possibly suggesting that the MyST behavior ought to be behind a flag

and (b) "runaway parsing" is actually a feature of Markdown not a bug, both fence blocks https://spec.commonmark.org/0.30/#example-126, and (extended) markdown div blocks https://htmlpreview.github.io/?https://github.com/jgm/djot/blob/master/doc/syntax.html#div are both "runaway" (and there are design reasons for this)

I agree; but on the other hand, it seems more valuable to match what the consensus seems to be among major implementations, rather than extrapolate from a spec that doesn't actually specify the behavior here!

Can I convince you of a feature flag where the default is the new behavior, or is that going to break too many things?

@chrisjsewell
Copy link
Member

Can I convince you of a feature flag where the default is the new behavior, or is that going to break too many things?

Yeh just to much possibility for breakage for the outset. Of course once it is in there then it's easy to control, if defaults need to be changed

@eric-wieser
Copy link
Contributor Author

Alright, I've added the flag to default to the old behavior.

@eric-wieser
Copy link
Contributor Author

eric-wieser commented Mar 3, 2023

Note that the tests won't run until you approve them (not the PR, just the "yes you didn't mine crypto in CI" button):

image

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers Eric

@chrisjsewell chrisjsewell changed the title port executablebooks/markdown-it-dollarmath#8 dollarmath: Add allow_blank_lines option Mar 6, 2023
@chrisjsewell chrisjsewell merged commit 061a544 into executablebooks:master Mar 6, 2023
@welcome
Copy link

welcome bot commented Mar 6, 2023

Congrats on your first merged pull request in this project! 🎉
congrats

Thank you for contributing, we are very proud of you! ❤️

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.

Do not allow blank lines within $$
2 participants