Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eb02043
Showing
6 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.PHONY: test lint coverage clean | ||
|
||
readme: | ||
python -c "import markdown_checklist as cl; print cl.__doc__.strip()" > README | ||
|
||
test: clean | ||
py.test -s --tb=short test | ||
|
||
lint: | ||
find . -name "*.py" -not -path "./venv/*" | while read filepath; do \ | ||
pep8 --ignore=E128,E261 $$filepath; \ | ||
done | ||
#upyflakes $$filepath; \ | ||
#pylint --reports=n --include-ids=y $$filepath; \ | ||
|
||
coverage: clean | ||
# option #1: figleaf | ||
find . test -name "*.py" > coverage.lst | ||
figleaf `which py.test` test | ||
figleaf2html -f coverage.lst | ||
# option #2: coverage | ||
coverage run `which py.test` test | ||
coverage html | ||
# reports | ||
coverage report | ||
@echo "[INFO] additional reports in \`html/index.html\` (figleaf) and" \ | ||
"\`htmlcov/index.html\` (coverage)" | ||
|
||
clean: | ||
find . -name "*.pyc" -print0 | xargs -0 rm || true | ||
rm -rf html .figleaf coverage.lst # figleaf | ||
rm -rf htmlcov .coverage # coverage | ||
rm -rf test/__pycache__ # pytest |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Markdown Checklist | ||
|
||
a [Python Markdown](http://pythonhosted.org/Markdown/) extension for lists of | ||
tasks with checkboxes | ||
|
||
inspired by | ||
[GitHub task lists](https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
README |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Markdown Checklist | ||
a [Python Markdown](http://pythonhosted.org/Markdown/) extension for lists of | ||
tasks with checkboxes | ||
inspired by | ||
[GitHub task lists](https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments) | ||
""" | ||
|
||
import re | ||
|
||
from markdown.extensions import Extension | ||
from markdown.preprocessors import Preprocessor | ||
|
||
|
||
class ChecklistExtension(Extension): | ||
|
||
def extendMarkdown(self, md, md_globals): | ||
md.preprocessors.add('checklist', ChecklistPreprocessor(md), | ||
'<reference') | ||
|
||
|
||
class ChecklistPreprocessor(Preprocessor): | ||
|
||
pattern = re.compile(r'^([*-]) \[([ Xx])\]') | ||
|
||
def run(self, lines): | ||
return [self._transform_line(line) for line in lines] | ||
|
||
def _transform_line(self, line): | ||
return self.pattern.sub(self._replacer, line) | ||
|
||
def _replacer(self, match): | ||
list_prefix, state = match.groups() | ||
checked = ' checked' if state != ' ' else '' | ||
return '%s <input type="checkbox" readonly%s>' % (list_prefix, checked) |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import markdown | ||
|
||
from markdown_checklist import ChecklistExtension | ||
|
||
|
||
def test_checkbox(): | ||
source = """ | ||
Hello World | ||
=========== | ||
* [ ] foo | ||
* [x] bar | ||
* [ ] baz | ||
lorem ipsum | ||
""".strip() | ||
|
||
html = markdown.markdown(source) | ||
assert html == """ | ||
<h1>Hello World</h1> | ||
<ul> | ||
<li>[ ] foo</li> | ||
<li>[x] bar</li> | ||
<li>[ ] baz</li> | ||
</ul> | ||
<p>lorem ipsum</p> | ||
""".strip() | ||
|
||
html = markdown.markdown(source, extensions=[ChecklistExtension()]) | ||
assert html == """ | ||
<h1>Hello World</h1> | ||
<ul> | ||
<li><input type="checkbox" readonly> foo</li> | ||
<li><input type="checkbox" readonly checked> bar</li> | ||
<li><input type="checkbox" readonly> baz</li> | ||
</ul> | ||
<p>lorem ipsum</p> | ||
""".strip() |