Skip to content

Instantly share code, notes, and snippets.

@waylan
waylan / docdata.py
Last active August 29, 2015 14:16
A better Meta-Data handler for lightweight markup languages.
"""
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
@waylan
waylan / html5parser.py
Last active August 1, 2018 04:45
HTML5Parser mostly replicates the behavior and API of htmlparser.HTMLParser, using the html5lib tokenizer.
"""
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.
@waylan
waylan / mdtest.py
Created March 28, 2015 03:13
Alternate testing framework for python-markdown without nose.
import unittest
import os
import markdown
import codecs
import difflib
try:
import tidylib
except ImportError:
tidylib = None
@waylan
waylan / htmlspellchecker.py
Created April 11, 2015 00:50
Check the spelling of an HTML document.
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.
@waylan
waylan / .gitignore
Last active August 29, 2015 14:23
Priority Sorted Registry
*.pyc
@waylan
waylan / mdtokenize.py
Last active August 1, 2025 18:44
Uselessly Simple Markdown Inline Tokenizer
"""
backtick `*
escape \\.
stem ***
st **
em *
stem ___
st __
em _
linkstart ]
@waylan
waylan / htree.py
Last active August 29, 2015 14:24
HTMLTree -- An HTML Node Tree toolkit. Warning! This is unfinished.
# -*- coding: utf-8 -*-
#
# HTMLTree
#
# An HTML Node Tree toolkit.
#
# --------------------------------------------------------------------
#
# Copyright (c) 2015 by Waylan Limberg. All rights reserved.
#
@waylan
waylan / parser.py
Last active August 29, 2015 14:24
A crazy idea I had as a way to parser HTML within a Markdown document.
"""
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
@waylan
waylan / soup.py
Created July 15, 2015 00:38
BeautifulSoup Document without parser - Currently broken!
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
@waylan
waylan / RawHTMLParser.py
Created September 1, 2015 19:44
An experimental Raw HTML Parser for Markdown. This may or may not be a good idea.
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',