Beispiel #1
0
    def replace(self, match):
        """
        Substitution function for the re.sub function.
        """
        filename, _ = self.getFilename(match.group(1))
        if not filename:
            msg = "Failed to located filename in following command in file {}.\n    {}"
            el = self.createErrorElement(msg.format(self.markdown.current.filename, match.group(0)),
                                         title="Unknown Markdown File")
            return etree.tostring(el)

        settings = self.getSettings(match.group(2))
        if settings['start'] or settings['end']:
            content = ListingPattern.extractLineRange(filename, settings['start'],
                                                      settings['end'], settings['include-end'])
        else:
            with open(filename, 'r') as fid:
                content = fid.read()

        if settings['re']:
            match = re.search(settings['re'], content, flags=re.MULTILINE|re.DOTALL)
            if not match:
                msg = "Failed to located regex in following command.\n{}"
                el = self.createErrorElement(msg.format(settings['re']), title="Failed Regex")
                return etree.tostring(el)
            if 'markdown' in match.groupdict():
                content = match.group('markdown')
            else:
                content = match.group(0)

        self._found = True
        return content
Beispiel #2
0
    def replace(self, match):
        """
        Substitution function for the re.sub function.
        """
        filename, _ = self.getFilename(match.group(1))
        if not filename:
            msg = "Failed to located filename in following command in file {}.\n    {}"
            el = self.createErrorElement(msg.format(
                self.markdown.current.filename, match.group(0)),
                                         title="Unknown Markdown File")
            return etree.tostring(el)

        settings = self.getSettings(match.group(2))
        if settings['start'] or settings['end']:
            content = ListingPattern.extractLineRange(filename,
                                                      settings['start'],
                                                      settings['end'],
                                                      settings['include-end'])
        else:
            with open(filename, 'r') as fid:
                content = fid.read()

        if settings['re']:
            match = re.search(settings['re'],
                              content,
                              flags=re.MULTILINE | re.DOTALL)
            if not match:
                msg = "Failed to located regex in following command.\n{}"
                el = self.createErrorElement(msg.format(settings['re']),
                                             title="Failed Regex")
                return etree.tostring(el)
            content = match.group(0)

        self._found = True
        return content
Beispiel #3
0
 def defaultSettings():
     """Settigns for MarkdownPreprocessor"""
     settings = MooseMarkdownCommon.defaultSettings()
     l_settings = ListingPattern.defaultSettings()
     settings['re'] = (None, "Python regular expression to use for removing text, with flags " \
                             "set to MULTILINE|DOTALL.")
     settings['start'] = l_settings['start']
     settings['end'] = l_settings['end']
     settings['include-end'] = l_settings['include-end']
     return settings
Beispiel #4
0
 def defaultSettings():
     """Settigns for MarkdownPreprocessor"""
     settings = MooseMarkdownCommon.defaultSettings()
     l_settings = ListingPattern.defaultSettings()
     settings['re'] = (None, "Python regular expression to use for removing text, with flags " \
                             "set to MULTILINE|DOTALL.")
     settings['start'] = l_settings['start']
     settings['end'] = l_settings['end']
     settings['include-end'] = l_settings['include-end']
     return settings