예제 #1
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"))
예제 #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"))
예제 #3
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"))
예제 #4
0
def new_image(man, match):
	tmatch = match
	image = match.group('image')
	
	# alt pealing
	alt = None
	if image[-1] == ')':
		i = image.rfind('(')
		if i >= 0:
			alt = image[i + 1:-1]
			image = image[:i]
	
	# style pealing
	info = doc.Info()
	image = use_par_style(info, image)
	
	# dimension pealing
	match = WXH_RE.search(image)
	if match:
		info.setInfo(doc.INFO_WIDTH, int(match.group(1)))
		info.setInfo(doc.INFO_HEIGHT, int(match.group(2)))
		image = image[:match.start()]
	else:
		match = WH_RE.search(image)
		if match:
			info.setInfo(doc.INFO_WIDTH, int(match.group(1)))
			info.setInfo(doc.INFO_HEIGHT, int(match.group(2)))
			image = image[:match.start()]
		else:
			match = PERCENT_RE.search(image)
			if match:
				info.setInfo(doc.INFO_PERCENT_SIZE, int(match.group(1)))
				image = image[:match.start()]

	# beginning link if any
	link = tmatch.group('iurl')
	if link:
		man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW_LINK, doc.Link(link)))
	
	# build the image	
	if info.getInfo(doc.INFO_ALIGN):
		node = doc.Image(image, None, None, alt)
	else:
		node = doc.EmbeddedImage(image, None, None, alt)
	node.mergeInfo(info)
	man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, node))
	
	# end link
	if link:
		man.send(doc.CloseEvent(doc.L_WORD, doc.ID_END_LINK, "link"))
예제 #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
예제 #6
0
def processLink(man, target, text):
    man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW_LINK, doc.Link(target)))
    man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, text))
    man.send(doc.CloseEvent(doc.L_WORD, doc.ID_END_LINK, "link"))
예제 #7
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"))