How to use the mistune.BlockLexer.default_rules 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 lepture / mistune / tests / test_subclassing.py View on Github external
import mistune

root = os.path.dirname(__file__)


class MathBlockGrammar(mistune.BlockGrammar):
    block_math = re.compile(r'^\$\$(.*?)\$\$', re.DOTALL)
    latex_environment = re.compile(
        r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}",
        re.DOTALL
    )


class MathBlockLexer(mistune.BlockLexer):
    default_rules = ['block_math', 'latex_environment'] + \
        mistune.BlockLexer.default_rules

    def __init__(self, rules=None, **kwargs):
        if rules is None:
            rules = MathBlockGrammar()
        super(MathBlockLexer, self).__init__(rules, **kwargs)

    def parse_block_math(self, m):
        """Parse a $$math$$ block"""
        self.tokens.append({
            'type': 'block_math',
            'text': m.group(1)
        })

    def parse_latex_environment(self, m):
        self.tokens.append({
            'type': 'latex_environment',
github miyakogi / m2r / m2r.py View on Github external
r'^( *\.\..*?)$',
            re.DOTALL | re.MULTILINE,
        )
    rest_code_block = re.compile(
            r'^::\s*$',
            re.DOTALL | re.MULTILINE,
        )


class RestBlockLexer(mistune.BlockLexer):
    grammar_class = RestBlockGrammar
    default_rules = [
        'directive',
        'oneline_directive',
        'rest_code_block',
    ] + mistune.BlockLexer.default_rules

    def parse_directive(self, m):
        self.tokens.append({
            'type': 'directive',
            'text': m.group(1),
        })

    def parse_oneline_directive(self, m):
        # reuse directive output
        self.tokens.append({
            'type': 'directive',
            'text': m.group(1),
        })

    def parse_rest_code_block(self, m):
        self.tokens.append({
github nitely / Spirit / spirit / core / utils / markdown / block.py View on Github external
r'(?:\s+min=(?P[0-9]+))?'
        r'(?:\s+max=(?P[0-9]+))?'
        r'(?:\s+close=(?P[0-9]+)d)?'
        r'(?:\s+mode=(?P(default|secret)))?'
        r'|(?P[^\]]*))'
        r'\])\n'
        r'((?:#\s*(?P<title>[^\n]+\n))?'
        r'(?P&lt;choices&gt;(?:[0-9]+\.\s*[^\n]+\n){2,})'
        r'|(?P&lt;invalid_body&gt;(?:[^\n]+\n)*))'
        r'(?:\[/poll\])'
    )


class BlockLexer(mistune.BlockLexer):

    default_rules = copy.copy(mistune.BlockLexer.default_rules)
    default_rules.insert(0, 'block_math')
    default_rules.insert(0, 'block_math_brackets')
    default_rules.insert(0, 'block_latex')
    default_rules.insert(0, 'block_link')
    default_rules.insert(0, 'poll')

    _sub_block_links = (
        'audio_link',
        'image_link',
        'video_link',
        'youtube_link',
        'vimeo_link',
        'gfycat_link'
    )

    def __init__(self, rules=None, **kwargs):</title>
github spacetelescope / asdf-standard / source / sphinxext / md2rst.py View on Github external
def enable_math(self):
        self.rules.block_math = re.compile(r'^\$\$(.*?)\$\$', re.DOTALL)
        self.default_rules = ['block_math'] + mistune.BlockLexer.default_rules
github sobhe / moratab / moratab / math.py View on Github external
"""
	Support Math features for mistune.

	:copyright: (c) 2014 by Hsiaoming Yang.
"""

import re, mistune


class MathBlockGrammar(mistune.BlockGrammar):
	block_math = re.compile(r"^\$\$(.*?)\$\$", re.DOTALL)
	latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}", re.DOTALL)

class MathBlockLexer(mistune.BlockLexer):
	default_rules = ['block_math', 'latex_environment'] + mistune.BlockLexer.default_rules

	def __init__(self, rules=None, **kwargs):
		if rules is None:
			rules = MathBlockGrammar()
		super(MathBlockLexer, self).__init__(rules, **kwargs)

	def parse_block_math(self, m):
		"""Parse a $$math$$ block"""
		self.tokens.append({
			'type': 'block_math',
			'text': m.group(1)
		})

	def parse_latex_environment(self, m):
		self.tokens.append({
			'type': 'latex_environment',
github cuthbertLab / music21 / music21 / ext / nbconvert / filters / markdown_mistune.py View on Github external
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
from pygments.util import ClassNotFound

from nbconvert.filters.strings import add_anchor
from nbconvert.utils.exceptions import ConversionException


class MathBlockGrammar(mistune.BlockGrammar):
    block_math = re.compile(r"^\$\$(.*?)\$\$", re.DOTALL)
    latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}",
                                                re.DOTALL)

class MathBlockLexer(mistune.BlockLexer):
    default_rules = ['block_math', 'latex_environment'] + mistune.BlockLexer.default_rules

    def __init__(self, rules=None, **kwargs):
        if rules is None:
            rules = MathBlockGrammar()
        super(MathBlockLexer, self).__init__(rules, **kwargs)

    def parse_block_math(self, m):
        """Parse a $$math$$ block"""
        self.tokens.append({
            'type': 'block_math',
            'text': m.group(1)
        })

    def parse_latex_environment(self, m):
        self.tokens.append({
            'type': 'latex_environment',
github ipython / ipython / IPython / nbconvert / filters / markdown_mistune.py View on Github external
from pygments.util import ClassNotFound

from IPython.nbconvert.filters.strings import add_anchor
from IPython.nbconvert.utils.exceptions import ConversionException
from IPython.utils.decorators import undoc


@undoc
class MathBlockGrammar(mistune.BlockGrammar):
    block_math = re.compile(r"^\$\$(.*?)\$\$", re.DOTALL)
    latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}",
                                                re.DOTALL)

@undoc
class MathBlockLexer(mistune.BlockLexer):
    default_rules = ['block_math', 'latex_environment'] + mistune.BlockLexer.default_rules

    def __init__(self, rules=None, **kwargs):
        if rules is None:
            rules = MathBlockGrammar()
        super(MathBlockLexer, self).__init__(rules, **kwargs)

    def parse_block_math(self, m):
        """Parse a $$math$$ block"""
        self.tokens.append({
            'type': 'block_math',
            'text': m.group(1)
        })

    def parse_latex_environment(self, m):
        self.tokens.append({
            'type': 'latex_environment',
github mattvonrocketstein / smash / smashlib / ipy3x / nbconvert / filters / markdown.py View on Github external
Output as returned by pandoc.
    """
    return pandoc(source, markup, 'latex', extra_args=extra_args)


@undoc
class MathBlockGrammar(mistune.BlockGrammar):
    block_math = re.compile("^\$\$(.*?)\$\$", re.DOTALL)
    latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}",
                                   re.DOTALL)


@undoc
class MathBlockLexer(mistune.BlockLexer):
    default_rules = ['block_math', 'latex_environment'] + \
        mistune.BlockLexer.default_rules

    def __init__(self, rules=None, **kwargs):
        if rules is None:
            rules = MathBlockGrammar()
        super(MathBlockLexer, self).__init__(rules, **kwargs)

    def parse_block_math(self, m):
        """Parse a $$math$$ block"""
        self.tokens.append({
            'type': 'block_math',
            'text': m.group(1)
        })

    def parse_latex_environment(self, m):
        self.tokens.append({
            'type': 'latex_environment',
github xalanq / ITree / imarkdown.py View on Github external
# LICENSE: LGPL v3.0

# markdown stuff

import mistune, re

# Thanks https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown_mistune.py

class MathBlockGrammar(mistune.BlockGrammar):
	block_math = re.compile(r"^\$\$(.*?)\$\$", re.DOTALL)
	latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}",
												re.DOTALL)


class MathBlockLexer(mistune.BlockLexer):
	default_rules = ['block_math', 'latex_environment'] + mistune.BlockLexer.default_rules

	def __init__(self, rules=None, **kwargs):
		if rules is None:
			rules = MathBlockGrammar()
		super(MathBlockLexer, self).__init__(rules, **kwargs)

	def parse_block_math(self, m):
		"""Parse a $$math$$ block"""
		self.tokens.append({
			'type': 'block_math',
			'text': m.group(1)
		})

	def parse_latex_environment(self, m):
		self.tokens.append({
			'type': 'latex_environment',
github tensorforce / tensorforce / docs / m2r.py View on Github external
r'^( *\.\..*?)$',
            re.DOTALL | re.MULTILINE,
        )
    rest_code_block = re.compile(
            r'^::\s*$',
            re.DOTALL | re.MULTILINE,
        )


class RestBlockLexer(mistune.BlockLexer):
    grammar_class = RestBlockGrammar
    default_rules = [
        'directive',
        'oneline_directive',
        'rest_code_block',
    ] + mistune.BlockLexer.default_rules

    def parse_directive(self, m):
        self.tokens.append({
            'type': 'directive',
            'text': m.group(1),
        })

    def parse_oneline_directive(self, m):
        # reuse directive output
        self.tokens.append({
            'type': 'directive',
            'text': m.group(1),
        })

    def parse_rest_code_block(self, m):
        self.tokens.append({