"""
========================= IMAGE LINKS =================================
Turns paragraphs like
<~~~~~~~~~~~~~~~~~~~~~~~~
dir/subdir
dir/subdir
dir/subdir
~~~~~~~~~~~~~~
dir/subdir
dir/subdir
dir/subdir
~~~~~~~~~~~~~~~~~~~>
Into mini-photo galleries.
"""
import re, markdown
import url_manager
IMAGE_LINK = """"""
SLIDESHOW_LINK = """[slideshow]"""
ALBUM_LINK = """ [%s]"""
class ImageLinksExtension (markdown.Extension):
def __init__ (self) :
self.reset()
def extendMarkdown(self, md, md_globals) :
self.md = md
# Stateless extensions do not need to be registered
md.registerExtension(self)
# Insert a preprocessor before all preprocessors
preprocessor = ImageLinkPreprocessor()
preprocessor.md = md
md.preprocessors.insert(0, preprocessor)
def reset(self) :
# May be called by Markdown is state reset is desired
pass
class ImageLinkPreprocessor (markdown.Preprocessor):
def run(self, lines) :
url = url_manager.BlogEntryUrl(url_manager.BlogUrl("all"),
"2006/08/29/the_rest_of_our")
all_images = []
blocks = []
in_image_block = False
new_lines = []
for line in lines :
if line.startswith("<~~~~~~~") :
albums = []
rows = []
in_image_block = True
if not in_image_block :
new_lines.append(line)
else :
line = line.strip()
if line.endswith("~~~~~~>") or not line :
in_image_block = False
new_block = "