Code Duplication    Length = 49-49 lines in 2 locations

pythonx/markdown_parser.py 1 location

@@ 430-478 (lines=49) @@
427
                'tag': tag,
428
                'extra': attr,
429
                'text': text
430
            })
431
432
    def parse_paragraph(self, m):
433
        text = m.group(1).rstrip('\n')
434
        self.tokens.append({'type': 'paragraph', 'text': text})
435
436
    def parse_text(self, m):
437
        text = m.group(0)
438
        self.tokens.append({'type': 'text', 'text': text})
439
440
441
class InlineGrammar(object):
442
    """Grammars for inline level tokens."""
443
444
    escape = re.compile(r'^\\([\\`*{}\[\]()#+\-.!_>~|])')  # \* \+ \! ....
445
    inline_html = re.compile(
446
        r'^(?:%s|%s|%s)' % (
447
            r'<!--[\s\S]*?-->',
448
            r'<(\w+%s)((?:%s)*?)\s*>([\s\S]*?)<\/\1>' % (_valid_end, _valid_attr),
449
            r'<\w+%s(?:%s)*?\s*\/?>' % (_valid_end, _valid_attr),
450
        )
451
    )
452
    autolink = re.compile(r'^<([^ >]+(@|:)[^ >]+)>')
453
    link = re.compile(
454
        r'^!?\[('
455
        r'(?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*'
456
        r')\]\('
457
        r'''\s*(<)?([\s\S]*?)(?(2)>)(?:\s+['"]([\s\S]*?)['"])?\s*'''
458
        r'\)'
459
    )
460
    reflink = re.compile(
461
        r'^!?\[('
462
        r'(?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*'
463
        r')\]\s*\[([^^\]]*)\]'
464
    )
465
    nolink = re.compile(r'^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]')
466
    url = re.compile(r'''^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])''')
467
    double_emphasis = re.compile(
468
        r'^_{2}([\s\S]+?)_{2}(?!_)'  # __word__
469
        r'|'
470
        r'^\*{2}([\s\S]+?)\*{2}(?!\*)'  # **word**
471
    )
472
    emphasis = re.compile(
473
        r'^\b_((?:__|[^_])+?)_\b'  # _word_
474
        r'|'
475
        r'^\*((?:\*\*|[^\*])+?)\*(?!\*)'  # *word*
476
    )
477
    code = re.compile(r'^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)')  # `code`
478
    linebreak = re.compile(r'^ {2,}\n(?!\s*$)')
479
    strikethrough = re.compile(r'^~~(?=\S)([\s\S]*?\S)~~')  # ~~word~~
480
    footnote = re.compile(r'^\[\^([^\]]+)\]')
481
    text = re.compile(r'^[\s\S]+?(?=[\\<!\[_*`~]|https?://| {2,}\n|$)')

pythonx/tests/markdown_parser.py 1 location

@@ 430-478 (lines=49) @@
427
        self.tokens.append({'type': 'text', 'text': text})
428
429
430
class InlineGrammar(object):
431
    """Grammars for inline level tokens."""
432
433
    escape = re.compile(r'^\\([\\`*{}\[\]()#+\-.!_>~|])')  # \* \+ \! ....
434
    inline_html = re.compile(
435
        r'^(?:%s|%s|%s)' % (
436
            r'<!--[\s\S]*?-->',
437
            r'<(\w+%s)((?:%s)*?)>([\s\S]*?)<\/\1>' % (_valid_end, _valid_attr),
438
            r'<\w+%s(?:%s)*?>' % (_valid_end, _valid_attr),
439
        )
440
    )
441
    autolink = re.compile(r'^<([^ >]+(@|:)[^ >]+)>')
442
    link = re.compile(
443
        r'^!?\[('
444
        r'(?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*'
445
        r')\]\('
446
        r'''\s*(<)?([\s\S]*?)(?(2)>)(?:\s+['"]([\s\S]*?)['"])?\s*'''
447
        r'\)'
448
    )
449
    reflink = re.compile(
450
        r'^!?\[('
451
        r'(?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*'
452
        r')\]\s*\[([^^\]]*)\]'
453
    )
454
    nolink = re.compile(r'^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]')
455
    url = re.compile(r'''^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])''')
456
    double_emphasis = re.compile(
457
        r'^_{2}([\s\S]+?)_{2}(?!_)'  # __word__
458
        r'|'
459
        r'^\*{2}([\s\S]+?)\*{2}(?!\*)'  # **word**
460
    )
461
    emphasis = re.compile(
462
        r'^\b_((?:__|[\s\S])+?)_\b'  # _word_
463
        r'|'
464
        r'^\*((?:\*\*|[\s\S])+?)\*(?!\*)'  # *word*
465
    )
466
    code = re.compile(r'^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)')  # `code`
467
    linebreak = re.compile(r'^ {2,}\n(?!\s*$)')
468
    strikethrough = re.compile(r'^~~(?=\S)([\s\S]+?\S)~~')  # ~~word~~
469
    footnote = re.compile(r'^\[\^([^\]]+)\]')
470
    text = re.compile(r'^[\s\S]+?(?=[\\<!\[_*`~]|https?://| {2,}\n|$)')
471
472
    def hard_wrap(self):
473
        """Grammar for hard wrap linebreak. You don't need to add two
474
        spaces at the end of a line.
475
        """
476
        self.linebreak = re.compile(r'^ *\n(?!\s*$)')
477
        self.text = re.compile(
478
            r'^[\s\S]+?(?=[\\<!\[_*`~]|https?://| *\n|$)'
479
        )
480
481