How to use the mistune.preprocessing function in mistune

To help you get started, we’ve selected a few mistune examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github huntzhan / zhlint / tests / test_preprocessor.py View on Github external
def load_test_md(name):
    return preprocessing(
        open(os.path.join(DATA, name), encoding='utf-8').read(),
    )
github huntzhan / zhlint / zhlint / main.py View on Github external
def fix(src, dst):
    file_content = preprocessing(src.read())
    text_elements = transform(file_content)

    correction_handler = ErrorCorrectionHandler(file_content, text_elements)
    for text_element in text_elements:
        process_errors(correction_handler, text_element)

    try:
        correction_executor = DiffOperationExecutor(
            correction_handler.diffs,
            correction_handler.raw_lines,
        )
        fixed = correction_executor.apply_diff_operations()
    except RuntimeError:
        click.echo('Something Wrong.')
        sys.exit(1)
github pytorch / hub / scripts / sanity_check.py View on Github external
def validate_markdown(self, markdown):
        m = mistune.Markdown()
        blocks = m.block(mistune.preprocessing(markdown))

        for block in blocks:
            if block['type'] == 'heading':
                # we dont want colon after section names
                assert not block['text'].endswith(':')
                if block['text'] in self.required_sections:
                    self.required_sections.remove(block['text'])
        try:
            assert len(self.required_sections) == 0
        except AssertionError as e:
            print("Missing required sections: {}".format(self.required_sections))
            raise e