Skip to content

Commit

Permalink
added packaging info
Browse files Browse the repository at this point in the history
this required restructuring the package to separate metadata from
functionality
  • Loading branch information
FND committed Sep 1, 2013
1 parent ee04bed commit 7ae0893
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.pyc
30 changes: 3 additions & 27 deletions markdown_checklist/__init__.py
Expand Up @@ -8,30 +8,6 @@
[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" disabled%s>' % (list_prefix, checked)
__version__ = '0.1.0'
__author__ = 'FND'
__license__ = 'MIT'
27 changes: 27 additions & 0 deletions markdown_checklist/extension.py
@@ -0,0 +1,27 @@
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" disabled%s>' % (list_prefix, checked)
32 changes: 32 additions & 0 deletions setup.py
@@ -0,0 +1,32 @@
import os

from setuptools import setup, find_packages

from markdown_checklist import (__version__ as VERSION, __author__ as AUTHOR,
__license__ as LICENSE, __doc__ as DESC)


META = {
'name': 'markdown-checklist',
'url': 'https://github.com/FND/markdown-checklist',
'version': VERSION,
'description': 'Python Markdown extension for task lists with checkboxes',
'long_description': DESC.strip(),
'license': LICENSE,
'author': AUTHOR,
'author_email': '',
'maintainer': 'FND',
'packages': find_packages(exclude=['test']),
'platforms': 'Posix; MacOS X; Windows',
'include_package_data': True,
'zip_safe': False,
'install_requires': ['markdown'],
'extras_require': {
'testing': ['pytest'],
'coverage': ['figleaf', 'coverage']
}
}


if __name__ == '__main__':
setup(**META)
2 changes: 1 addition & 1 deletion test/test_main.py
@@ -1,6 +1,6 @@
import markdown

from markdown_checklist import ChecklistExtension
from markdown_checklist.extension import ChecklistExtension


def test_checkbox():
Expand Down

0 comments on commit 7ae0893

Please sign in to comment.