Skip to content

Instantly share code, notes, and snippets.

@brokaw
Created December 14, 2017 15:58
Show Gist options
  • Save brokaw/c0d42ca6bdb52bac5e01e59bd4eb2912 to your computer and use it in GitHub Desktop.
Save brokaw/c0d42ca6bdb52bac5e01e59bd4eb2912 to your computer and use it in GitHub Desktop.
A python script to process markdown and stylize code blocks. Works well with Marked 2
#!/usr/bin/env python
# This script is writted as a custom markdown processor with Marked 2
# It takes markdown on standard input and writes rendered html5 to
# standard output. Unlike the built-in processors, this marks code
# blocks with CSS classes, which can be stylized with a stylesheet.
# This obviates the for javascript running on the client stylizing the
# code at page load.
import sys
import markdown
def main():
extensions = ['markdown.extensions.extra',
'markdown.extensions.codehilite',
'markdown.extensions.smarty']
extension_config = {'markdown.extensions.codehilite':
{'linenums': False, 'guess_lang': False}}
text = sys.stdin.read()
output = markdown.markdown(text, extensions=extensions,
extension_configs=extension_config,
outputformat='html5')
sys.stdout.write(output)
return 0
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment