当前位置: 首页>>代码示例>>Python>>正文


Python markdown.extensions方法代码示例

本文整理汇总了Python中markdown.extensions方法的典型用法代码示例。如果您正苦于以下问题:Python markdown.extensions方法的具体用法?Python markdown.extensions怎么用?Python markdown.extensions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在markdown的用法示例。


在下文中一共展示了markdown.extensions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_engine

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def build_engine(realm_filters: List[Tuple[str, str, int]],
                 realm_filters_key: int,
                 email_gateway: bool) -> markdown.Markdown:
    engine = Markdown(
        realm_filters=realm_filters,
        realm=realm_filters_key,
        code_block_processor_disabled=email_gateway,
        extensions = [
            nl2br.makeExtension(),
            tables.makeExtension(),
            codehilite.makeExtension(
                linenums=False,
                guess_lang=False,
            ),
        ])
    return engine

# Split the topic name into multiple sections so that we can easily use
# our common single link matching regex on it. 
开发者ID:zulip,项目名称:zulip,代码行数:21,代码来源:__init__.py

示例2: __init__

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def __init__(self, markdown_file: Path):

        super().__init__()

        self.markdown_file = markdown_file

        self.html = bleach.clean(
            markdown.markdown(
                get_path(self.markdown_file).read_text(),
                extensions=[
                    "tables",
                    "sane_lists",
                    _WebvizMarkdownExtension(base_path=markdown_file.parent),
                ],
            ),
            tags=Markdown.ALLOWED_TAGS,
            attributes=Markdown.ALLOWED_ATTRIBUTES,
            styles=Markdown.ALLOWED_STYLES,
        )

        # Workaround for upstream issue https://github.com/plotly/dash-core-components/issues/746,
        # where we convert void html tags from <tag> to <tag/>.
        self.html = re.sub("<img (.*?[^/])>", r"<img \1/>", self.html)
        self.html = self.html.replace("<br>", "<br/>").replace("<hr>", "<hr/>") 
开发者ID:equinor,项目名称:webviz-config,代码行数:26,代码来源:_markdown.py

示例3: extendMarkdown

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def extendMarkdown(self, md, md_globals):
        """ Configure markdown by disabling elements and replacing them with
        others. """
        # Add checklist processing extension based on: 'markdown_checklist.extension'.
        md.postprocessors.add('checklist', ChecklistPostprocessor(md), '>raw_html')

        # Remove default patterns.
        del md.inlinePatterns['image_link']

        # Create a new one and insert into pipeline.
        multi_purpose_pattern = MultiPurposeLinkPattern(IMAGE_LINK_RE, md)
        md.inlinePatterns['multi_purpose_pattern'] = multi_purpose_pattern

        # Remove line headers.
        del md.parser.blockprocessors['setextheader']

        # Swap hash headers for one that can change the DOM h1, h2 level.
        md.parser.blockprocessors['hashheader'] = OffsetHashHeaderProcessor(md.parser)


# https://python-markdown.github.io/extensions/ 
开发者ID:HEInventions,项目名称:docnado,代码行数:23,代码来源:docnado.py

示例4: _render_markdown

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def _render_markdown(self, skip_headers=False, images_base64_encode=True, urlmappers=[]):
        """
        Returns the `Markdown` instance as well as the rendered html output
        as a tuple: (`Markdown`, str).
        """
        # Copy urlmappers locally so we can modify it without affecting global
        # state
        urlmappers = urlmappers[:]
        if images_base64_encode:
            urlmappers.insert(0, self.base64_encode_image_mapper)

        # proxy posts are assumed to be embeddable links
        if 'proxy' in self.kp.headers:
            return None, '<a href="{0}">Linked Post</a>\n<iframe width=100% height=1000 src="{0}"></iframe>'.format(self.kp.headers['proxy'].strip())

        html = ''
        if not skip_headers:
            html += self.render_headers()

        md = markdown.Markdown(extensions=MARKDOWN_EXTENSIONS)
        html += md.convert(self.kp.read())

        html = self.apply_url_remapping(html, urlmappers)

        return md, html 
开发者ID:airbnb,项目名称:knowledge-repo,代码行数:27,代码来源:html.py

示例5: render_headers

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def render_headers(self):
        headers = self.kp.headers

        headers['authors_string'] = ', '.join(headers.get('authors'))
        headers['tldr'] = markdown.Markdown(extensions=MARKDOWN_EXTENSIONS[
                                            :-1]).convert(headers['tldr'])
        headers['date_created'] = headers['created_at'].isoformat()
        headers['date_updated'] = headers['updated_at'].isoformat()

        header = """
<h1>{title}</h1>
<p id='metadata'>
<strong>Author</strong>: {authors_string} <br>
<strong>Date Created</strong>: {date_created}<br>
<strong>Date Updated</strong>: {date_updated}<br>
<strong>Tags</strong><text>: </text><br>
<strong>TLDR</strong>: {tldr}<br>
</p>
""".format(**headers)

        return header 
开发者ID:airbnb,项目名称:knowledge-repo,代码行数:23,代码来源:html.py

示例6: ipynb_to_md

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def ipynb_to_md(ipynb_path):
    orig_path = os.getcwd()
    os.chdir(os.path.dirname(ipynb_path))
    file_name = os.path.basename(ipynb_path)
    subprocess.call(['python', '-m', 'nbconvert',
                     '--to', 'markdown', file_name])

    new_s = []
    md_name = file_name.replace('.ipynb', '.md')
    with open(md_name, 'r') as f:
        for line in f:
            if line.startswith('#'):
                new_s.append(line)
                break
        for line in f:
            if line.startswith('## API'):
                new_s.append(line)
                new_s.append('\n')
                break
            new_s.append(line)
        for line in f:
            if line.lstrip().startswith('#'):
                break
        for line in f:
            if line.lstrip().startswith('```'):
                continue
            else:
                new_s.append(line[4:])

    with open(md_name, 'w') as f:
        f.write(''.join(new_s))
    os.chdir(orig_path)


# md = markdown.Markdown(extensions=[ImgExtExtension()])
# html = md.convert(data)
# print(md.images) 
开发者ID:rasbt,项目名称:screenlamp,代码行数:39,代码来源:ipynb2markdown.py

示例7: is_image

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def is_image(self, url: str) -> bool:
        if not self.md.image_preview_enabled:
            return False
        parsed_url = urllib.parse.urlparse(url)
        # remove html urls which end with img extensions that can not be shorted
        if parsed_url.netloc == 'pasteboard.co':
            return False

        # List from https://support.google.com/chromeos/bin/answer.py?hl=en&answer=183093
        for ext in [".bmp", ".gif", ".jpe", "jpeg", ".jpg", ".png", ".webp"]:
            if parsed_url.path.lower().endswith(ext):
                return True
        return False 
开发者ID:zulip,项目名称:zulip,代码行数:15,代码来源:__init__.py

示例8: render

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def render(self, config, files):
        """
        Convert the Markdown source file to HTML as per the config.
        """

        extensions = [
            _RelativePathExtension(self.file, files)
        ] + config['markdown_extensions']

        md = markdown.Markdown(
            extensions=extensions,
            extension_configs=config['mdx_configs'] or {}
        )
        self.content = md.convert(self.markdown)
        self.toc = get_toc(getattr(md, 'toc_tokens', [])) 
开发者ID:mkdocs,项目名称:mkdocs,代码行数:17,代码来源:pages.py

示例9: build_meta_cache

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def build_meta_cache(root):
    """ Recursively search for Markdown files and build a cache of `Meta`
    from metadata in the Markdown.
    :param root: str: The path to search for files from.
    """
    doc_files = glob.iglob(root + '/**/*.md', recursive=True)

    def _meta(path):
        with open(path, 'r', encoding='utf-8') as f:
            md = markdown.Markdown(extensions=mdextensions)
            md.page_root = os.path.dirname(path)
            Markup(md.convert(f.read()))
            return md.Meta if hasattr(md, 'Meta') else None

    doc_files_meta = {os.path.relpath(path, start=root): _meta(path) for path in doc_files}
    doc_files_meta = {path: value for path, value in doc_files_meta.items() if value is not None}

    # If a nav filter is set, exclude relevant documents.
    # This takes the comma separated string supplied to `nav_limit`
    # and excludes certain documents if they are NOT in this list.
    global CMD_ARGS
    if CMD_ARGS.nav_limit:
        nav_filters = CMD_ARGS.nav_limit.split(',')
        nav_filters = [nav_filter.strip().lower() for nav_filter in nav_filters]
        nav_filters = [nav_filter for nav_filter in nav_filters if nav_filter]

        def _should_include(doc_meta):
            nav_strings = [nav.lower() for nav in doc_meta.get('nav', [])]
            return any([y.startswith(x) for x in nav_filters for y in nav_strings])
        doc_files_meta = {path: value for path, value in doc_files_meta.items() if _should_include(value)}

    return doc_files_meta 
开发者ID:HEInventions,项目名称:docnado,代码行数:34,代码来源:docnado.py

示例10: _render_markdown

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def _render_markdown(file_path, **kwargs):
    """ Given a `file_path` render the Markdown and return the result of `render_template`.
    """
    global NAV_MENU, PROJECT_LOGO, PDF_GENERATION_ENABLED
    default_template = 'document'
    with open(file_path, 'r', encoding='utf-8') as f:
        md = markdown.Markdown(extensions=mdextensions)
        md.page_root = os.path.dirname(file_path)
        md.page_file = file_path
        markup = Markup(md.convert(f.read()))

        # Fetch the template defined in the metadata.
        template = md.Meta.get('template', None)
        template = template[0] if template else default_template
        if not template:
            raise Exception('no template found for document')
        template = f'{template}.html'

        # Load any HTML to be injected from the meta-data.
        injections = md.Meta.get('inject', [])
        injections = [os.path.join(md.page_root, file) for file in injections]
        injections = [read_html_for_injection(file) for file in injections]

        # Render it out with all the prepared data.
        return render_template(template,
                               content=markup,
                               nav_menu=NAV_MENU,
                               project_logo=PROJECT_LOGO,
                               pdf_enabled=PDF_GENERATION_ENABLED,
                               injections=injections,
                               **md.Meta,
                               **kwargs) 
开发者ID:HEInventions,项目名称:docnado,代码行数:34,代码来源:docnado.py

示例11: find_references

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def find_references(document_path):
    """ Search through the markdown 'document_path' and make a list of referenced files
    with paths that are relative to the directory containing the `document_path`.
    """
    # Open the file to search.
    with open(document_path, 'r', encoding='utf-8') as f:
        markdown_raw_data = f.read()

    # Render as HTML.
    md = markdown.Markdown(extensions=mdextensions)
    document_dir = os.path.dirname(document_path)
    md.page_root = document_dir

    # Interpret with the BeautifulSoup HTML scraping library.
    soup = BeautifulSoup(md.convert(markdown_raw_data), 'html.parser')
    tags_to_search = {
        'img': 'src',
        'a': 'href',
        'video': 'src',
        'table': 'source',
        'embed': 'src',
    }

    # For each entry in the `tags_to_search` table, extract the tag attribute value.
    references = set()
    for k, v in tags_to_search.items():
        for tag in soup.find_all(k):
            val = tag.get(v)
            if val:
                references.add(val)

    # Normalise the referenced assets (to take into account relative paths).
    references = [os.path.join(document_dir, urllib.request.url2pathname(ref)) for ref in references]

    # Make unique.
    return set(references) 
开发者ID:HEInventions,项目名称:docnado,代码行数:38,代码来源:docnado.py

示例12: __init__

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def __init__(self, md_file):
        """ Open a Markdown document and find all links in `<a href .../>`.
        """
        # Store important information about this document.
        self.md_file = md_file
        self.md_dir = os.path.dirname(md_file)

        # Read in Markdown and generate HTML with our parser.
        with open(md_file, 'r', encoding='utf-8') as f:
            markdown_raw_data = f.read()
        md = markdown.Markdown(extensions=mdextensions)
        md.page_root = self.md_dir
        html = md.convert(markdown_raw_data)

        # Interpret with the BeautifulSoup HTML scraping library.
        soup = BeautifulSoup(html, 'html.parser')

        tags_to_search = {
            'img': 'src',
            'a': 'href',
            'video': 'src',
            'table': 'source',
            'embed': 'src',
        }

        self.references = set()
        for k, v in tags_to_search.items():
            links = soup.find_all(k)

            for link in links:
                if link.get('href'):
                    if link.get('href').find('http:') > -1 or link.get('href').find('https:') > -1:
                        val = link.get(v)
                        if val:
                            self.references.add(val)
                else:
                    val = link.get(v)
                    if val:
                        self.references.add(val) 
开发者ID:HEInventions,项目名称:docnado,代码行数:41,代码来源:docnado.py

示例13: render_post_tldr

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def render_post_tldr(post):
    if isinstance(post, KnowledgePost):
        return markdown.Markdown(extensions=MARKDOWN_EXTENSIONS).convert(post.headers.get('tldr').strip())
    else:
        return markdown.Markdown(extensions=MARKDOWN_EXTENSIONS).convert(post.tldr.strip()) 
开发者ID:airbnb,项目名称:knowledge-repo,代码行数:7,代码来源:render.py

示例14: markdownify

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def markdownify(text, project=None):
    """
    Convert a markdown text to HTML.
    """
    if project and isinstance(project, Project):
        # if the project was specified as parameter, some custom extensions could be loaded
        extra_extensions = [IssueExtension(project),
                            UserExtension(project)]
    else:
        extra_extensions = []

    return bleach.clean(markdown.markdown(text,
                                          extensions=['markdown.extensions.tables',
                                                      'markdown.extensions.nl2br',
                                                      'markdown.extensions.extra',
                                                      'mdx_urlize',
                                                      'markdown_del_ins',
                                                      ] + extra_extensions
                                          ),
                        attributes={u'img': [u'src', u'title', u'height', u'width'],
                                    u'a': [u'href', u'title'],
                                    u'td': [u'align'],
                                    },
                        tags=["p", "b", "a", "i", "img", "ul", "li", "ol", "br", "em",
                              "hr", "h1", "h2", "h3", "h4", "h5", "h6", "pre", "code",
                              "strong", "blockquote", "table", "tr", "td", "th", "thead", "tbody",
                              "del", "ins",
                              ]
                        ) 
开发者ID:iguana-project,项目名称:iguana,代码行数:31,代码来源:markdownify.py

示例15: extract_code_blocks

# 需要导入模块: import markdown [as 别名]
# 或者: from markdown import extensions [as 别名]
def extract_code_blocks(filename):
    with open(filename) as fin:
        doc = fin.read().split("\n")

    M = markdown.Markdown(extensions=[SpecialFencedCodeExtension()])

    preprocessors = M.preprocessors
    tree_processors = M.treeprocessors

    try:
        version_info = markdown.__version_info__
    except AttributeError:
        version_info = markdown.version_info

    # Markdown 3.* stores the processors in a class that can be iterated directly.
    # Markdown 2.* stores them in a dict, so we have to pull out the values.
    if version_info[0] == 2:
        # Note: `markdown.version_info` will be deprecated in favor of
        # `markdown.__version_info__` in later versions of Markdown.
        preprocessors = preprocessors.values()
        tree_processors = tree_processors.values()

    for prep in preprocessors:
        doc = prep.run(doc)

    root = M.parser.parseDocument(doc).getroot()

    for treeproc in tree_processors:
        newRoot = treeproc.run(root)
        if newRoot is not None:
            root = newRoot

    return SpecialFencePreprocessor.EXAMPLES 
开发者ID:cwacek,项目名称:python-jsonschema-objects,代码行数:35,代码来源:markdown_support.py


注:本文中的markdown.extensions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。