Python markdown.preprocessors() Examples

The following are 12 code examples of markdown.preprocessors(). 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: markdown_extension.py    From zulip with Apache License 2.0 5 votes vote down vote up
def extendMarkdown(self, md: markdown.Markdown, md_globals: Dict[str, Any]) -> None:
        md.preprocessors.add(
            'generate_code_example', APICodeExamplesPreprocessor(md, self.getConfigs()), '_begin',
        )
        md.preprocessors.add(
            'generate_api_description', APIDescriptionPreprocessor(md, self.getConfigs()), '_begin',
        ) 
Example #2
Source File: tabbed_sections.py    From zulip with Apache License 2.0 5 votes vote down vote up
def extendMarkdown(self, md: markdown.Markdown, md_globals: Dict[str, Any]) -> None:
        md.preprocessors.add(
            'tabbed_sections', TabbedSectionsPreprocessor(md, self.getConfigs()), '_end') 
Example #3
Source File: help_relative_links.py    From zulip with Apache License 2.0 5 votes vote down vote up
def extendMarkdown(self, md: markdown.Markdown, md_globals: Dict[str, Any]) -> None:
        """ Add RelativeLinksHelpExtension to the Markdown instance. """
        md.registerExtension(self)
        md.preprocessors.add('help_relative_links', RelativeLinks(), '_begin') 
Example #4
Source File: help_settings_links.py    From zulip with Apache License 2.0 5 votes vote down vote up
def extendMarkdown(self, md: markdown.Markdown, md_globals: Dict[str, Any]) -> None:
        """ Add SettingHelpExtension to the Markdown instance. """
        md.registerExtension(self)
        md.preprocessors.add('setting', Setting(), '_begin') 
Example #5
Source File: api_arguments_table_generator.py    From zulip with Apache License 2.0 5 votes vote down vote up
def extendMarkdown(self, md: markdown.Markdown, md_globals: Dict[str, Any]) -> None:
        md.preprocessors.add(
            'generate_api_arguments', APIArgumentsTablePreprocessor(md, self.getConfigs()), '_begin',
        ) 
Example #6
Source File: api_return_values_table_generator.py    From zulip with Apache License 2.0 5 votes vote down vote up
def extendMarkdown(self, md: markdown.Markdown, md_globals: Dict[str, Any]) -> None:
        md.preprocessors.add(
            'generate_return_values', APIReturnValuesTablePreprocessor(md, self.getConfigs()), '_begin',
        ) 
Example #7
Source File: markdown-processor.py    From pygments with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def extendMarkdown(self, md, md_globals):
        md.preprocessors.add('CodeBlockPreprocessor', CodeBlockPreprocessor(), '_begin') 
Example #8
Source File: html.py    From knowledge-repo with Apache License 2.0 5 votes vote down vote up
def extendMarkdown(self, md, md_globals=None):
        md.preprocessors.add("code_isolation",
                             IndentsAsCellOutputPreprocessor(md),
                             "<html_block")
        md.parser.blockprocessors['code'] = IndentsAsCellOutputProcessor(md.parser) 
Example #9
Source File: html.py    From knowledge-repo with Apache License 2.0 5 votes vote down vote up
def extendMarkdown(self, md, md_globals=None):
        """ Add MetaPreprocessor to Markdown instance. """
        md.preprocessors.add("knowledge_meta",
                             KnowledgeMetaPreprocessor(md),
                             ">normalize_whitespace") 
Example #10
Source File: markdown_support.py    From python-jsonschema-objects with MIT License 5 votes vote down vote up
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 
Example #11
Source File: markdown_support.py    From python-jsonschema-objects with MIT License 5 votes vote down vote up
def extendMarkdown(self, md, md_globals=None):
        """ Add FencedBlockPreprocessor to the Markdown instance. """
        md.registerExtension(self)

        if markdown.version_info[0] >= 3:
            md.preprocessors.register(
                SpecialFencePreprocessor(md), "fenced_code_block", 10
            )
        else:
            md.preprocessors.add(
                "fenced_code_block",
                SpecialFencePreprocessor(md),
                ">normalize_whitespace",
            ) 
Example #12
Source File: compat.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def md_filter_add_syntax_highlight(md):
        md.preprocessors.add('highlight', CodeBlockPreprocessor(), "_begin")
        return True