2 from csv import reader, QUOTE_NONE
4 from markdown import Extension
5 from markdown.preprocessors import Preprocessor
8 from forum import settings
10 class SettingsExtension(markdown.Extension):
11 def __init__(self, configs):
12 self.configs = {} # settings.REP_TO_VOTE_UP}
13 for key, value in configs:
14 self.config[key] = value
16 # self.extendMarkdown(markdown.Markdown()., config)
21 def extendMarkdown(self, md, md_globals):
22 md.registerExtension(self)
23 self.parser = md.parser
24 md.preprocessors.add('MinRep', SettingsPre(self), '_begin')
26 SETTING_RE = re.compile(r'\|[A-Z_]+\|')
28 def setting_rep_callback(m):
29 setting_name = m.group(0).strip('|')
30 if hasattr(settings, setting_name):
31 return unicode(getattr(settings, setting_name))
36 class SettingsPre(Preprocessor):
40 new_lines.append(SETTING_RE.sub(setting_rep_callback, line))
45 def makeExtension(configs=None) :
46 return SettingsExtension(configs=configs)