def handle_term(man, word): """Handle a hashed word.""" res = man.doc.resolve_hash(word) if res == None: man.warn("hash term '#%s' is unknown!" % word) res = doc.Word(word) man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, res))
def handle_mailto_link(man, match): url = match.group('email_auto') man.send( doc.ObjectEvent(doc.L_WORD, doc.ID_NEW_LINK, doc.Link("mailto:" + url))) man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(url))) man.send(doc.CloseEvent(doc.L_WORD, doc.ID_END_LINK, "link"))
def new_link(man, match, ltag, utag): target = match.group(utag) label = match.group(ltag) link = doc.Link(target) # peal label if label and label[0] == '(': i = label.find(')') if i >= 0: link.setInfo(doc.INFO_CLASS, label[1:i]) label = label[i + 1:] tooltip = None if label and label[-1] == ')': i = label.rfind('(') if i >= 0: tooltip = label[i + 1:-1] label = label[:i] # build the link # tooltip are ignored now: what to do with this? if not label: label = target man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW_LINK, link)) man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(label))) man.send(doc.CloseEvent(doc.L_WORD, doc.ID_END_LINK, "link"))
def handle_ref(man, match): try: url = man.defs[match.group("id_ref")][0] man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW_LINK, doc.Link(url))) man.send( doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(match.group("text_ref")))) man.send(doc.CloseEvent(doc.L_WORD, doc.ID_END_LINK, "link")) except KeyError: common.warn("reference %s is unknown!" % match.group("id_ref"))
def resolve(self, word): """Lookup for an unresolved word.""" found = [] for p in self.prefixes: try: found.append(self.map[p + word]) except KeyError: pass if found == []: return None if len(found) > 1: self.man.warn("'#%s' is ambiguous!" % word) link = doc.Link(found[0]) link.append(doc.Word(word)) return link
def handleNonParsed(man, match): man.send( doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(match.group('nonparsed')[:-2])))
def handleLink(man, match): target = match.group('target') label = match.group('label') if not label: label = target processLink(man, target, doc.Word(label))
def handleEMail(man, match): processLink(man, "mailto:" + match.group(0), doc.Word(match.group(0)))
def handleURL(man, match): processLink(man, match.group(0), doc.Word(match.group(0)))
def handleDouble(man, match): man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word("#")))
def handle_backtrick(man, match): text = match.group("text_backtrick") word = doc.Word(text) style = doc.Style(doc.STYLE_CODE) style.append(word) man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, style))
def new_squote(man, match): text = match.group("sqtext") t = i18n.getTranslator(man.doc) man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(t.get(i18n.GLYPH_OPEN_SQUOTE)))) tparser.handleText(man, text, '') man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(t.get(i18n.GLYPH_CLOSE_SQUOTE))))
def new_size(man, match): w = match.group('sw') h = match.group('sh') man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(w))) man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Glyph(0x2A09))) man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(h)))
def new_escape(man, match): man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(match.group('esc'))))
def handle_link(man, match): URL = match.group('URL') text = match.group('text') man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW_LINK, doc.Link(URL))) man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(text))) man.send(doc.CloseEvent(doc.L_WORD, doc.ID_END_LINK, "link"))
def handlePercent(man, match): man.send( doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(match.group('percent'))))
def handleMath(man, match): text = match.group("latexmath") if text == "": man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word("$"))) else: man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, LatexMath(text)))
def handle_word(man, word): man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(word)))