Convert a txt file to html file
$ python txt2html.py < input.txt > output.html
-
Support *emphasis*
Rule:
r'\*(.+?)\*'
-
Support url
Rule:
r'(http://[\.a-zA-Z/]+)'
-
Support email
Rule:
r'[\.a-zA-Z]+@[\.a-zA-Z]+[a-zA-Z]+'
-
Support title
Rule: First heading
-
Support heading
Rule: A block with no
\n
with less than 70 characters and the last charater is not:
-
Support list
Rule: A consecutive array of list items
-
Support list items
Rule: A block starting with
-
(hyphen) -
Support paragraph
Rule: A block that is not marked down as a heading/title or list/list items
Token: block, lines
util
: to break things into block and lines (lexemes)
Syntax Rules: rules (conditions) and filters (regex)
rules
: syntax rules for block-level token, e.g.: list, list item, title, heading, paragraph, etc.
filters
: syntax rules for within-block elements, e.g.: email, url, emphasis, etc.
Semantics: How to interpret each rule on a block
handlers
: handle rule action and filter, using visitor pattern
parser
: Assemble rules and filters
Debug frameworkRefactor filter to a standalone classPopulate more rules and filters- Potential Extension: Markdown for table and table item
- Potential Extension: Support more markup language (Markdown, XML, YAML, etc)