Exemplo n.º 1
0
def render(source, headerleveloffset=0):
    """
    Render markdown with Steak Renderer
    """
    parser = Parser()
    ast = parser.parse(source)
    renderer = SteakRenderer(headerleveloffset=headerleveloffset)
    return renderer.render(ast)
Exemplo n.º 2
0
class TestParser(unittest.TestCase):
    def setUp(self):
        self.parser = Parser()

    @given(text())
    @example('')
    @example('* unicode: \u2020')
    def test_text(self, s):
        self.parser.parse(s)
Exemplo n.º 3
0
class TestParser(unittest.TestCase):
    def setUp(self):
        self.parser = Parser()

    def test_empty_string(self):
        self.parser.parse('')

    def test_unicode(self):
        self.parser.parse('* unicode: \u2020')
Exemplo n.º 4
0
class TestParser(unittest.TestCase):
    def setUp(self):
        self.parser = Parser()

    @given(text())
    @example('')
    @example('* unicode: \u2020')
    def test_text(self, s):
        self.parser.parse(s)
Exemplo n.º 5
0
def commonmark(text, format="html"):
    """Render CommonMark into HTML, JSON or AST
    Optional keyword arguments:
    format:     'html' (default), 'json' or 'ast'

    >>> commonmark("*hello!*")
    '<p><em>hello</em></p>\\n'
    """
    parser = Parser()
    ast = parser.parse(text)
    if format not in ["html", "json", "ast"]:
        raise ValueError("format must be 'html', 'json' or 'ast'")
    if format == "html":
        renderer = HTMLRenderer()
        return renderer.render(ast)
    if format == "json":
        return ASTtoJSON(ast)
    if format == "ast":
        return dumpAST(ast)
Exemplo n.º 6
0
def commonmark(text, format="html"):
    """Render CommonMark into HTML, JSON or AST
    Optional keyword arguments:
    format:     'html' (default), 'json' or 'ast'

    >>> commonmark("*hello!*")
    '<p><em>hello</em></p>\\n'
    """
    parser = Parser()
    ast = parser.parse(text)
    if format not in ["html", "json", "ast"]:
        raise ValueError("format must be 'html', 'json' or 'ast'")
    if format == "html":
        renderer = HtmlRenderer()
        return renderer.render(ast)
    if format == "json":
        return ASTtoJSON(ast)
    if format == "ast":
        return dumpAST(ast)
Exemplo n.º 7
0
    def test_normalize_contracts_text_nodes(self):
        md = '_a'
        ast = Parser().parse(md)

        def assert_text_literals(text_literals):
            walker = ast.walker()
            document, _ = walker.next()
            self.assertEqual(document.t, 'document')
            paragraph, _ = walker.next()
            self.assertEqual(paragraph.t, 'paragraph')
            for literal in text_literals:
                text, _ = walker.next()
                self.assertEqual(text.t, 'text')
                self.assertEqual(text.literal, literal)
            paragraph, _ = walker.next()
            self.assertEqual(paragraph.t, 'paragraph')

        assert_text_literals(['_', 'a'])
        ast.normalize()
        # assert text nodes are contracted
        assert_text_literals(['_a'])
        ast.normalize()
        # assert normalize() doesn't alter a normalized ast
        assert_text_literals(['_a'])
Exemplo n.º 8
0
 def test_dumpAST_orderedlist(self):
     md = '1.'
     ast = Parser().parse(md)
     CommonMark.dumpAST(ast)
Exemplo n.º 9
0
 def setUp(self):
     self.parser = Parser()
Exemplo n.º 10
0
 def setUp(self):
     self.parser = Parser()