Problem
我一直在使用(Python) Sphinx 文档 http://www.sphinx-doc.org/, 随着通用标志 http://commonmark.org/解析器,用于编写包含以 reStructuredText 和 Markdown 编写的文件的 Sphinx 文档。到目前为止一切顺利,效果非常好(请参阅 Sphinx 示例中的这一行conf.py file https://bitbucket.org/lbesson/web-sphinx/src/master/conf.py?fileviewer=file-view-default#conf.py-157).
然而,CommonMark 对 GitHub 风格的 Markdown (GFM) 的支持并不完美,它缺少的一个重要功能是emoji。
我搜索了其他 Markdown 解析器,例如更具体的 GFMpy-gfm https://py-gfm.readthedocs.io/en/latest/,但似乎都不支持表情符号。
For instance, the screenshot below shows the Sphinx output on the left, and the GitHub rendered version on the right:
所以我的问题是:
- 有谁知道 Sphinx 扩展可以在 rST 和/或 Markdown 中添加对类似 GFM 的表情符号的支持? (即,表情符号写成
:boom:
this).
- 或者我可以用来转换任何表情符号的技巧,例如,
:boom:
,到小图像? (无论如何,这就是 GitHub 正在做的事情,请参见例如the :boom: image https://assets-cdn.github.com/images/icons/emoji/unicode/1f4a5.png)这个技巧可能应该在 Sphinx 创建的 HTML 页面上,而不是在源 Markdown 文件上(我希望它们仍然可以通过 GitHub 文件查看器读取)。
提前致谢。
问候。
2 部分解决方案
部分解决方案是这个Python小脚本 https://bitbucket.org/lbesson/bin/src/master/emojize.py我写的,使用carpedm20 的表情符号 https://github.com/carpedm20/emoji/包裹。
如果可能的话,它会将任何 :emoji: 别名(写为 :like_this:)转换为其 UTF-8 版本。
我也尝试使用pymdownx.emoji https://facelessuser.github.io/pymdown-extensions/extensions/emoji/封装,写第二个脚本 https://bitbucket.org/lbesson/bin/src/master/emojize_pngorsvg.py。
它将任何 :emoji: 别名转换为一段 HTML 代码,加载远程 PNG(或 SVG)版本(来自 JsDelivr 的 CDN)。仍然不完美,尺寸/缩放比例不好,甚至...中的表情符号都被替换了。 (我会改进这一点)。
两者都可以与这个小型 Bash for 循环一起使用:
BUILDDIR=_build/html # Adapt to the location of your Sphinx output
for i in "$BUILDDIR"/*.html; do
emojize.py "$i" > "$i".new
# or emojize_pngorsvg.py "$i" > "$i".new
wdiff -3 "$i" "$i".new;
mv -vf "$i".new "$i"
done
Demo:
- With UTF-8 codes for emojis:
- With PNG images for emojis (still not perfect):
没有找到任何东西,所以结束了创建扩展 https://github.com/sphinx-contrib/emojicodes.
安装它:
pip install sphinxemoji
然后,在你的狮身人面像中conf.py
:
extensions = [
'...',
'sphinxemoji.sphinxemoji',
]
然后您可以开始在文档中使用表情符号代码(但请注意,您需要在表情符号代码周围使用横线):
This text includes a smily face |:smile:| and a snake too! |:snake:|
Don't you love it? |:heart_eyes:|
如果你想要一致的表情符号风格,你可以将其添加到你的conf.py
:
sphinxemoji_style = 'twemoji'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)