0

I recently built a website using flask, flask-flatpages, and flask-freeze and I am wondering how to highlight syntax when I use block-codes in my markdown files.

These are my installed packages:

click (6.6) Flask (0.11.1) Flask-FlatPages (0.6) Frozen-Flask (0.13) itsdangerous (0.24) Jinja2 (2.8) Markdown (2.6.7) MarkupSafe (0.23) pip (9.0.1) Pygments (2.1.3) PyYAML (3.12) setuptools (27.2.0) Werkzeug (0.11.11) wheel (0.29.0)

and my flatpage render settings for my web looks like this:

def prerender_jinja(text):
    return pygmented_markdown(render_template_string(Markup(text)))

FLATPAGES_EXTENSION =['.md']
FLATPAGES_MARKDOWN_EXTENSION =['codehilite']
FLATPAGES_HTML_RENDERER = prerender_jinja

What else do I have to do in order to enable syntax highlighting when I convert my .md files to .html files?

Thanks.

aii
  • 39
  • 8

1 Answers1

2

From http://flask-flatpages.readthedocs.io/en/latest/#how-it-works:

To use Pygments, you need to include the style declarations separately. You can get them with pygments_style_defs():

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

and in templates:

<link rel="stylesheet" href="{{ url_for('pygments_css') }}">

Community
  • 1
  • 1
Sebastian Stigler
  • 6,819
  • 2
  • 29
  • 31
  • I have tried this, but my code block remains style-less. Just black font. – aii Jan 12 '17 at 12:55
  • Did you open the file directly in the browser or did you start an webserver (i.e. `cd build; python -m SimpleHTTPServer` -> open http://localhost:8000 in your browser)? – Sebastian Stigler Jan 12 '17 at 13:44
  • I started a webserver – aii Jan 12 '17 at 15:14
  • Ah, okay. the solution was to have the language specified. (when I did the above style declaration, i was only getting html syntax highlighted) I basically pasted the code in Sebastian's comment and did :::javascript block code I want to write – aii Jan 13 '17 at 03:54