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.
32 lines
959 B
32 lines
959 B
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)
|
|
img_el = markdown.util.etree.Element('img')
|
|
li.append(img_el)
|
|
img_el.attrib["src"]=img
|
|
img_el.attrib["alt"]=alt
|
|
img_el.attrib["class"]='galleryimage'
|
|
|
|
return ul
|
|
|
|
class GalleryExtension(markdown.Extension):
|
|
def extendMarkdown(self, md, md_globals):
|
|
md.inlinePatterns.add('gallery', GalleryPattern(md), '<image_link')
|
|
|
|
|