Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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"))
Exemplo n.º 3
0
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"))
Exemplo n.º 4
0
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"))
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
def handleNonParsed(man, match):
    man.send(
        doc.ObjectEvent(doc.L_WORD, doc.ID_NEW,
                        doc.Word(match.group('nonparsed')[:-2])))
Exemplo n.º 7
0
def handleLink(man, match):
    target = match.group('target')
    label = match.group('label')
    if not label:
        label = target
    processLink(man, target, doc.Word(label))
Exemplo n.º 8
0
def handleEMail(man, match):
    processLink(man, "mailto:" + match.group(0), doc.Word(match.group(0)))
Exemplo n.º 9
0
def handleURL(man, match):
    processLink(man, match.group(0), doc.Word(match.group(0)))
Exemplo n.º 10
0
def handleDouble(man, match):
    man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word("#")))
Exemplo n.º 11
0
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))
Exemplo n.º 12
0
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))))
Exemplo n.º 13
0
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)))
Exemplo n.º 14
0
def new_escape(man, match):
	man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(match.group('esc'))))
Exemplo n.º 15
0
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"))
Exemplo n.º 16
0
def handlePercent(man, match):
    man.send(
        doc.ObjectEvent(doc.L_WORD, doc.ID_NEW,
                        doc.Word(match.group('percent'))))
Exemplo n.º 17
0
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)))
Exemplo n.º 18
0
def handle_word(man, word):
    man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(word)))