예제 #1
0
 def test_end_with_empty_line(self):
     doc = dedent(r"""
     \tag
         
         """)
     parser = QqParser(allowed_tags={"tag"})
     tree = parser.parse(doc)
예제 #2
0
 def test_inlinetag_with_multiple_arguments(self):
     doc = r"""\blocktag Some \inlinetag[Hello][world]"""
     parser = QqParser(allowed_tags={'inlinetag', 'blocktag'})
     tree = parser.parse(doc)
     self.assertEqual(tree.as_list(),
                      ["_root", ["blocktag", "Some ",
                                 ["inlinetag", ["_item", "Hello"],
                                  ["_item", "world"]]]])
예제 #3
0
    def test_inline_tag1(self):
        doc = r"""Hello, \tag{inline} tag!
"""
        parser = QqParser(allowed_tags={'tag'})
        tree = parser.parse(doc)
        self.assertEqual(tree[0], 'Hello, ')
        self.assertEqual(tree.tag_.value, 'inline')
        self.assertEqual(tree[2], ' tag!')
예제 #4
0
    def test_inline_tag2(self):
        doc = r"""Hello, \othertag{\tag{inline} tag}!
"""
        parser = QqParser(allowed_tags={'tag', 'othertag'})
        tree = parser.parse(doc)
       # self.assertEqual(tree._othertag._tag.value, 'inline')
        self.assertEqual(tree.as_list(), ['_root', 'Hello, ',
                                          ['othertag', ['tag', 'inline'],
                                           ' tag'], '!'])
예제 #5
0
 def test_multiline_inline_with_attribute(self):
     doc = "\\tag{hello \\tag world \n this is \n a \\tag test}"
     parser = QqParser(allowed_tags={"tag"})
     tree = parser.parse(doc)
     self.assertEqual(tree.as_list(),
                      ['_root',
                       ['tag', 'hello ',
                        ['tag', 'world \n this is \n a'],
                        ['tag', 'test']]])
예제 #6
0
    def test_alias2tag(self):
        doc = r"""\# Heading 1
\## Heading 2
Hello
"""
        parser = QqParser(allowed_tags={'h1', 'h2'},
                          alias2tag={"#": 'h1', "##": 'h2'})
        tree = parser.parse(doc)
        self.assertEqual(tree.as_list(),
                         ["_root", ["h1", "Heading 1"],
                          ["h2", "Heading 2"], "Hello"])
예제 #7
0
    def test_block_additional_indent(self):
        doc = r"""Hello
\tag
    First
        Second
    Third
End"""
        parser = QqParser(allowed_tags={'tag'})
        tree = parser.parse(doc)
        self.assertEqual(tree.tag_._children,
                         ['First\n    Second\nThird'])
예제 #8
0
    def test_empty_square_bracket_tag(self):
        doc = r"""\blocktag
    Some \empty[

    ] tag
"""
        parser = QqParser(allowed_tags={'blocktag', 'empty'})
        tree = parser.parse(doc)
        self.assertEqual(tree.as_list(),["_root", ['blocktag', 'Some ',
                                                   ['empty',
                                                    ['_item', '\n']],
                                                   ' tag']])
예제 #9
0
    def test_blocktag_inside_inlinetag(self):
        doc = r"""\blocktag Some \inlinetag[Hello \blocktag test]"""
        parser = QqParser(allowed_tags={'inlinetag', 'blocktag'})
        tree = parser.parse(doc)

        self.assertEqual(tree.as_list(), ['_root', ['blocktag', 'Some ',
                                          ['inlinetag',
                                           ['_item', 'Hello ',
                                            ['blocktag', 'test']]]]])

        doc = r"""Some \inlinetag[Hello \blocktag test
        \blocktag another test]"""
        parser = QqParser(allowed_tags={'inlinetag', 'blocktag'})
        tree = parser.parse(doc)
        print(tree.as_list())
        self.assertEqual(tree.as_list(),
                         ['_root', 'Some ', ['inlinetag',
                                             ['_item', 'Hello ',
                                              ['blocktag', 'test'],
                                              ['blocktag',
                                               'another test']]]])
예제 #10
0
 def test_newline(self):
     doc = dedent(r"""
     \tag
         Hello
     
     Stop.
     """)
     parser = QqParser(allowed_tags={'tag'})
     tree = parser.parse(doc)
     self.assertEqual(tree.as_list(),
                      ['_root', '', ['tag', 'Hello'],
                       '\nStop.'])
예제 #11
0
    def test_block_tags1(self):
        doc = r"""Hello
\tag
    World
"""
        parser = QqParser(allowed_tags={'tag'})
        tree = parser.parse(doc)
        print(tree.as_list())
        self.assertEqual(tree[0], "Hello")

        self.assertEqual(tree.tag_.name, 'tag')
        self.assertEqual(tree.tag_.value, 'World')
예제 #12
0
    def test_inline_tag4(self):
        doc = r"Hello, \tag{I'm [your{taggy}] tag} okay"
        parser = QqParser(allowed_tags={'tag', 'othertag'})
        tree = parser.parse(doc)
        self.assertEqual(tree.as_list(), [
            '_root', 'Hello, ',
            [
                'tag',
                "I'm [your{taggy}] tag"
            ],
            " okay"
        ])

        def test_block_and_inline_tags(self):
            doc = r"""Hello,
    \tag
        I'm your \othertag{tag}
        \tag
            {
            \tag
                {
                this \tag{is a {a test}
                okay}
            }
        }
    """
            parser = QqParser(allowed_tags={'tag', 'othertag'})
            tree = parser.parse(doc)
            self.assertEqual(tree.as_list(), [
                '_root', 'Hello,\n',
                [
                    'tag',
                    "I'm your ",
                    ['othertag', 'tag'],
                    '\n',
                    [
                        'tag',
                        '{\n',
                        [
                            'tag',
                            '{\nthis ',
                            [
                                'tag',
                                'is a {a test}\nokay',
                            ],
                            '\n'
                        ],
                        '}\n'
                    ],
                    '}\n'
                ]
            ])
예제 #13
0
 def test_mixed_brackets_inline(self):
     doc = r"Some inline \tag[with]{multiple}[arguments]"
     parser = QqParser(allowed_tags={"tag"})
     tree = parser.parse(doc)
     self.assertEqual(tree.as_list(),
                      [
                          "_root", "Some inline ",
                          ["tag",
                           ["_item", "with"],
                           "multiple",
                           ["_item", "arguments"]
                           ]
                      ])
예제 #14
0
 def test_blank_line_after_tag(self):
     doc = dedent(r"""
         \tag
         
             otherline
             \tag
                 othertag
     """)
     parser = QqParser(allowed_tags={"tag"})
     tree = parser.parse(doc)
     self.assertEqual(tree.as_list(),
                      ['_root', '',
                       ['tag', '\notherline', ['tag', 'othertag']]])
예제 #15
0
 def test_as_etree(self):
     doc = dedent(r"""
     \tag
         some content
         \tag
             other content
         more text here
     """)
     parser = QqParser(allowed_tags={"tag"})
     tree = parser.parse(doc)
     self.assertEqual(et.tostring(tree.as_etree()),
                      b'<_root><tag>some content'
                      b'<tag>other content'
                      b'</tag>more text here'
                      b'</tag></_root>')
예제 #16
0
 def test_inline_tag_at_the_beginning_of_the_line(self):
     doc = r"""\tag
 some content here here and here and we have some inline
 \tag{here and \othertag{there}}
 """
     parser = QqParser(allowed_tags={'tag', 'othertag'})
     tree = parser.parse(doc)
     self.assertEqual(tree.as_list(), ['_root', ['tag','some content '
                                                       'here here and '
                                                       'here and we '
                                                       'have some '
                                                       'inline\n',
                                       ['tag', 'here and ',['othertag',
                                                            'there']],
                                                 '']])
예제 #17
0
 def test_children_tags(self):
     doc = dedent(r"""
             \tag
                 some content
                 \tag
                     other content
                 more text here
                 \tag
                     some other tag
             """)
     parser = QqParser(allowed_tags={"tag"})
     tree = parser.parse(doc)
     childrens = (list(tree.tag_.children_tags()))
     self.assertEqual(childrens[0].as_list(), ["tag", "other content"])
     self.assertEqual(childrens[1].as_list(), ["tag",
                                               "some other tag"])
예제 #18
0
    def test_multiple_arguments2(self):
        doc = r"""\proof
    By \ref[existence
    and uniqueness theorem\nonumber][thm:4:eu] there exists
"""
        parser = QqParser(allowed_tags={"proof", "ref", "nonumber"})
        tree = parser.parse(doc)
        print(tree.as_list())
        self.assertEqual(tree.as_list(),
                         ['_root', ['proof', 'By ',
                                    ['ref',
                                     ['_item',
                                      'existence\nand uniqueness theorem',
                                      ['nonumber']],
                                     ['_item',
                                      'thm:4:eu']],
                                    ' there exists']])
예제 #19
0
    def test_inline_tag3(self):
        doc = r"""Hello, \tag{
this is a continuation of inline tag on the next line

the next one\othertag{okay}}
"""
        parser = QqParser(allowed_tags={'tag', 'othertag'})
        tree = parser.parse(doc)
        self.assertEqual(tree.as_list(), [
            '_root', 'Hello, ',
            [
                'tag',
                ('\nthis is a continuation of inline tag on the next line'
                 '\n\nthe next one'),
                [
                    'othertag',
                    'okay'
                ]
            ], ''
        ])
예제 #20
0
    def test_block_tags_nested(self):
        doc = r"""Hello
\tag
    World
    \othertag
        This
        Is
    A test
The end

Blank line before the end
"""
        parser = QqParser(allowed_tags={'tag', 'othertag'})
        tree = parser.parse(doc)
        print(tree.as_list())
        self.assertEqual(tree[0], "Hello")
        self.assertEqual(tree.tag_[0], "World")
        self.assertEqual(tree.tag_.othertag_._children, ["This\nIs"])
        self.assertEqual(tree.tag_[2], 'A test')
        self.assertEqual(tree[2], 'The end\n\nBlank line before the end')
        self.assertEqual(tree.tag_.parent, tree)
        self.assertEqual(tree.tag_.othertag_.parent, tree.tag_)
예제 #21
0
    def test_escape_unescape(self):
        doc = r"""Hello
\sometag test
\\sometag test
\sometag
    \ here we are
    we are here
some \inline{tag with \{ curve bracket inside} okay
some \inline[square bracket \[ inside] okay
"""
        parser = QqParser(allowed_tags={'sometag', 'inline'})
        tree = parser.parse(doc)
        self.assertEqual(tree.as_list(), [
            "_root", "Hello",
            ["sometag", "test"],
            "\\sometag test",
            ["sometag", " here we are\nwe are here"],
            "some ",
            ["inline", "tag with { curve bracket inside"],
            " okay\nsome ",
            ["inline",
             ["_item", "square bracket [ inside"]],
            " okay"
        ])
