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.
36 lines
1.1 KiB
36 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()
|
|
|
|
ul = markdown.util.etree.Element('ul')
|
|
ul.attrib["class"]='gallery'
|
|
for img in imgs:
|
|
li = markdown.util.etree.Element('li')
|
|
ul.append(li)
|
|
anch = markdown.util.etree.Element('a')
|
|
anch.attrib["href"]=img
|
|
anch.attrib["target"]="_blank"
|
|
anch.attrib["onclick"]='loadImg("%s");return false;' % (img)
|
|
li.append(anch)
|
|
|
|
img_el = markdown.util.etree.Element('img')
|
|
anch.append(img_el)
|
|
img_el.attrib["src"]=img
|
|
img_el.attrib["alt"]=alt
|
|
|
|
return ul
|
|
|
|
class GalleryExtension(markdown.Extension):
|
|
def extendMarkdown(self, md, md_globals):
|
|
md.inlinePatterns.add('gallery', GalleryPattern(md), '<image_link')
|
|
|
|
|