Pygments code in preview

This commit is contained in:
Grégory Soutadé 2013-01-31 19:24:29 +01:00
parent e0da2df75f
commit 6e997862e7
2 changed files with 25 additions and 18 deletions

View File

@ -117,6 +117,28 @@ class Index(DynastieGenerator):
root.replaceChild(node, date_elem)
def pygmentCode(self, code):
while True:
start = code.find('<dyn:code')
if start == -1: break
end = code.find('</dyn:code>')
if end < start:
self.addError('Invalid <dyn:code> tags in ' + filename)
break
try:
dom = parseString(code[start:end+11])
except xml.dom.DOMException as e:
self.addError('Error parsing ' + filename)
break
res = self.createCode(dom, dom.firstChild)
code = code.replace(code[start:end+11], res)
return code
def createPost(self, posts, dom, post_elem, root):
post = self.cur_post_obj
@ -148,24 +170,7 @@ class Index(DynastieGenerator):
else:
post_content = self.hash_posts_content[filename]
while True:
start = post_content.find('<dyn:code')
if start == -1: break
end = post_content.find('</dyn:code>')
if end < start:
self.addError('Invalid <dyn:code> tags in ' + filename)
break
try:
dom2 = parseString(post_content[start:end+11])
except xml.dom.DOMException as e:
self.addError('Error parsing ' + filename)
break
res = self.createCode(dom2, dom2.firstChild)
post_content = post_content.replace(post_content[start:end+11], res)
post_content = self.pygmentCode(post_content)
self.simpleTransform(values, dom, post_elem, root)

View File

@ -204,6 +204,8 @@ class Post(Index):
v['date'] = now.strftime("%A, %d %B %Y %H:%m")
v['post_content'] = ''
values['content'] = self.pygmentCode(values['content'])
self.simpleTransform(v, dom, root, node)
content_nodes = root.getElementsByTagName("div")