Skip to content

Instantly share code, notes, and snippets.

@waylan
Created September 16, 2020 18:41
Show Gist options
  • Save waylan/4a470a6e05e04b9cadb1e11ba8d330de to your computer and use it in GitHub Desktop.
Save waylan/4a470a6e05e04b9cadb1e11ba8d330de to your computer and use it in GitHub Desktop.
Some test tools I used when refactoring Python-Markdown's HTML parser. Preserved here for future reference.
import markdown
src = """
<div><p markdown="1">Hello _World!_</p></div>
"""
md = markdown.Markdown(extensions=['md_in_html'])
print('Doc: ', '\n'.join(md.preprocessors['html_block'].run(src.split('\n'))))
print('Stash: ', md.htmlStash.rawHtmlBlocks)
md.htmlStash.reset()
print('Ouput: ', '\n---------------------\n' + md.convert(src) + '\n---------------------')
print('Stash: ', md.htmlStash.rawHtmlBlocks)
import markdown
import timeit
with open('tests/extensions/extra/raw-html.txt') as f:
src = f.read()
num, dur = timeit.Timer(lambda: markdown.markdown(src, extensions=['md_in_html'])).autorange()
print(dur / num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment