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

Add optional support for math syntax #142

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

jonatanklosko
Copy link
Collaborator

Adds support for mathematical expressions with $ and $$. This is far from standardised, but GitHub now supports math expressions, so I think having an optional extension is justified.

For more context, now that there are more Nx-based packages it's becoming common to write math expressions docs. Math rendering is left to the user (by extending ExDoc), however there are issues if the math is not understood at parser level. For example $x *y* x would be parsed as emphasis, hence destroying the original expression. See elixir-lang/ex_doc#1571.

This implementation should match GitHub for the most part. There are tiny differences, for example:

  • GitHub parsing has bugs - in the docs they say \$ should work within expression, but it actually only \\$ works
  • to escape inline math GitHub uses <span>$</span>, but EarmarkParses doesn't support inline HTML; and also I don't see a good reason to not support \$ as with all other delimiters

I looked around and tried to come up with reasonable rules as outlined by the test suite. I also added a note to the docs that this feature is a subject to future changes, it should be fine to do further adjustments as needed, as long as we keep AST compatibility.

As for the AST, I used <code> with .math-inline and .math-display. As far as I can tell, display-style math is generally included within a paragraph (so it's still falls under "inline" parsing). I didn't use <pre> for display-style math because <pre> is not allowed within <p>, but I think that's fine.

@@ -25,6 +25,7 @@
- [Pure links](#pure-links)
- [Wikilinks...](#wikilinks)
- [Sub and Sup HTML Elements](#sub-and-sup-html-elements)
- [Mathematical expressions](#mathematical-expressions)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I couldn't find the readme task, so I mirrored the changes from moduledoc manually. Let me know if/how I should generate it :)

Copy link
Owner

Choose a reason for hiding this comment

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

Done it is mix xtra I guess I should document that somewhere, maybe contribution notes/rules?

Copy link
Owner

Choose a reason for hiding this comment

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

Also done 😊

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah it comes from an external package, that makes sense, thanks!

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.

3 participants