Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.74k stars 858 forks source link

How to integrate arithmatex with python-markdown? #1386

Closed JTP-123 closed 11 months ago

JTP-123 commented 11 months ago

As a new beginner, I decided to make my small tiny flask blog support math formula, so I chose arithmatex under python-markdown. After I have read offical documentation, i made such configuration as follows, namely I put mathjax cdn link at the bottom of the block script of base.html template, arithmatex is included by markdown function. But it doesn't work. Can anyone give me a favor? thank you.

include arithmatex

def on_changed_body(target, value, oldvalue, initiator): allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code', # define allowed html tags for Markdown 'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul', 'h1', 'h2', 'h3', 'p', 'img', 'kbd', 'sup', 'sub', 'br', 'table', 'footer', 'thead', 'tbody', 'tr', 'th', 'td', 'small', 'big'] extensions = ['pymdownx.arithmatex', 'pymdownx.b64', 'pymdownx.emoji'] target.body_html = bleach.linkify(bleach.clean( markdown(value, output_format='html', extensions=extensions, extension_configs={ "pymdownx.arithmatex": { "generic": True } }), tags=allowed_tags, strip=True))

part of base.html: {% block scripts %} ... // other script code like moment.js, self-defined js function

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async 
        src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>

{% endblock %}

but after my configuration ends, it still produces a plain text, not math formula: 批注 2023-10-06 131915

facelessuser commented 11 months ago

Python Markdown is not the appropriate place to ask questions about 3rd party extensions. You already asked in the appropriate place: https://github.com/facelessuser/pymdown-extensions/discussions/2192, and I've answered as best as can be done.

You need to debug your flask app to find what you are doing wrong. I've already provided you with a working example you can compare against.