##// END OF EJS Templates
markdown: fixed GFM auto checkbox generation. References #5513
marcink -
r3281:d18fef65 default
parent child Browse files
Show More
@@ -60,6 +60,7 b' markdown_tags = ['
60 60 "table", "thead", "tbody", "tfoot", "tr", "th", "td",
61 61 "img",
62 62 "a",
63 "input",
63 64 ]
64 65
65 66 markdown_attrs = {
@@ -68,7 +69,8 b' markdown_attrs = {'
68 69 "a": ["href", "alt", "title", "name"],
69 70 "abbr": ["title"],
70 71 "acronym": ["title"],
71 "pre": ["lang"]
72 "pre": ["lang"],
73 "input": ["type", "disabled"]
72 74 }
73 75
74 76 standard_styles = [
@@ -22,36 +22,7 b' import re'
22 22
23 23 import markdown
24 24
25 from mdx_gfm import GithubFlavoredMarkdownExtension # noqa
26
27
28 class FlavoredCheckboxExtension(markdown.Extension):
29
30 def extendMarkdown(self, md, md_globals):
31 md.preprocessors.add('checklist',
32 FlavoredCheckboxPreprocessor(md), '<reference')
33 md.postprocessors.add('checklist',
34 FlavoredCheckboxPostprocessor(md), '>unescape')
35
36
37 class FlavoredCheckboxPreprocessor(markdown.preprocessors.Preprocessor):
38 """
39 Replaces occurrences of [ ] or [x] to checkbox input
40 """
41
42 pattern = re.compile(r'^([*-]) \[([ x])\]')
43
44 def run(self, lines):
45 return [self._transform_line(line) for line in lines]
46
47 def _transform_line(self, line):
48 return self.pattern.sub(self._replacer, line)
49
50 def _replacer(self, match):
51 list_prefix, state = match.groups()
52 checked = '' if state == ' ' else ' checked="checked"'
53 return '%s <input type="checkbox" disabled="disabled"%s>' % (list_prefix,
54 checked)
25 from mdx_gfm import GithubFlavoredMarkdownExtension # pragma: no cover
55 26
56 27
57 28 class FlavoredCheckboxPostprocessor(markdown.postprocessors.Postprocessor):
General Comments 0
You need to be logged in to leave comments. Login now