Markdown
I spent the greater part of the day attempting to upgrade the blogging capability of this site with markdown.
I've been planning on making the change for ages and this morning I ran across this post
"I was building a tiny microservice which would let the client side application securely authenticate with GitHub. After writing the only required API, I wanted to render the README.md file on the index page."
The lack of any type of styling in the previous sentence indicates I need to add blockquotes to my css style list. It's a pretty simple implementation. I've used it in Wagtail, but I didn't feel like my site needs all that wagtail brings along with it. I didn't want to have to redo all my fields with wagtail stream fields.
import markdown
from django import template
from django.template.defaultfilters import stringfilter
from pygments.formatters import HtmlFormatter
register = template.Library()
@stringfilter
@register.filter(name='markdown', is_safe=True)
def markdown_to_html(value):
md_template_string = markdown.markdown(value, extensions=['extra', 'codehilite'])
return md_template_string
# formatter = HtmlFormatter(style="tango",full=True,cssclass="codehilite")
# css_string = formatter.get_style_defs()
# md_css_string = "<style>" + css_string + "</style>"
# md_template = md_css_string + md_template_string
# return md_template
# register.filter('markdown', markdown_to_html)
Most of this code has been commented out. It was initially used to experiment with the various pygment formatters. I'm afraid I'm going to run into problems with this implementation but I'm happy with it so far. And it makes blogging significantly more enjoyable than it was before.