Example #1
0
    def filesInStr(self, mid, string, includeRemote=False):
        """The list of media's path in the string.
        
        Each clozes are expanded in every possible ways. It allows
        for different strings to be created.

        Concerning the part of the string related to LaTeX, media are
        generated as explained in latex._imgLink's docstring

        Keyword arguments:
        mid -- the id of the model of the note whose string is considered
        string -- A string, which corresponds to a field of a note
        includeRemote -- whether the list should include contents which is with http, https or ftp
        """
        l = []
        model = self.col.models.get(mid)
        strings = []
        if model['type'] == MODEL_CLOZE and "{{c" in string:
            # if the field has clozes in it, we'll need to expand the
            # possibilities so we can render latex
            strings = self._expandClozes(string)
        else:
            strings = [string]
        for string in strings:
            # handle latex
            string = mungeQA(string, None, None, model, None, self.col)
            # extract filenames
            for reg in self.regexps:
                for match in re.finditer(reg, string):
                    fname = match.group("fname")
                    isLocal = not re.match("(https?|ftp)://", fname.lower())
                    if isLocal or includeRemote:
                        l.append(fname)
        return l
Example #2
0
 def filesInStr(self, mid, string, includeRemote=False):
     l = []
     # convert latex first
     model = self.col.models.get(mid)
     string = mungeQA(string, None, None, model, None, self.col)
     # extract filenames
     for reg in self.regexps:
         for (full, fname) in re.findall(reg, string):
             isLocal = not re.match("(https?|ftp)://", fname.lower())
             if isLocal or includeRemote:
                 l.append(fname)
     return l
Example #3
0
 def filesInStr(self, mid, string, includeRemote=False):
     l = []
     # convert latex first
     model = self.col.models.get(mid)
     string = mungeQA(string, None, None, model, None, self.col)
     # extract filenames
     for reg in self.regexps:
         for (full, fname) in re.findall(reg, string):
             isLocal = not re.match("(https?|ftp)://", fname.lower())
             if isLocal or includeRemote:
                 l.append(fname)
     return l
Example #4
0
 def filesInStr(self, mid, string, includeRemote=False):
     l = []
     model = self.col.models.get(mid)
     strings = []
     if model['type'] == MODEL_CLOZE and "{{c" in string:
         # if the field has clozes in it, we'll need to expand the
         # possibilities so we can render latex
         strings = self._expandClozes(string)
     else:
         strings = [string]
     for string in strings:
         # handle latex
         string = mungeQA(string, None, None, model, None, self.col)
         # extract filenames
         for reg in self.regexps:
             for (full, fname) in re.findall(reg, string):
                 isLocal = not re.match("(https?|ftp)://", fname.lower())
                 if isLocal or includeRemote:
                     l.append(fname)
     return l
Example #5
0
 def filesInStr(self,
                mid: Union[int, str],
                string: str,
                includeRemote: bool = False) -> List[str]:
     l = []
     model = self.col.models.get(mid)
     strings: List[str] = []
     if model["type"] == MODEL_CLOZE and "{{c" in string:
         # if the field has clozes in it, we'll need to expand the
         # possibilities so we can render latex
         strings = self._expandClozes(string)
     else:
         strings = [string]
     for string in strings:
         # handle latex
         string = mungeQA(string, None, None, model, None, self.col)
         # extract filenames
         for reg in self.regexps:
             for match in re.finditer(reg, string):
                 fname = match.group("fname")
                 isLocal = not re.match("(https?|ftp)://", fname.lower())
                 if isLocal or includeRemote:
                     l.append(fname)
     return l