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

Magic Editor doesn't support formula blocks #182

Open
MdoubleDash opened this issue Mar 19, 2020 · 2 comments
Open

Magic Editor doesn't support formula blocks #182

MdoubleDash opened this issue Mar 19, 2020 · 2 comments

Comments

@MdoubleDash
Copy link
Contributor

MdoubleDash commented Mar 19, 2020

As noted here, some of the communities are using MathJax to render formulas. Anything between single or double dollar signs will be considered a formula ($...$ or $$...$$).

There would be concerns about false positives, like the ones @makyen mentioned here #181:

(e.g. someone providing a list of prices in $, would look like multiple blocks of $...$)

Short answer to this specific concern would be that in those communities, one needs to escape the dollar sign (\$) if they actually want to have it as is and not as indication of start/end of formulas.

Refer to to Match everything Between two Characters except when there is a Blank line for a detailed explanation of what should be considered a formula-block.

In the SO post above, The fourth bird's answer provides a regex that would match formula blocks and would not return false positives.

(?<!\S)(\$\$?+)[^\r\n$]*(?:\$(?!\$)[^\r\n$]*)*(?:\r?\n(?![^\S\r\n]*$)[^\r\n$]*(?:\$(?!\$)[^\r\n$]*)*)*\1(?!\S)

Regex101 demo

Wiktor Stribiżew's comment -- DEMO:

/^[^\S\r\n]*(\${1,2})(?:(?!\1|^$)[\s\S])+?\1[^\S\r\n]*$/gm

There is also a matter of implementing this only for communities which support MatchJax.

@makyen
Copy link
Contributor

makyen commented Mar 19, 2020

Thanks for creating an issue.

Just an FYI wrt. your SO question: If you want a regex that works in JavaScript (i.e. in MagicEditor), you need to specify JavaScript in your SO question. There are many flavors of regular expressions, which all support different sets of features. Specific to the question you linked above, JavaScript supports neither lookbehind, nor possessive quantifiers, so the regex in the answer isn't viable for MagicEditor as written.

However, having definite examples of what should be detected and should be excluded, like what's included in the regex101 link you provided, helps quite a bit. Thanks.

It helps quite a bit to know that $ must be escaped on sites which support MathJax. It's relatively easy to determine if a site supports MathJax. So, using the combination of those two makes it easier to avoid false positives.

As to generating a regex to identify MathJax, I appreciate the effort, but we'll probably generate our own, or look at what MathJax uses to identify the blocks it's going to act upon.

@MdoubleDash
Copy link
Contributor Author

I just wanted to add that matching code-blocks should have priority over formulas. Imagine a meta post that is trying to explain how to write formulas. They would either use grave accents or 4+ leading spaces. Just another special case to have in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants