V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
RadAsm
V2EX  ›  Python

mistune 怎么给 markdown 的关键字加颜色

  •  
  •   RadAsm · 2015-11-08 14:57:35 +08:00 · 3986 次点击
    这是一个创建于 3083 天前的主题,其中的信息可能已经有所发展或是发生改变。

    rt ,使用mistune来解析 markdown ,解析也差不多成功了,还加了代码颜色,如图,这样子:

    mistune

    接下来,我想把代码中诸如“ maven ”,“ class ”...啊这类关键字变色或者加个样式,就像使用 markdown 编辑器展示的那样子,请问有什么好的解决方案没。

    5 条回复    2015-11-08 16:13:25 +08:00
    SErHo
        1
    SErHo  
       2015-11-08 15:45:37 +08:00
    参考 https://github.com/lepture/mistune#renderer 使用 Pygments 高亮代码,只要 Pygments 支持的语言,就可以。
    RadAsm
        2
    RadAsm  
    OP
       2015-11-08 15:52:23 +08:00
    @SErHo
    可能是我描述的不清晰,代码我亮了,但是代码中诸如:“ class ”,“ interface ”。。。这类关键字,我希望能加上样式(字体啦,颜色啦什么的。。)

    刚才想了一会,感觉可以用 js 代码实现吧。。
    SErHo
        3
    SErHo  
       2015-11-08 15:55:11 +08:00
    @RadAsm 你确定用了 Pygments ?以及选则对了语言,如果还没有正确高亮的话,应该是 Pygments 支持不完整。当然你也可以用前端的 js 来实现。
    RadAsm
        4
    RadAsm  
    OP
       2015-11-08 16:03:13 +08:00
    @SErHo
    吖。。。不知道啊,我用了吧,嗯。。。(难道姿势不正确。。~~(╯﹏╰)~~)
    但是不确定有没有用对,正确用对了,应该出现什么效果。
    SErHo
        5
    SErHo  
       2015-11-08 16:13:25 +08:00   ❤️ 1
    @RadAsm http://lepture.com/en/2014/markdown-parsers-in-python#fnref-mistune-features 这种效果。。当然记得加上 Pygments 的样式 css 。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4221 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 05:28 · PVG 13:28 · LAX 22:28 · JFK 01:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.