bugdown: Factor out creating a link into its own method

(imported from commit 869cec9927570c4126b78f90aeedc2d5b542d097)
This commit is contained in:
Luke Faraone 2013-04-29 13:17:17 -07:00 committed by Tim Abbott
parent 598c3a00f2
commit 8601c1670f
1 changed files with 12 additions and 8 deletions

View File

@ -52,6 +52,17 @@ def walk_tree(root, processor, stop_after_first=False):
return results
def add_a(root, url, link, height=None):
div = markdown.util.etree.SubElement(root, "div")
div.set("class", "message_inline_image");
a = markdown.util.etree.SubElement(div, "a")
a.set("href", link)
a.set("target", "_blank")
a.set("title", link)
img = markdown.util.etree.SubElement(a, "img")
img.set("src", url)
class InlineImagePreviewProcessor(markdown.treeprocessors.Treeprocessor):
def is_image(self, url):
parsed_url = urlparse.urlparse(url)
@ -100,14 +111,7 @@ class InlineImagePreviewProcessor(markdown.treeprocessors.Treeprocessor):
def run(self, root):
image_urls = self.find_images(root)
for (url, link) in image_urls:
div = markdown.util.etree.SubElement(root, "div")
div.set("class", "message_inline_image");
a = markdown.util.etree.SubElement(div, "a")
a.set("href", link)
a.set("target", "_blank")
a.set("title", link)
img = markdown.util.etree.SubElement(a, "img")
img.set("src", url)
add_a(root, url, link)
return root