mirror of https://github.com/zulip/zulip.git
bugdown: Factor out creating a link into its own method
(imported from commit 869cec9927570c4126b78f90aeedc2d5b542d097)
This commit is contained in:
parent
598c3a00f2
commit
8601c1670f
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue