You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
def makeExtension(configs=None) :
|
|
return GalleryExtension()
|
|
|
|
from markdown.inlinepatterns import Pattern
|
|
import markdown, urllib
|
|
|
|
class GalleryPattern(Pattern):
|
|
def __init__(self,md):
|
|
Pattern.__init__(self,'!\\[(.*?)\\]\(\((.*?)\)\)',md) # )
|
|
def handleMatch(self, m):
|
|
|
|
alt=m.group(2)
|
|
imgs=m.group(3).split()
|
|
|
|
span = markdown.util.etree.Element('span')
|
|
span.attrib["class"]='gallery'
|
|
for img in imgs:
|
|
anch = markdown.util.etree.Element('a')
|
|
anch.attrib["href"]=img
|
|
anch.attrib["target"]="_blank"
|
|
anch.attrib["class"]="gallery_link"
|
|
anch.attrib["onclick"]='loadImg("%s",this);return false;' % (img)
|
|
span.append(anch)
|
|
|
|
img_el = markdown.util.etree.Element('img')
|
|
img_el.attrib["src"]=img
|
|
img_el.attrib["alt"]=alt
|
|
anch.append(img_el)
|
|
|
|
return span
|
|
|
|
class GalleryExtension(markdown.Extension):
|
|
def extendMarkdown(self, md, md_globals):
|
|
md.inlinePatterns.add('gallery', GalleryPattern(md), '<image_link')
|
|
|
|
|