本文整理汇总了Python中markdown.Extension方法的典型用法代码示例。如果您正苦于以下问题:Python markdown.Extension方法的具体用法?Python markdown.Extension怎么用?Python markdown.Extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类markdown
的用法示例。
在下文中一共展示了markdown.Extension方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: registerExtensions
# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import Extension [as 别名]
def registerExtensions(self, extensions, configs):
"""
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.
"""
for ext in extensions:
if isinstance(ext, str):
ext = self.build_extension(ext, configs.get(ext, []))
if isinstance(ext, Extension):
# might raise NotImplementedError, but that's the extension author's problem
ext.extendMarkdown(self, globals())
elif ext is not None:
raise ValueError('Extension "%s.%s" must be of type: "markdown.Extension".' \
% (ext.__class__.__module__, ext.__class__.__name__))
return self
示例2: __init__
# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import Extension [as 别名]
def __init__(self, **kwargs):
self.config = {
'classes': ["uml", "Space separated list of classes for the generated image. Defaults to 'uml'."],
'alt': ["uml diagram", "Text to show when image is not available. Defaults to 'uml diagram'"],
'format': ["png", "Format of image to generate (png, svg or txt). Defaults to 'png'."],
'title': ["", "Tooltip for the diagram"],
'server': ["", "PlantUML server url, for remote rendering. Defaults to '', use local command."],
'cachedir': ["", "Directory for caching of diagrams. Defaults to '', no caching"],
'priority': ["30", "Extension priority. Higher values means the extension is applied sooner than others. "
"Defaults to 30"],
'base_dir': [".", "Base directory for external files inclusion"]
}
# Fix to make links navigable in SVG diagrams
etree.register_namespace('xlink', 'http://www.w3.org/1999/xlink')
super(PlantUMLMarkdownExtension, self).__init__(**kwargs)
示例3: registerExtensions
# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import Extension [as 别名]
def registerExtensions(self, extensions, configs):
"""
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.
"""
for ext in extensions:
if isinstance(ext, util.string_type):
ext = self.build_extension(ext, configs.get(ext, {}))
if isinstance(ext, Extension):
ext.extendMarkdown(self, globals())
logger.debug(
'Successfully loaded extension "%s.%s".'
% (ext.__class__.__module__, ext.__class__.__name__)
)
elif ext is not None:
raise TypeError(
'Extension "%s.%s" must be of type: "markdown.Extension"'
% (ext.__class__.__module__, ext.__class__.__name__))
return self
示例4: __init__
# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import Extension [as 别名]
def __init__(self, app):
markdown.Extension.__init__(self)
self.app = app
self._use_wiki = False
示例5: __init__
# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import Extension [as 别名]
def __init__(self, linktypes):
markdown.Extension.__init__(self)
self.linktypes = linktypes
示例6: _getLang
# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import Extension [as 别名]
def _getLang(self):
"""
Determines language of a code block from shebang line and whether said
line should be removed or left in place. If the sheband line contains a
path (even a single /) then it is assumed to be a real shebang line and
left alone. However, if no path is given (e.i.: #!python or :::python)
then it is assumed to be a mock shebang for language identifitation of a
code fragment and removed from the code block prior to processing for
code highlighting. When a mock shebang (e.i: #!python) is found, line
numbering is turned on. When colons are found in place of a shebang
(e.i.: :::python), line numbering is left in the current state - off
by default.
"""
import re
#split text into lines
lines = self.src.split("\n")
#pull first line to examine
fl = lines.pop(0)
c = re.compile(r'''
(?:(?:^::+)|(?P<shebang>^[#]!)) # Shebang or 2 or more colons.
(?P<path>(?:/\w+)*[/ ])? # Zero or 1 path
(?P<lang>[\w+-]*) # The language
''', re.VERBOSE)
# search first line for shebang
m = c.search(fl)
if m:
# we have a match
try:
self.lang = m.group('lang').lower()
except IndexError:
self.lang = None
if m.group('path'):
# path exists - restore first line
lines.insert(0, fl)
if m.group('shebang'):
# shebang exists - use line numbers
self.linenos = True
else:
# No match
lines.insert(0, fl)
self.src = "\n".join(lines).strip("\n")
# ------------------ The Markdown Extension -------------------------------