Reputation: 3847
Happy New Year! I have started out my new year by making a resolution to get Markdown rendering to HTML working for my Django blog. I came across Django Markdownify and it is pretty OK! I managed to get my markdown file rendered, via get_context_data
as described below in installation and usage:
class MarkDown(TemplateView):
template_name = 'index.html'
def get_context_data(self, **kwargs):
markdowntext = open(os.path.join(os.path.dirname(__file__), 'templates/test.md')).read()
context = super(MarkDown, self).get_context_data(**kwargs)
context['markdowntext'] = markdowntext
return context
{% load markdownify %}
{{ markdowntext|markdownify }}
Although basic rendering works, there are some major drawbacks. Including:
###
in ### My Header
gets stripped completely)>
))These two issues alone are enough to give me pause and seek out an alternative solution for Markdown to HTML in Django. I did open an issue for the header problem and I'll wait to hear back. Until then, if anyone can recommend some Django specific workarounds I'd greatly appreciate it.
Upvotes: 1
Views: 850
Reputation: 157
Add this to your settings.py and it should work fine.
MARKDOWNIFY_WHITELIST_TAGS = [
'a',
'abbr',
'acronym',
'b',
'blockquote',
'em',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'i',
'li',
'ol',
'p',
'strong',
'ul'
]
Upvotes: 0
Reputation: 4404
Brief summary of google results on topic:
Django Integrated Markdown Editors - allow editing and previewing markdown and possibly other formats. Maybe not so lightweight. Usually provide best html escaping:
Django Fields with Markdown support:
Other:
markdown
, misaka
, mistune
, ...) and generate markdown html in django, possible syntax higlightng with pygments
- more low-level, more configuration, more issues to solveUpvotes: 1