flatpages-flask中的Fenced Code Blocks的语法高亮显示

时间:2017-04-25 17:17:57

标签: python html css flask pygments

我正在尝试使用flask-flatpages来渲染我的降价帖子。 Markdown扩展名为fenced_code_blocks,因此我为flatpages-flask设置了FLATPAGES_MARKDOWN_EXTENSIONS = ['fenced_code']。而且我想使用pygments css突出显示我的代码。创建css视图:

@app.route('/pygments.css')
def pygments_css():
    return pygments_style_defs('tango'), 200, {'Content-Type':"text/css"}

Jinja2模板html如下:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="{{ url_for('pygments_css')  }}">
  </head>
    {{ post.html|safe}}
  <body>

  </body>
</html>

但最终的html未突出显示,pygments.css包含codehilite,这是flask-flatpages中的默认降价扩展

# part of pygments.css
.codehilite .hll { background-color: #ffffcc }
.codehilite  { background: #f8f8f8; }
.codehilite .c { color: #8f5902; font-style: italic } /* Comment */
.codehilite .err { color: #a40000; border: 1px solid #ef2929 } /* Error */
.codehilite .g { color: #000000 } /* Generic */
.codehilite .k { color: #204a87; font-weight: bold } /* Keyword */
.codehilite .l { color: #000000 } /* Literal */
.codehilite .n { color: #000000 } /* Name */
.codehilite .o { color: #ce5c00; font-weight: bold } /* Operator */
.codehilite .x { color: #000000 } /* Other */  

要突出显示围栏代码块渲染的html,我应该使用fenced代码块样式css。无论如何得到fenced代码块hightlight css文件?

0 个答案:

没有答案