MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / ImageLinkPreprocessor

Class ImageLinkPreprocessor

markdown/extensions/imagelinks.py:37–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35
36
37class ImageLinkPreprocessor(markdown.preprocessors.Preprocessor):
38
39 def run(self, lines):
40
41 url = url_manager.BlogEntryUrl(url_manager.BlogUrl("all"),
42 "2006/08/29/the_rest_of_our")
43
44
45 all_images = []
46 blocks = []
47 in_image_block = False
48
49 new_lines = []
50
51 for line in lines:
52
53 if line.startswith("<~~~~~~~"):
54 albums = []
55 rows = []
56 in_image_block = True
57
58 if not in_image_block:
59
60 new_lines.append(line)
61
62 else:
63
64 line = line.strip()
65
66 if line.endswith("~~~~~~>") or not line:
67 in_image_block = False
68 new_block = "<div><br/><center><span class='image-links'>\n"
69
70 album_url_hash = {}
71
72 for row in rows:
73 for photo_url, title in row:
74 new_block += "&nbsp;"
75 new_block += IMAGE_LINK % (photo_url,
76 photo_url.get_thumbnail(),
77 title)
78
79 album_url_hash[str(photo_url.get_album())] = 1
80
81 new_block += "<br/>"
82
83 new_block += "</span>"
84 new_block += SLIDESHOW_LINK % url.get_slideshow()
85
86 album_urls = list(album_url_hash.keys())
87 album_urls.sort()
88
89 if len(album_urls) == 1:
90 new_block += ALBUM_LINK % (album_urls[0], "complete album")
91 else :
92 for i in range(len(album_urls)) :
93 new_block += ALBUM_LINK % (album_urls[i],
94 "album %d" % (i + 1) )

Callers 1

extendMarkdownMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected