forked from revolunet/sublimetext-markdown-preview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown_wrapper.py
43 lines (35 loc) · 1.58 KB
/
markdown_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Markdown Preview wrapper."""
from __future__ import absolute_import
import traceback
from markdown import Markdown, util
from markdown.extensions import Extension
class StMarkdown(Markdown):
"""A wrapper around "markdown" lib."""
def __init__(self, *args, **kwargs):
"""Intialize."""
Markdown.__init__(self, *args, **kwargs)
self.Meta = {}
def registerExtensions(self, extensions, configs): # noqa
"""
Register extensions with this instance of Markdown.
Keyword arguments:
* extensions: A list of extensions, which can either
be strings or objects. See the docstring on Markdown.
* configs: A dictionary mapping module names to config options.
We are overriding this in order to gracefully handle bad extensions
and to prevent old deprecated style of 'extensions(option=value)'.
"""
for ext in extensions:
try:
# Make sure we aren't using old form `extension(option=value)`
if isinstance(ext, util.string_type) and ('(' not in ext):
ext = self.build_extension(ext, configs.get(ext, []))
if isinstance(ext, Extension):
ext.extendMarkdown(self, globals())
elif ext is not None:
raise TypeError(
'Extension "%s.%s" must be of type: "markdown.Extension"'
% (ext.__class__.__module__, ext.__class__.__name__))
except Exception:
print(str(traceback.format_exc()))
return self