Code Duplication    Length = 49-50 lines in 2 locations

pythonx/mistune.py 1 location

@@ 451-500 (lines=50) @@
448
        self.tokens.append({'type': 'text', 'text': text})
449
450
451
class InlineGrammar(object):
452
    """Grammars for inline level tokens."""
453
454
    escape = re.compile(r'^\\([\\`*{}\[\]()#+\-.!_>~|])')  # \* \+ \! ....
455
    inline_html = re.compile(
456
        r'^(?:%s|%s|%s)' % (
457
            r'<!--[\s\S]*?-->',
458
            r'<(\w+%s)((?:%s)*?)\s*>([\s\S]*?)<\/\1>' % (
459
                _valid_end, _valid_attr),
460
            r'<\w+%s(?:%s)*?\s*\/?>' % (_valid_end, _valid_attr),
461
        )
462
    )
463
    autolink = re.compile(r'^<([^ >]+(@|:)[^ >]+)>')
464
    link = re.compile(
465
        r'^!?\[('
466
        r'(?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*'
467
        r')\]\('
468
        r'''\s*(<)?([\s\S]*?)(?(2)>)(?:\s+['"]([\s\S]*?)['"])?\s*'''
469
        r'\)'
470
    )
471
    reflink = re.compile(
472
        r'^!?\[('
473
        r'(?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*'
474
        r')\]\s*\[([^^\]]*)\]'
475
    )
476
    nolink = re.compile(r'^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]')
477
    url = re.compile(r'''^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])''')
478
    double_emphasis = re.compile(
479
        r'^_{2}([\s\S]+?)_{2}(?!_)'  # __word__
480
        r'|'
481
        r'^\*{2}([\s\S]+?)\*{2}(?!\*)'  # **word**
482
    )
483
    emphasis = re.compile(
484
        r'^\b_((?:__|[^_])+?)_\b'  # _word_
485
        r'|'
486
        r'^\*((?:\*\*|[^\*])+?)\*(?!\*)'  # *word*
487
    )
488
    code = re.compile(r'^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)')  # `code`
489
    linebreak = re.compile(r'^ {2,}\n(?!\s*$)')
490
    strikethrough = re.compile(r'^~~(?=\S)([\s\S]*?\S)~~')  # ~~word~~
491
    footnote = re.compile(r'^\[\^([^\]]+)\]')
492
    text = re.compile(r'^[\s\S]+?(?=[\\<!\[_*`~]|https?://| {2,}\n|$)')
493
494
    def hard_wrap(self):
495
        """Grammar for hard wrap linebreak. You don't need to add two
496
        spaces at the end of a line.
497
        """
498
        self.linebreak = re.compile(r'^ *\n(?!\s*$)')
499
        self.text = re.compile(
500
            r'^[\s\S]+?(?=[\\<!\[_*`~]|https?://| *\n|$)'
501
        )
502
503

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