Skip to content

Commit

Permalink
feat: support markdown style math tags
Browse files Browse the repository at this point in the history
We can configure MathJax to detect the convention of single dollar signs
in addition to its other methods, as it's not on by default.

The inline script needs to be supported by our CSP, and if the stanza
ever changes, we'll need to recalculate the hash and update the CSP
accordingly.

Resolves pypi#12009
Resolves pypa/readme_renderer#214

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
  • Loading branch information
miketheman committed Aug 30, 2022
1 parent d83b36f commit bf950d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/unit/test_csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def test_includeme():
"'sha256-U3hKDidudIaxBDEzwGJApJgPEf2mWk6cfMWghrAa6i0='",
"https://cdn.jsdelivr.net/npm/mathjax@3.2.2/",
"'sha256-1CldwzdEg2k1wTmf7s5RWVd7NMXI/7nxxjJM2C4DqII='",
"'sha256-0POaN8stWYQxhzjKS+/eOfbbJ/u4YHO5ZagJvLpMypo='",
],
"style-src": [
"'self'",
Expand Down
3 changes: 3 additions & 0 deletions warehouse/csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def includeme(config):
"https://cdn.jsdelivr.net/npm/mathjax@3.2.2/",
# Hash for v3.2.2 of MathJax tex-svg.js
"'sha256-1CldwzdEg2k1wTmf7s5RWVd7NMXI/7nxxjJM2C4DqII='",
# Hash for MathJax inline config
# See warehouse/templates/packaging/detail.html
"'sha256-0POaN8stWYQxhzjKS+/eOfbbJ/u4YHO5ZagJvLpMypo='",
],
"style-src": [
SELF,
Expand Down
7 changes: 7 additions & 0 deletions warehouse/templates/packaging/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ <h3>
{% endblock %}

{% block extra_js %}
<script>
MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
},
};
</script>
<script async
src="https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-svg.js"
integrity="sha256-1CldwzdEg2k1wTmf7s5RWVd7NMXI/7nxxjJM2C4DqII="
Expand Down

0 comments on commit bf950d3

Please sign in to comment.