Exemplo n.º 1
0
 def read(self, contents):
     assert isinstance(contents, string_types)
     parser = Parser()
     contents = _parse_math(contents)
     cm = parser.parse(contents)
     ast = CommonMarkToAST().transform_main(cm)
     return ast
Exemplo n.º 2
0
def main(argv: List[str]):
    args = parse_args(argv)

    flags = ValidatorFlags(0)
    categories = args.validate.split(",")
    for category in categories:
        category = category.lower()
        if category == "all":
            flags |= ValidatorFlags.ALL
        elif category == "external":
            flags |= ValidatorFlags.EXTERNAL
        elif category == "local":
            flags |= ValidatorFlags.LOCAL
        elif category == "link":
            flags |= ValidatorFlags.LINK
        elif category == "anchor":
            flags |= ValidatorFlags.ANCHOR
        elif category == "image":
            flags |= ValidatorFlags.IMAGE
        else:
            raise Exception("unknown category '{}'".format(category))

    for filename in args.FILE:
        if args.dump_ast:
            with open(filename) as fin:
                parser = Parser()
                document = parser.parse(fin.read())
                dumpAST(document)
        else:
            validator = Validator(filename)
            validator.set_flags(flags)
            validator.validate()
Exemplo n.º 3
0
 def parse(self, inputstring, document):
     self.document = document
     self.current_node = document
     self.setup_parse(inputstring, document)
     self.setup_sections()
     parser = Parser()
     ast = parser.parse(inputstring + '\n')
     self.convert_ast(ast)
     self.finish_parse()
Exemplo n.º 4
0
 def parse(self, inputstring, document):
     self.document = document
     self.current_node = document
     self.setup_parse(inputstring, document)
     self.setup_sections()
     parser = Parser()
     ast = parser.parse(inputstring + '\n')
     self.convert_ast(ast)
     self.finish_parse()
def latex_markdown(value):
    """Turns markdown into LaTeX and returns it
    """
    if not has_markdown:
        raise ImproperlyConfigured('CommonMark needs to be installed')
    parser = Parser()
    ast = parser.parse(value)
    lr = LatexRenderer()
    latex = lr.render(ast)
    return mark_safe(latex)
Exemplo n.º 6
0
    def validate(self) -> None:
        with open(self._filename) as fin:
            parser = Parser()
            document = parser.parse(fin.read())

            for node, starttag in document.walker():
                self.preprocess(node, starttag)

            for node, starttag in document.walker():
                self.check(node, starttag)
    def test_inline_formatting(self):
        case = """
The **quick** brown _fox_ jumped over the __lazy__ cow.
        """
        parser = Parser()
        ast = parser.parse(case)
        lr = LatexRenderer()
        latex = lr.render(ast)
        self.assertEquals(latex, (
            'The \\textbf{quick} brown \\emph{fox} jumped over'
            ' the \\textbf{lazy} cow.\n\n'
        ))
   def test_escape(self):
       case = """
\begin{parahrah}
   \\textt{NO}
\end{paragraph}
       """
       parser = Parser()
       ast = parser.parse(case)
       lr = LatexRenderer()
       latex = lr.render(ast)
       self.assertEquals(latex, (
           '\\textbackslash{}begin\{parahrah\}\\textbackslash'
           '{}textt\{NO\}\\textbackslash{}end\{paragraph\}\n\n'
       ))
Exemplo n.º 9
0
    def parse(self, inputstring, document):
        self.setup_parse(inputstring, document)

        self.document = document
        self.current_node = document
        self.section_handler = _SectionHandler(document)

        parser = Parser()

        ast = parser.parse(inputstring + '\n')

        self.convert_block(ast)

        self.finish_parse()
Exemplo n.º 10
0
    def parse(self, inputstring, document):
        self.setup_parse(inputstring, document)

        self.document = document
        self.current_node = document
        self.section_handler = _SectionHandler(document)

        parser = Parser()

        ast = parser.parse(inputstring + '\n')

        self.convert_block(ast)

        self.finish_parse()
Exemplo n.º 11
0
    def test_list(self):
        case = """
Shopping list:

* Eggs
* Cheese
* Lager
        """
        parser = Parser()
        ast = parser.parse(case)
        lr = LatexRenderer()
        latex = lr.render(ast)
        self.assertEquals(latex, (
            'Shopping list:\n\n\\begin{enumerate}\\item Eggs\n\n'
            '\\item Cheese\n\n\\item Lager\n\n\\end{enumerate}'
        ))
