added markdown extension for galleries, still needs JS and css

master
Stefan Krulj 14 years ago
parent 1edd6cee16
commit d900c4dfcf
  1. 32
      mdx_gallery.py
  2. 4
      pylog_action_impl.py

@ -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')

@ -39,7 +39,7 @@ def disp_txt(path):
print '<div class="entrytext">'
f = codecs.open(path, mode="r", encoding=cfg.encoding)
txt=f.read()
print markdown.markdown(txt,extensions=['math']).encode(cfg.encoding)
print markdown.markdown(txt,extensions=['gallery','math']).encode(cfg.encoding)
f.close()
print '</div>'
@ -161,7 +161,7 @@ def prev(path):
def prev_txt(path):
fi = codecs.open(path, mode="r", encoding=cfg.encoding)
txt=get_n_words(fi,40)
print '<div class="preview">'+markdown.markdown(txt[0],extensions=['math']).encode(cfg.encoding)
print '<div class="preview">'+markdown.markdown(txt[0],extensions=['gallery','math']).encode(cfg.encoding)
if txt[1]:
print '<i>&nbsp;...</i>'
print '</div>'

Loading…
Cancel
Save