|
a/Allura/allura/lib/markdown_extensions.py |
|
b/Allura/allura/lib/markdown_extensions.py |
|
... |
|
... |
20 |
|
20 |
|
21 |
log = logging.getLogger(__name__)
|
21 |
log = logging.getLogger(__name__)
|
22 |
|
22 |
|
23 |
class ForgeExtension(markdown.Extension):
|
23 |
class ForgeExtension(markdown.Extension):
|
24 |
|
24 |
|
25 |
def __init__(self, wiki=False, email=False):
|
25 |
def __init__(self, wiki=False, email=False, macro_context=None):
|
26 |
markdown.Extension.__init__(self)
|
26 |
markdown.Extension.__init__(self)
|
27 |
self._use_wiki = wiki
|
27 |
self._use_wiki = wiki
|
28 |
self._is_email = email
|
28 |
self._is_email = email
|
|
|
29 |
self._macro_context = macro_context
|
29 |
|
30 |
|
30 |
def extendMarkdown(self, md, md_globals):
|
31 |
def extendMarkdown(self, md, md_globals):
|
31 |
md.registerExtension(self)
|
32 |
md.registerExtension(self)
|
32 |
self.forge_processor = ForgeProcessor(self._use_wiki, md)
|
33 |
self.forge_processor = ForgeProcessor(self._use_wiki, md, macro_context=self._macro_context)
|
33 |
self.forge_processor.install()
|
34 |
self.forge_processor.install()
|
34 |
md.preprocessors['fenced-code'] = FencedCodeProcessor()
|
35 |
md.preprocessors['fenced-code'] = FencedCodeProcessor()
|
35 |
md.inlinePatterns['autolink_1'] = AutolinkPattern(r'(http(?:s?)://[a-zA-Z0-9./\-_0%?&=+#;~]+)')
|
36 |
md.inlinePatterns['autolink_1'] = AutolinkPattern(r'(http(?:s?)://[a-zA-Z0-9./\-_0%?&=+#;~]+)')
|
36 |
md.treeprocessors['br'] = LineOrientedTreeProcessor(md)
|
37 |
md.treeprocessors['br'] = LineOrientedTreeProcessor(md)
|
37 |
# Sanitize HTML
|
38 |
# Sanitize HTML
|
|
... |
|
... |
67 |
macro_pattern = r'\[(\[([^\]\[]*)\])\]'
|
68 |
macro_pattern = r'\[(\[([^\]\[]*)\])\]'
|
68 |
placeholder_prefix = '#jgimwge'
|
69 |
placeholder_prefix = '#jgimwge'
|
69 |
placeholder = '%s:%%s:%%.4d#khjhhj' % placeholder_prefix
|
70 |
placeholder = '%s:%%s:%%.4d#khjhhj' % placeholder_prefix
|
70 |
placeholder_re = re.compile('%s:(\\w+):(\\d+)#khjhhj' % placeholder_prefix)
|
71 |
placeholder_re = re.compile('%s:(\\w+):(\\d+)#khjhhj' % placeholder_prefix)
|
71 |
|
72 |
|
72 |
def __init__(self, use_wiki = False, markdown=None):
|
73 |
def __init__(self, use_wiki = False, markdown=None, macro_context=None):
|
73 |
self.markdown = markdown
|
74 |
self.markdown = markdown
|
74 |
self._use_wiki = use_wiki
|
75 |
self._use_wiki = use_wiki
|
|
|
76 |
self._macro_context = macro_context
|
75 |
self.inline_patterns = {
|
77 |
self.inline_patterns = {
|
76 |
'forge.alink' : ForgeInlinePattern(self, self.alink_pattern),
|
78 |
'forge.alink' : ForgeInlinePattern(self, self.alink_pattern),
|
77 |
'forge.macro' : ForgeInlinePattern(self, self.macro_pattern)}
|
79 |
'forge.macro' : ForgeInlinePattern(self, self.macro_pattern)}
|
78 |
self.postprocessor = ForgePostprocessor(self)
|
80 |
self.postprocessor = ForgePostprocessor(self)
|
79 |
self.tree_processor = ForgeTreeProcessor(self)
|
81 |
self.tree_processor = ForgeTreeProcessor(self)
|
|
... |
|
... |
114 |
self.alinks.update(M.Shortlink.from_links(*self.stash['link']))
|
116 |
self.alinks.update(M.Shortlink.from_links(*self.stash['link']))
|
115 |
except:
|
117 |
except:
|
116 |
self.alinks = {}
|
118 |
self.alinks = {}
|
117 |
self.stash['artifact'] = map(self._expand_alink, self.stash['artifact'])
|
119 |
self.stash['artifact'] = map(self._expand_alink, self.stash['artifact'])
|
118 |
self.stash['link'] = map(self._expand_link, self.stash['link'])
|
120 |
self.stash['link'] = map(self._expand_link, self.stash['link'])
|
119 |
self.stash['macro'] = map(macro.parse, self.stash['macro'])
|
121 |
self.stash['macro'] = map(macro.parse(self._macro_context), self.stash['macro'])
|
120 |
|
122 |
|
121 |
def reset(self):
|
123 |
def reset(self):
|
122 |
self.stash = dict(
|
124 |
self.stash = dict(
|
123 |
artifact=[],
|
125 |
artifact=[],
|
124 |
macro=[],
|
126 |
macro=[],
|