Created
April 9, 2015 14:11
-
-
Save uchan-nos/7a045aaa80bd2ce98a77 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/python34 | |
| import codecs | |
| import mistune | |
| md_text = '''\ | |
| this is markdown. | |
| ``` | |
| block code! | |
| ``` | |
| - ab | |
| - cd | |
| - *emphasis text* | |
| - **double emphasis text** | |
| ''' | |
| class MyRenderer(mistune.Renderer): | |
| def block_code(self, code, lang): | |
| return '\x1b[35m{}\x1b[0m\n'.format(code) | |
| def paragraph(self, text): | |
| return '{}\n'.format(text) | |
| def list(self, body, orderer=True): | |
| return body | |
| def list_item(self, text): | |
| lines = text.split('\n') | |
| new_lines = ['', '- {}'.format(lines[0])] | |
| new_lines += [' {}'.format(line) for line in lines[1:]] | |
| return '\n'.join(new_lines) | |
| def emphasis(self, text): | |
| return '\x1b[4m{}\x1b[0m'.format(text) | |
| def double_emphasis(self, text): | |
| return '\x1b[7m{}\x1b[0m'.format(text) | |
| renderer = MyRenderer() | |
| md = mistune.Markdown(renderer=renderer) | |
| print(md.render(md_text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment