Ejemplo n.º 1
0
    def extendMarkdown(self, md, md_globals):
        """Insert <ins>test</ins> tags as ^^test^^ and/or <sup>test</sup> tags as ^test^."""

        config = self.getConfigs()
        insert = bool(config.get('insert', True))
        superscript = bool(config.get('superscript', True))
        smart = bool(config.get('smart_insert', True))

        escape_chars = []
        if insert or superscript:
            escape_chars.append('^')
        if superscript:
            escape_chars.append(' ')
        util.escape_chars(md, escape_chars)

        ins_rule = RE_SMART_INS if smart else RE_INS
        sup_ins_rule = RE_SUP_INS
        sup_ins2_rule = RE_SMART_SUP_INS2 if smart else RE_SUP_INS2
        sup_rule = RE_SUP

        if insert:
            md.inlinePatterns.add("ins", SimpleTagPattern(ins_rule, "ins"), "<not_strong")
            md.inlinePatterns.add('not_caret', SimpleTextPattern(RE_NOT_CARET), "<ins")
            if superscript:
                md.inlinePatterns.add("sup_ins", DoubleTagPattern(sup_ins_rule, "sup,ins"), "<ins")
                md.inlinePatterns.add("sup_ins2", DoubleTagPattern(sup_ins2_rule, "sup,ins"), "<ins")
                md.inlinePatterns.add("sup", SimpleTagPattern(sup_rule, "sup"), ">ins" if smart else "<ins")
        elif superscript:
            md.inlinePatterns.add("sup", SimpleTagPattern(sup_rule, "sup"), "<not_strong")
            md.inlinePatterns.add('not_caret', SimpleTextPattern(RE_NOT_CARET), "<sup")
Ejemplo n.º 2
0
    def extendMarkdown(self, md, md_globals):
        md.registerExtension(self)

        # Add inline pseudo form pattern. Replace all inlinePatterns that
        # include an underscore with patterns that do not include underscores.
        md.inlinePatterns['em_strong'] = DoubleTagPattern(
            EM_STRONG_RE, 'strong,em')
        md.inlinePatterns['strong_em'] = DoubleTagPattern(
            STRONG_EM_RE, 'em,strong')
        md.inlinePatterns['strong'] = SimpleTagPattern(STRONG_RE, 'strong')
        md.inlinePatterns['pseudo-form'] = PseudoFormPattern(PSEUDO_FORM_RE)
        md.inlinePatterns['section-symbol'] = SectionSymbolPattern(
            SECTION_SYMBOL_RE)
        del md.inlinePatterns['emphasis2']

        # Add block reference processor for `see(label)` syntax
        md.parser.blockprocessors.add(
            'blockreference',
            BlockReferenceProcessor(
                md.parser,
                url_resolver=self.getConfig('url_resolver'),
                contents_resolver=self.getConfig('contents_resolver'),
                render_block_reference=self.getConfig(
                    'render_block_reference'),
            ), '<paragraph')

        # Replace the default paragraph processor with one that handles
        # `{label}` syntax and gives default hash-based ids to paragraphs
        md.parser.blockprocessors['paragraph'] = \
            LabeledParagraphProcessor(md.parser)

        # Delete the ordered list processor
        del md.parser.blockprocessors['olist']
Ejemplo n.º 3
0
    def extendMarkdown(self, md, md_globals):
        """Insert `<del>test</del>` tags as `~~test~~` and `<sub>test</sub>` tags as `~test~`."""

        config = self.getConfigs()
        delete = bool(config.get('delete', True))
        subscript = bool(config.get('subscript', True))
        smart = bool(config.get('smart_delete', True))

        escape_chars = []
        if delete or subscript:
            escape_chars.append('~')
        if subscript:
            escape_chars.append(' ')
        util.escape_chars(md, escape_chars)

        delete_rule = RE_SMART_DEL if smart else RE_DEL
        sub_del_rule = RE_SMART_SUB_DEL if smart else RE_SUB_DEL
        sub_del2_rule = RE_SMART_SUB_DEL2 if smart else RE_SUB_DEL2
        sub_rule = RE_SUB

        if delete:
            md.inlinePatterns.add("del", SimpleTagPattern(delete_rule, "del"), "<not_strong")
            md.inlinePatterns.add('not_tilde', SimpleTextPattern(RE_NOT_TILDE), "<del")
            if subscript:
                md.inlinePatterns.add("sub_del", DoubleTagPattern(sub_del_rule, "sub,del"), "<del")
                md.inlinePatterns.add("sub_del2", DoubleTagPattern(sub_del2_rule, "sub,del"), "<del")
                md.inlinePatterns.add("sub", SimpleTagPattern(sub_rule, "sub"), ">del" if smart else "<del")
        elif subscript:
            md.inlinePatterns.add("sub", SimpleTagPattern(sub_rule, "sub"), "<not_strong")
            md.inlinePatterns.add('not_tilde', SimpleTextPattern(RE_NOT_TILDE), "<sub")
