markdown: fixed GFM auto checkbox generation. References #5513
marcink -
r3281:d18fef65 default
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -60,6 +60,7
60 "table", "thead", "tbody", "tfoot", "tr", "th", "td",
60 "table", "thead", "tbody", "tfoot", "tr", "th", "td",
61 "img",
61 "img",
62 "a",
62 "a",
63 "input",
63 ]
64 ]
64
65
65 markdown_attrs = {
66 markdown_attrs = {
@@ -68,7 +69,8
68 "a": ["href", "alt", "title", "name"],
69 "a": ["href", "alt", "title", "name"],
69 "abbr": ["title"],
70 "abbr": ["title"],
70 "acronym": ["title"],
71 "acronym": ["title"],
71 "pre": ["lang"]
72 "pre": ["lang"],
73 "input": ["type", "disabled"]
72 }
74 }
73
75
74 standard_styles = [
76 standard_styles = [
@@ -22,36 +22,7
22
22
23 import markdown
23 import markdown
24
24
25 from mdx_gfm import GithubFlavoredMarkdownExtension # noqa
25 from mdx_gfm import GithubFlavoredMarkdownExtension # pragma: no cover
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)
55
26
56
27
57 class FlavoredCheckboxPostprocessor(markdown.postprocessors.Postprocessor):
28 class FlavoredCheckboxPostprocessor(markdown.postprocessors.Postprocessor):
Comments 0
You need to be logged in to leave comments. Login now