MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / FencedBlockPreprocessor

Class FencedBlockPreprocessor

markdown/extensions/fenced_code.py:84–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82
83
84class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
85
86 def run(self, lines):
87 """ Match and store Fenced Code Blocks in the HtmlStash. """
88 text = "\n".join(lines)
89 while 1:
90 m = FENCED_BLOCK_RE.search(text)
91 if m:
92 lang = ''
93 if m.group('lang'):
94 lang = LANG_TAG % m.group('lang')
95 code = CODE_WRAP % (lang, self._escape(m.group('code')))
96 placeholder = self.markdown.htmlStash.store(code, safe=True)
97 text = '%s\n%s\n%s'% (text[:m.start()], placeholder, text[m.end():])
98 else:
99 break
100 return text.split("\n")
101
102 def _escape(self, txt):
103 """ basic html escaping """
104 txt = txt.replace('&', '&')
105 txt = txt.replace('<', '&lt;')
106 txt = txt.replace('>', '&gt;')
107 txt = txt.replace('"', '&quot;')
108 return txt
109
110
111def makeExtension(configs=None):

Callers 1

extendMarkdownMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected