parent
1edd6cee16
commit
d900c4dfcf
@ -0,0 +1,32 @@ |
||||
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') |
||||
|
||||
Loading…
Reference in new issue