Exemplo n.º 12
0
    def test_paragraphs(self):
        case = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nullam augue felis, eleifend at quam id, molestie placerat felis.
Nunc laoreet sapien tellus, ac blandit arcu lobortis eu. Etiam sit amet ex commodo, condimentum felis quis, suscipit nunc. Duis eu egestas diam, sed placerat arcu. Aliquam vestibulum consectetur ipsum a ullamcorper. Integer pretium eros a nisl cursus tristique. Cras in molestie nisi, nec dictum 
nunc. Phasellus ultrices euismod tortor, vel molestie mi cursus
eu. Integer blandit et urna vel molestie. Pellentesque et est
et arcu tincidunt maximus.

Morbi dignissim, risus ac ornare accumsan, ex magna accumsam
diam, ac interdum nisl enim nec justo. Donec efficitur, tortor
non ornare sagittis, sapien tellus rutrum neque, quis lobortis sapien
urna vitae magna. Pellentesque dictum magna eu urna commodo,
a vulputate massa fringilla. Sed egestas sodales libero, sed blandit
dui gravida sit amet. Mauris egestas consectetur leo in tincidunt.
Vivamus bibendum sodales risus. Maecenas bibendum justo non auctor
ullamcorper. Sed felis ipsum,
viverra non justo id, congue fringilla neque. Proin a facilisis lectus.

Suspendisse potenti. Proin vitae diam sem. Nam accumsan nisi vel
diam accumsan, at porta dui tempus. In in nunc pellentesque ligula
porta iaculis. Aenean ultricies ante ex, nec fringilla felis
sollicitudin non. Ut diam est, varius a mi id, commodo tincidunt dui.
Donec et ante consequat, consequat elit vitae, rutrum justo. Ut mattis
ex porta nibh porta mattis. Suspendisse sit amet est turpis. Donec a
fermentum diam, semper dapibus ipsum. Duis volutpat libero et quam
rutrum porta.

Nulla nec suscipit nunc. Duis ut ligula ac neque condimentum commodo.
Donec eu ullamcorper felis. Ut rhoncus lectus vel sapien blandit varius.
Ut aliquet odio ligula, sit amet viverra augue interdum nec. Donec
sodales, turpis sed suscipit euismod, ex erat venenatis neque, ut
dictum ipsum ante ac urna. Vestibulum at magna id lacus luctus
fermentum. Pellentesque nisi purus, tempus eu faucibus sed, fringilla
sit amet justo. In laoreet, nisl sed posuere vulputate, lorem augue
placerat ipsum, at facilisis quam odio ut est. Proin eget enim dui.
Morbi id feugiat mauris, in faucibus odio. Nam quis venenatis quam.
Fusce leo velit, ullamcorper in leo vestibulum, ultricies pulvinar
neque. Suspendisse semper eros sit amet diam bibendum fringilla.
Vestibulum consectetur venenatis erat a faucibus. Integer tristique
eleifend mauris.
        """
        parser = Parser()
        ast = parser.parse(case)
        lr = LatexRenderer()
        latex = lr.render(ast)
        self.assertEquals(latex.count('\n\n'), 4)
Exemplo n.º 13
0
    def test_headings(self):
        case = """
# Heading 1

## Heading 2

### Heading 3

#### Heading 4

##### Heading 5

##### Heading 6
        """
        parser = Parser()
        ast = parser.parse(case)
        lr = LatexRenderer()
        latex = lr.render(ast)

        self.assertEquals(latex.count('\huge'), 2)
        self.assertEquals(latex.count('\LARGE'), 1)
        self.assertEquals(latex.count('\Large'), 1)
        self.assertEquals(latex.count('\large'), 2)
Exemplo n.º 14
0
def commonmark():
    contents = 'hello *world*'
    parser = Parser()
    cm = parser.parse(contents)
    return cm
Exemplo n.º 15
0
 def read_markdown(self, contents):
     parser = Parser()
     contents = _parse_math(contents)
     cm = parser.parse(contents)
     ast = CommonMarkToAST().transform_main(cm)
     return ast
Exemplo n.º 16
0
def commonmark():
    contents = 'hello *world*'
    parser = Parser()
    cm = parser.parse(contents)
    return cm
Exemplo n.º 17
0
 def read_markdown(self, contents):
     parser = Parser()
     contents = _parse_math(contents)
     cm = parser.parse(contents)
     ast = CommonMarkToAST().transform_main(cm)
     return ast