python-markdown extension for support mathjax
Project description
md4mathjax
this is a python-markdown extension. basicly learning from the pelican plugin render-math. and i think inside its code, the mathjax extension split would be better.
This Extension is writing in the Python-Markdown Recommend way, so basically it's usage can reference the Python-Markdown Extension Usage document.
本插件在写法是Python-Markdown的统一写法,因此使用可以参看Python-Markdown的插件使用文档。
原插件做了很多额外的工作,但现在mathjax对于数学公式写法上的支持已经很强大了,很多额外的工作都是没有必要的了。
本插件做的两个工作一就是检测markdown文档里面是否有数学公式,如果有则插入下面这段js代码。
<script>
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath: [["$$", "$$"], ['\\[', '\\]']],
packages: {
'[+]': ['mhchem']
}
},
loader: {
load: ['[tex]/mhchem']
},
}
</script>
<script id="MathJax-script" async src="{{SRC}}"></script>
这段代码用jinja2封装的,也就是后面可以进行更多的调配来提供对外参数接口。并没有在参数上额外封装,而直接是mathjax的配置,所以使用者直接参看mathjax文档即可。
本插件还有一个工作就是将检测到的数学公式封装进 class=math
的span或者div环境中。这给后续css调配提供了便利。
此外因为markdown的EscapeInlineProcessor机制存在,如果不进行处理 \(...\)
\[...\)
这两个写法都会出错的,本插件经过处理将数学公式统一转为 $...$
和 $$ ... $$
这样的形式了。
很简单直观的一个插件,同时又完成了必要的工作。tests文件夹下可以有输出html文件参考。
Usage
插件
参数
- auto_insert 默认True 是否根据文章有否数学公式来添加mathjax
- tag_class 默认 math
- mathjax_src 默认 https://cdn.jsdelivr.net/npm/mathjax@3.2.0/es5/tex-mml-chtml.js
CHANGELOG
0.1.1
yi
0.1.0
初步编写完成
pelican上使用:
MARKDOWN = {
'extensions': [
'md4mathjax'
],
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file md4mathjax-0.1.1.tar.gz
.
File metadata
- Download URL: md4mathjax-0.1.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca43aaa110fa7572e69cf75829503e387c91627a7fa71445eeca698ee3f18c0f |
|
MD5 | df5ceadc97699b4de70c4d3e59b6d095 |
|
BLAKE2b-256 | a2117a37ba800ed7c3117a263a4b30df773451413fac648be5c2db5848336bca |
File details
Details for the file md4mathjax-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: md4mathjax-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a41b20201e9e631d163f4afd8c48f3c888c11f01fd9d26ba29c67e08250c876b |
|
MD5 | 19b1738a2a24d7efebf271c376363826 |
|
BLAKE2b-256 | acf8c45a429044daf054459cce662e4a698e1de4a54e3a07d2caf538dbc84f25 |