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
| """ | |
| DocData | |
| A Meta-Data handler for lightweight markup languages. | |
| Note: This was an experiment which was rejected in favor of a different API. | |
| See the better implementation here: <https://github.com/waylan/docdata> | |
| An implementation of Meta-Data as defined by MultiMarkdown. However, it can | |
| work with any lightweight markup language and the various keys can have |
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
| """ | |
| HTML5Parser | |
| The HTML5Parser **mostly** replicates the behavior and API of the | |
| `htmlparser.HTMLParser` class. However, it uses the html5lib tokenizer | |
| to parser the source HTML. Note that it only takes the raw tokens | |
| and does not run the entire html5lib parser which normalizes the tokens, | |
| etc. In other words, if invalid (improperly nested) elements exist in the | |
| source HTML, they will be feed to HTML5Parser as they appear in the source | |
| document. |
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
| import unittest | |
| import os | |
| import markdown | |
| import codecs | |
| import difflib | |
| try: | |
| import tidylib | |
| except ImportError: | |
| tidylib = None |
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
| try: | |
| from html.parser import HTMLParser | |
| except ImportError: | |
| from HTMLParser import HTMLParser | |
| from enchant.checker import SpellChecker | |
| class HTMLSpellChecker(HTMLParser): | |
| """ | |
| Check the spelling of an HTML document using the given SpellChecker. |
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
| *.pyc |
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
| """ | |
| backtick `* | |
| escape \\. | |
| stem *** | |
| st ** | |
| em * | |
| stem ___ | |
| st __ | |
| em _ | |
| linkstart ] |
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
| # -*- coding: utf-8 -*- | |
| # | |
| # HTMLTree | |
| # | |
| # An HTML Node Tree toolkit. | |
| # | |
| # -------------------------------------------------------------------- | |
| # | |
| # Copyright (c) 2015 by Waylan Limberg. All rights reserved. | |
| # |
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
| """ | |
| A crazy Idea! | |
| Just maybe, the way to parse HTML within a Markdown document is to run the document | |
| through an HTML Parser first. Some parsers, like the HTMLParser included in the | |
| Python Standard lib will properly parse the plain text not wrapped in HTML tags | |
| as plain text and simply return it unaltered. The problem is with Markdown's | |
| autolinks (`<foo@bar.com>` and `<http://example.com>`). | |
| However, as of Python 2.7.3 and 3.2.2, the HTMLParser can now handle invalid HTML |
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
| from bs4.element import Tag, NavigableString | |
| class Doc(Tag): | |
| """ | |
| Dumby Document Root. | |
| This class provides a document root object without a parser. | |
| The document will need to be built mannually by adding Tags, | |
| NavigableStrings, Comments and the like. This class assumes |
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
| try: | |
| from HTMLParser import HTMLParser | |
| except ImportError: | |
| from html.parser import HTMLParser | |
| HTML_BLOCK = set([ | |
| 'p', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', | |
| 'pre', 'table', 'dl', 'ol', 'ul', 'script', 'noscript', 'form', | |
| 'fieldset', 'iframe', 'math', 'hr', 'style', 'li', 'dt', 'dd', |