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)
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)
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)