Ejemplo n.º 4
0
    def extendMarkdown(self, md, md_globals):
        """Insert <ins>test</ins> tags as ^^test^^ and/or <sup>test</sup> tags as ^test^."""

        config = self.getConfigs()
        insert = bool(config.get('insert', True))
        superscript = bool(config.get('superscript', True))
        smart = bool(config.get('smart_insert', True))

        if "^" not in md.ESCAPED_CHARS and (insert or superscript):
            md.ESCAPED_CHARS.append('^')
        if " " not in md.ESCAPED_CHARS and superscript:
            md.ESCAPED_CHARS.append(' ')

        ins_rule = RE_SMART_INS if smart else RE_INS
        sup_ins_rule = RE_SUP_INS
        sup_ins2_rule = RE_SMART_SUP_INS2 if smart else RE_SUP_INS2
        sup_rule = RE_SUP

        if insert:
            md.inlinePatterns.add("ins", SimpleTagPattern(ins_rule, "ins"),
                                  "<not_strong")
            if superscript:
                md.inlinePatterns.add(
                    "sup_ins", DoubleTagPattern(sup_ins_rule, "sup,ins"),
                    "<ins")
                md.inlinePatterns.add(
                    "sup_ins2", DoubleTagPattern(sup_ins2_rule, "sup,ins"),
                    "<ins")
                md.inlinePatterns.add("sup", SimpleTagPattern(sup_rule, "sup"),
                                      ">ins" if smart else "<ins")
        elif superscript:
            md.inlinePatterns.add("sup", SimpleTagPattern(sup_rule, "sup"),
                                  "<not_strong")
Ejemplo n.º 5
0
    def extendMarkdown(self, md, md_globals):
        """Insert <del>test</del> tags as ~~test~~ and <sub>test</sub> tags as ~test~."""

        config = self.getConfigs()
        delete = bool(config.get('delete', True))
        subscript = bool(config.get('subscript', True))
        smart = bool(config.get('smart_delete', True))

        if "~" not in md.ESCAPED_CHARS and (delete or subscript):
            md.ESCAPED_CHARS.append('~')
        if " " not in md.ESCAPED_CHARS and subscript:
            md.ESCAPED_CHARS.append(' ')

        delete_rule = RE_SMART_DEL if smart else RE_DEL
        sub_del_rule = RE_SMART_SUB_DEL if smart else RE_SUB_DEL
        sub_del2_rule = RE_SMART_SUB_DEL2 if smart else RE_SUB_DEL2
        sub_rule = RE_SUB

        if delete:
            md.inlinePatterns.add("del", SimpleTagPattern(delete_rule, "del"), "<not_strong")
            if subscript:
                md.inlinePatterns.add("sub_del", DoubleTagPattern(sub_del_rule, "sub,del"), "<del")
                md.inlinePatterns.add("sub_del2", DoubleTagPattern(sub_del2_rule, "sub,del"), "<del")
                md.inlinePatterns.add("sub", SimpleTagPattern(sub_rule, "sub"), ">del" if smart else "<del")
        elif subscript:
            md.inlinePatterns.add("sub", SimpleTagPattern(sub_rule, "sub"), "<not_strong")
Ejemplo n.º 6
0
    def make_better(self, md):
        """
        Configure all the pattern rules.

        This should be used instead of smart_strong package.
        pymdownx.extra should be used in place of markdown.extensions.extra.
        """

        config = self.getConfigs()
        enabled = config["smart_enable"]
        if enabled:
            enable_all = enabled == "all"
            enable_under = enabled == "underscore" or enable_all
            enable_star = enabled == "asterisk" or enable_all

        star_strong_em = SMART_STAR_STRONG_EM if enable_star else STAR_STRONG_EM
        under_strong_em = SMART_UNDER_STRONG_EM if enable_under else UNDER_STRONG_EM
        star_em_strong = SMART_STAR_EM_STRONG if enable_star else STAR_EM_STRONG
        under_em_strong = SMART_UNDER_EM_STRONG if enable_under else UNDER_EM_STRONG
        star_strong_em2 = SMART_STAR_STRONG_EM2 if enable_star else STAR_STRONG_EM2
        under_strong_em2 = SMART_UNDER_STRONG_EM2 if enable_under else UNDER_STRONG_EM2
        star_strong = SMART_STAR_STRONG if enable_star else STAR_STRONG
        under_strong = SMART_UNDER_STRONG if enable_under else UNDER_STRONG
        star_emphasis = SMART_STAR_EM if enable_star else STAR_EM
        under_emphasis = SMART_UNDER_EM if enable_under else UNDER_EM

        md.inlinePatterns["strong_em"] = DoubleTagPattern(
            star_strong_em, 'strong,em')
        md.inlinePatterns.add("strong_em2",
                              DoubleTagPattern(under_strong_em, 'strong,em'),
                              '>strong_em')
        if util.MD3:  # pragma: no cover
            value = md.inlinePatterns["em_strong"]
            index = md.inlinePatterns._priority[
                md.inlinePatterns.get_index_for_name("strong_em2")].priority
            md.inlinePatterns.register(value, "em_strong", index + 1)
        else:
            md.inlinePatterns.link("em_strong", ">strong_em2")
        md.inlinePatterns["em_strong"] = DoubleTagPattern(
            star_em_strong, 'em,strong')
        md.inlinePatterns.add('em_strong2',
                              DoubleTagPattern(under_em_strong, 'em,strong'),
                              '>em_strong')
        md.inlinePatterns.add('strong_em3',
                              DoubleTagPattern(star_strong_em2, 'strong,em'),
                              '>em_strong2')
        md.inlinePatterns.add('strong_em4',
                              DoubleTagPattern(under_strong_em2, 'strong,em'),
                              '>strong_em3')
        md.inlinePatterns["strong"] = SimpleTagPattern(star_strong, 'strong')
        md.inlinePatterns.add("strong2",
                              SimpleTagPattern(under_strong, 'strong'),
                              '>strong')
        md.inlinePatterns["emphasis"] = SimpleTagPattern(star_emphasis, 'em')
        md.inlinePatterns["emphasis2"] = SimpleTagPattern(under_emphasis, 'em')