Last active
March 16, 2019 04:50
-
-
Save ryanwoodsmall/bf8c1bc0575585fd74ce6065b642c944 to your computer and use it in GitHub Desktop.
extremely simple python 2.7 + apache markdown + gfm + yaml renderer cgi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/python/current/bin/python | |
# working meta_yaml.py: | |
# mde="$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')/markdown/extensions" | |
# test -e ${mde} && mkdir -p ${mde} | |
# wget -P ${mde} https://raw.githubusercontent.com/teoric/python-markdown-yaml-meta-data/master/meta_yaml.py | |
# sed -i 's/>meta/<normalize_whitespace/g' ${mde}/meta_yaml.py | |
# | |
# apache conf: | |
# Action rendermd /cgi-bin/rendermd.cgi | |
# AddHandler rendermd .md | |
# | |
# some stuff: | |
# https://github.com/teoric/python-markdown-yaml-meta-data.git | |
# https://github.com/twardoch/markdown-steroids | |
# https://gregbrown.co/code/githib-flavoured-markdown-python-implementation | |
# | |
# mirrors: | |
# https://github.com/ryanwoodsmall/python-markdown-yaml-meta-data | |
# https://github.com/ryanwoodsmall/markdown-steroids | |
# | |
# reqs: | |
# markdown | |
# py-gfm (for GitHub Flavored Markdown) | |
# yaml (for metadata) | |
# ??? | |
import os | |
import markdown | |
from mdx_gfm import GithubFlavoredMarkdownExtension | |
import yaml | |
# XXX - handle stdin or passed filename if PATH_TRANSLATED not set | |
f = open(os.environ.get('PATH_TRANSLATED'),'r') | |
source = f.read() | |
f.close() | |
md = markdown.Markdown(source, extensions=[GithubFlavoredMarkdownExtension(),'meta_yaml']) | |
html = md.convert(source) | |
title = 'no_name.md' | |
if hasattr(md, 'Meta'): | |
if 'title' in md.Meta.keys(): | |
title = md.Meta['title'][0] | |
# XXX - defaults, handle a header/footer template (html/md/...) if they exist | |
header = """ | |
<html> | |
<head> | |
<title>""" + title + """</title> | |
</head> | |
<body> | |
""" | |
footer = """ | |
</body> | |
</html> | |
""" | |
print('Content-type: text/html\n\n') | |
print(header) | |
print(html) | |
#print(md.Meta) | |
print(footer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment