本文整理匯總了Python中markdown.inlinepatterns方法的典型用法代碼示例。如果您正苦於以下問題:Python markdown.inlinepatterns方法的具體用法?Python markdown.inlinepatterns怎麽用?Python markdown.inlinepatterns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類markdown
的用法示例。
在下文中一共展示了markdown.inlinepatterns方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import markdown [as 別名]
# 或者: from markdown import inlinepatterns [as 別名]
def __init__(self):
markdown.inlinepatterns.Pattern.__init__(self, r'(?<!\\)(\$\$?)(.+?)\2')
示例2: to_markdown
# 需要導入模塊: import markdown [as 別名]
# 或者: from markdown import inlinepatterns [as 別名]
def to_markdown(text: str, *,
docformat: str = None,
module: pdoc.Module = None, link: Callable[..., str] = None):
"""
Returns `text`, assumed to be a docstring in `docformat`, converted to markdown.
`__docformat__` is respected
if present, otherwise Numpydoc and Google-style docstrings are assumed,
as well as pure Markdown.
`module` should be the documented module (so the references can be
resolved) and `link` is the hyperlinking function like the one in the
example template.
"""
if not docformat:
docformat = str(getattr(getattr(module, 'obj', None), '__docformat__', 'numpy,google '))
docformat, *_ = docformat.lower().split()
if not (set(docformat.split(',')) & {'', 'numpy', 'google'}):
warn('__docformat__ value {!r} in module {!r} not supported. '
'Supported values are: numpy, google.'.format(docformat, module))
docformat = 'numpy,google'
with _fenced_code_blocks_hidden(text) as result:
text = result[0]
text = _ToMarkdown.admonitions(text, module)
if 'google' in docformat:
text = _ToMarkdown.google(text)
text = _ToMarkdown.doctests(text)
text = _ToMarkdown.raw_urls(text)
# If doing both, do numpy after google, otherwise google-style's
# headings are incorrectly interpreted as numpy params
if 'numpy' in docformat:
text = _ToMarkdown.numpy(text)
if module and link:
# Hyperlink markdown code spans not within markdown hyperlinks.
# E.g. `code` yes, but not [`code`](...). RE adapted from:
# https://github.com/Python-Markdown/markdown/blob/ada40c66/markdown/inlinepatterns.py#L106
# Also avoid linking triple-backticked arg names in deflists.
linkify = partial(_linkify, link=link, module=module, wrap_code=True)
text = re.sub(r'(?P<inside_link>\[[^\]]*?)?'
r'(?:(?<!\\)(?:\\{2})+(?=`)|(?<!\\)(?P<fence>`+)'
r'(?P<code>.+?)(?<!`)'
r'(?P=fence)(?!`))',
lambda m: (m.group()
if m.group('inside_link') or len(m.group('fence')) > 2
else linkify(m)), text)
result[0] = text
text = result[0]
return text