Esempio n. 1
0
def render():
    text = request.values.get('text', '').replace('\r\n', '\n')
    formatter = QqHTMLFormatter()

    formatter.localnames = {}

    parser = QqParser(allowed_tags=formatter.safe_tags)
    try:
        tree = parser.parse(text)
    except Exception as e:
        return jsonify(error='parse error: ' + str(e))

    formatter.root = tree
    try:
        output = formatter.do_format()
    except Exception as e:
        return jsonify(error='format error: ' + str(e))
    return jsonify(output=output)
Esempio n. 2
0
def render(path):
    print(path_to_source_url(path))
    r = requests.get(path_to_source_url(path))
    r.encoding = 'UTF-8'
    if not r:
        abort(500)

    formatter = QqHTMLFormatter(with_chapters=False)

    formatter.localnames = {}

    parser = QqParser(allowed_tags=formatter.safe_tags)
    try:
        tree = parser.parse(r.text)
    except Exception as e:
        if app.debug:
            raise e
        return render_template("error.html",
                               error='parse error: ' + str(e)), 400

    formatter.root = tree
    try:
        output = formatter.do_format()
    except Exception as e:
        if app.debug:
            raise e
        return render_template("error.html",
                               error='format error: ' + str(e)), 400

    meta = tree.find_or_empty("meta")
    print(meta.as_list())

    return render_template("render_url.html",
                           output=output,
                           source_url=path_to_url(path),
                           meta=meta)