0

I'm using Flask-Misaka with Flask to render a markdown string to html. However, it seems that the Flask-Misaka can't recognize fenced code. It does removed the back-ticks, but no colored block is displayed. I have tried with versions 0.4.0 and 0.4.1.

app.py

from flask import Flask, render_template
from flask_misaka import Misaka, markdown
app = Flask(__name__)
Misaka(app, fenced_code=True)
TEST_MD = markdown("```block```\n", fenced_code=True)

@app.route("/", methods=['GET'])
def index():
    return render_template('{{s|markdown}}', s=TEST_MD)
Chenlu
  • 449
  • 1
  • 6
  • 19
  • Can you provide an example Markdown input and the actual HTML output? It is not clear from your question if the source is not being converted to a code block, or the code block is not getting syntax highlighting, which are two separate things. – Waylan Dec 13 '18 at 22:32

1 Answers1

0

The issue is that you are missing a stylesheet. If you look at the HTML output of Flask it will show <p><code>block</code></p>\n. So the fenced code is seen and the HTML output is rendered correctly.

Short example which directly shows the result when the code is executed:

from flask import Flask, render_template_string
from flask_misaka import markdown

app = Flask(__name__)

with app.app_context():
    render_template_string('{{s}}', s=markdown("```block```\n", fenced_code=True))
rfkortekaas
  • 6,049
  • 2
  • 27
  • 34
  • Thanks. You are right. I accidently figured it out myself just now. By adding some code style html code like `code {background-color: #eee; border: 1px solid #999; display: block; padding: 20px;}`, I can see the colored code block in the rendered page now. – Chenlu Dec 14 '18 at 15:23
  • Shouldn't a fenced code block be rendered as `` within a `
    ` block? (this is what hugo currently does)
    – Charl Botha Apr 16 '20 at 12:04
  • Yes, that’s correct. Apparently Misaka isn’t doing it right. – rfkortekaas Apr 16 '20 at 17:45