def pretty_json_as_html(data, sort_keys=True):
response = json.dumps(data, sort_keys=sort_keys, indent=2)
# Truncate the data. Alter as needed
response = response[:5000]
# Get the Pygments formatter
formatter = HtmlFormatter(style='colorful')
# Highlight the data
response = highlight(response, JsonLexer(), formatter)
# Get the stylesheet
style = "<style>" + formatter.get_style_defs() + "</style><br>"
# Safe the output
return mark_safe(style + response)
评论列表
文章目录