예제 #22
0
    def test_sameline_tags(self):
        self.maxDiff = None
        doc = r"""    Hello!
    \h1 Intro to qqmbr

    \h2 Fresh documentation system

    **qqmbr** is a documentation system intended to be extremely simple and extremely extensible.
    It was written to allow writing rich content that can be compiled into different formats.
    One source, multiple media: HTML, XML, LaTeX, PDF, eBooks, any other. Look below to see it in action.

    \h3 This is nice level-3 header

    Some paragraph text. See also \ref{sec:another} (reference to different header).

    There are LaTeX formulas here:

    \eq
        x^2 + y^2 = z^2

    `\\eq` is a qqtag. It is better than tag, because it is auto-closing (look at the indent, like Python).

    Here is formula with the label:

    \equation \label eq:Fermat
        x^n + y^n = z^n, \quad n>2

    Several formulas with labels:

    \gather
        \item \label eq:2x2
            2\times 2 = 4
        \item \label eq:3x3
            3\times 3 = 9

    We can reference formula \eqref{eq:Fermat} and \eqref{eq:2x2} just like we referenced header before.

    \h3 Another level-3 header \label sec:another

    Here is the header we referenced.

    \h3 More interesting content

    \figure
        \source http://example.com/somefig.png
        \caption Some figure
        \width 500px

    \question
        Do you like qqmbr?
        \quiz
            \choice \correct false
                No.
                \comment You didn't even try!
            \choice \correct true
                Yes, i like it very much!
                \comment And so do I!
"""
        parser = QqParser(
            allowed_tags={'h1', 'h2', 'h3', 'eq', 'equation', 'label',
                          'gather', 'inlne', 'item', 'ref', 'eqref',
                          'source', 'caption', 'width', 'question',
                          'quiz', 'choice',
                          'comment', 'correct', 'figure'})
        tree = parser.parse(doc)
        print(tree.as_list())
        self.assertEqual(tree.as_list(), ['_root',
                                          'Hello!',
                                          ['h1', 'Intro to qqmbr'],
                                          '',
                                          ['h2',
                                           'Fresh documentation system'],
                                          '\n**qqmbr** is a documentation system intended to be extremely simple and extremely extensible.\nIt was written to allow writing rich content that can be compiled into different formats.\nOne source, multiple media: HTML, XML, LaTeX, PDF, eBooks, any other. Look below to see it in action.\n',
                                          ['h3',
                                           'This is nice level-3 header'],
                                          '\nSome paragraph text. See also ',
                                          ['ref', 'sec:another'],
                                          ' (reference to different header).\n\nThere are LaTeX formulas here:\n',
                                          ['eq',
                                           'x^2 + y^2 = z^2'],
                                          '\n`\\eq` is a qqtag. It is better than tag, because it is auto-closing (look at the indent, like Python).\n\nHere is formula with the label:\n',
                                          ['equation',
                                           ['label', 'eq:Fermat'],
                                           'x^n + y^n = z^n, \\quad n>2'],
                                          '\nSeveral formulas with labels:\n',
                                          ['gather',
                                           ['item',
                                            ['label', 'eq:2x2'],
                                            '2\\times 2 = 4'],
                                           ['item',
                                            ['label', 'eq:3x3'],
                                            '3\\times 3 = 9']],
                                          '\nWe can reference formula ',
                                          ['eqref', 'eq:Fermat'],
                                          ' and ',
                                          ['eqref', 'eq:2x2'],
                                          ' just like we referenced header before.\n',
                                          ['h3',
                                           'Another level-3 header ',
                                           ['label',
                                            'sec:another']],
                                          '\nHere is the header we referenced.\n',
                                          ['h3',
                                           'More interesting content'],
                                          '',
                                          ['figure',
                                           ['source',
                                            'http://example.com/somefig.png'],
                                           ['caption',
                                            'Some figure'],
                                           ['width', '500px']],
                                          '',
                                          ['question',
                                           'Do you like qqmbr?',
                                           ['quiz',
                                            ['choice',
                                             ['correct', 'false'],
                                             'No.',
                                             ['comment',
                                              "You didn't even try!"]],
                                            ['choice',
                                             ['correct', 'true'],
                                             'Yes, i like it very much!',
                                             ['comment',
                                              'And so do I!']]]]])
예제 #23
0
 def test_non_allowed_tag_with_bracket(self):
     doc = r"""Hello \inlinetag{some \forbiddentag{here} okay} this"""
     parser = QqParser(allowed_tags={'inlinetag'})
     tree = parser.parse(doc)
     self.assertEqual(tree.as_list(), ["_root", "Hello ", ["inlinetag", "some \\forbiddentag{here} okay"], " this"])