예제 #1
0
 def _format_fragment(self, text, fragment, seen):
     htmlclass = " ".join((self.classname, self.termclass))
     
     output = []
     index = fragment.startchar
     
     for t in fragment.matches:
         if t.startchar > index:
             output.append(text[index:t.startchar])
         
         ttxt = htmlescape(text[t.startchar:t.endchar])
         if t.matched:
             if t.text in seen:
                 termnum = seen[t.text]
             else:
                 termnum = len(seen) % self.maxclasses
                 seen[t.text] = termnum
             ttxt = self.template % {"tag": self.tagname,
                                     "q": self.attrquote,
                                     "cls": htmlclass,
                                     "t": ttxt, "tn": termnum}
         output.append(ttxt)
         index = t.endchar
     
     if index < fragment.endchar:
         output.append(text[index:fragment.endchar])
     
     return "".join(output)
예제 #2
0
    def _format_fragment(self, text, fragment, seen):
        htmlclass = " ".join((self.classname, self.termclass))

        output = []
        index = fragment.startchar

        for t in fragment.matches:
            if t.startchar > index:
                output.append(text[index:t.startchar])

            ttxt = htmlescape(text[t.startchar:t.endchar])
            if t.matched:
                if t.text in seen:
                    termnum = seen[t.text]
                else:
                    termnum = len(seen) % self.maxclasses
                    seen[t.text] = termnum
                ttxt = self.template % {
                    "tag": self.tagname,
                    "q": self.attrquote,
                    "cls": htmlclass,
                    "t": ttxt,
                    "tn": termnum
                }
            output.append(ttxt)
            index = t.endchar

        if index < fragment.endchar:
            output.append(text[index:fragment.endchar])

        return "".join(output)
예제 #3
0
    def _format_fragment(self, text, fragment):
        output = []
        index = fragment.startchar
        
        for t in fragment.matches:
            if t.startchar > index:
                output.append(htmlescape(text[index:t.startchar]))

            ttxt = htmlescape(text[t.startchar:t.endchar])
            if t.matched:
                ttxt = "<b>%s</b>" % ttxt
                if self.firstPos == -1:
                    self.firstPos = t.startchar
                else:
                    self.firstPos = min(self.firstPos, t.startchar)

            output.append(ttxt)
            index = t.endchar
        
        output.append(htmlescape(text[index:fragment.endchar]))
        return u"".join(output)
예제 #4
0
    def _format_fragment(self, text, fragment):
        output = []
        index = fragment.startchar

        for t in fragment.matches:
            if t.startchar > index:
                output.append(htmlescape(text[index:t.startchar]))

            ttxt = htmlescape(text[t.startchar:t.endchar])
            if t.matched:
                ttxt = "<b>%s</b>" % ttxt
                if self.firstPos == -1:
                    self.firstPos = t.startchar
                else:
                    self.firstPos = min(self.firstPos, t.startchar)

            output.append(ttxt)
            index = t.endchar

        output.append(htmlescape(text[index:fragment.endchar]))
        return u"".join(output)