Esempio n. 1
0
    def extendMarkdown(self, md):
        """Create a dict of inline replace patterns and add to the tree processor."""

        configs = self.getConfigs()
        self.patterns = Registry()

        for k, v in REPL.items():
            if configs[k]:
                self.add_pattern(v, md)

        inline_processor = treeprocessors.InlineProcessor(md)
        inline_processor.inlinePatterns = self.patterns
        md.treeprocessors.register(inline_processor, "smart-symbols", 2.1)
Esempio n. 2
0
    def extendMarkdown(self, md, md_globals):
        """Create a dict of inline replace patterns and add to the tree processor."""

        configs = self.getConfigs()
        self.patterns = OrderedDict()

        for k, v in REPL.items():
            if configs[k]:
                self.add_pattern(v, md)

        inline_processor = treeprocessors.InlineProcessor(md)
        inline_processor.inlinePatterns = self.patterns
        md.treeprocessors.add('smart-symbols', inline_processor, '_end')
        if "smarty" in md.treeprocessors.keys():
            md.treeprocessors.link('smarty', '_end')
    def extendMarkdown(self, md):
        """Create replace patterns and add to the tree processor."""

        configs = self.getConfigs()
        self.patterns = Registry()

        # User configured patterns
        if configs['substitutions']:  # if not empty
            self.addSubstitutions(
                'smart-user', normalizeSubstitutions(configs['substitutions']),
                100, md)

        # Pre-defined patterns
        for name in [
                'symbols', 'dice', 'arrows', 'numbers', 'fractions', 'math',
                'roman', 'greek'
        ]:
            if configs[name]:
                self.addSubstitutions('smart-' + name, *getSubstitutions(name),
                                      md)
        # NOTE regex too complex to use direct replacement mechanism
        if configs['ordinal_numbers']:
            self.addPattern(*REPL_ORDINALS, md)

        # Named XHTML 1.0 Latin-1 entities (incl ASCII)
        if configs['html_entities']:
            self.addSubstitutions('smart-html',
                                  *getSubstitutions('html_entities'), md)
        # Named HTML5 Unicode entities (excl. ASCII)
        if configs['html5_entities']:
            self.addSubstitutions('smart-html5',
                                  *getSubstitutions('html5_entities'), md)
        # Numbered HTML entities (excl. ASCII)
        if configs['html_unicode']:
            self.addPattern(*REPL_NASCII, md)

        # NOTE InlineProcessor (TreeProcesser) does *not* process HTML tags: <tag prop="val" />
        inlineProcessor = treeprocessors.InlineProcessor(md)
        inlineProcessor.inlinePatterns = self.patterns
        md.treeprocessors.register(inlineProcessor, "smart-user-symbols", 2.1)