Python markdown.inlinepatterns() Examples
The following are 2
code examples of markdown.inlinepatterns().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
markdown
, or try the search function
.
Example #1
Source File: html.py From knowledge-repo with Apache License 2.0 | 5 votes |
def __init__(self): markdown.inlinepatterns.Pattern.__init__(self, r'(?<!\\)(\$\$?)(.+?)\2')
Example #2
Source File: html_helpers.py From pdoc with GNU Affero General Public License v3.0 | 4 votes |
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