3
=============================================================================
5
Markdown also allows post-processors, which are similar to preprocessors in
6
that they need to implement a "run" method. However, they are run after core
15
def __init__(self, markdown_instance=None):
17
self.markdown = markdown_instance
19
class Postprocessor(Processor):
21
Postprocessors are run after the ElementTree it converted back into text.
23
Each Postprocessor implements a "run" method that takes a pointer to a
24
text string, modifies it as necessary and returns a text string.
26
Postprocessors must extend markdown.Postprocessor.
32
Subclasses of Postprocessor should implement a `run` method, which
33
takes the html document as a single text string and returns a
34
(possibly modified) string.
40
class RawHtmlPostprocessor(Postprocessor):
41
""" Restore raw html to the document. """
44
""" Iterate over html stash and restore "safe" html. """
45
for i in range(self.markdown.htmlStash.html_counter):
46
html, safe = self.markdown.htmlStash.rawHtmlBlocks[i]
47
if self.markdown.safeMode and not safe:
48
if str(self.markdown.safeMode).lower() == 'escape':
49
html = self.escape(html)
50
elif str(self.markdown.safeMode).lower() == 'remove':
53
html = markdown.HTML_REMOVED_TEXT
54
if safe or not self.markdown.safeMode:
55
text = text.replace("<p>%s</p>" %
56
(markdown.preprocessors.HTML_PLACEHOLDER % i),
58
text = text.replace(markdown.preprocessors.HTML_PLACEHOLDER % i,
62
def escape(self, html):
63
""" Basic html escaping """
64
html = html.replace('&', '&')
65
html = html.replace('<', '<')
66
html = html.replace('>', '>')
67
return html.replace('"', '"')
70
class AndSubstitutePostprocessor(Postprocessor):
71
""" Restore valid entities """
76
text = text.replace(markdown.AMP_SUBSTITUTE, "&")