Pygments code in preview
This commit is contained in:
parent
e0da2df75f
commit
6e997862e7
|
@ -117,6 +117,28 @@ class Index(DynastieGenerator):
|
||||||
|
|
||||||
root.replaceChild(node, date_elem)
|
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):
|
def createPost(self, posts, dom, post_elem, root):
|
||||||
post = self.cur_post_obj
|
post = self.cur_post_obj
|
||||||
|
|
||||||
|
@ -148,24 +170,7 @@ class Index(DynastieGenerator):
|
||||||
else:
|
else:
|
||||||
post_content = self.hash_posts_content[filename]
|
post_content = self.hash_posts_content[filename]
|
||||||
|
|
||||||
while True:
|
post_content = self.pygmentCode(post_content)
|
||||||
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)
|
|
||||||
|
|
||||||
self.simpleTransform(values, dom, post_elem, root)
|
self.simpleTransform(values, dom, post_elem, root)
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,8 @@ class Post(Index):
|
||||||
v['date'] = now.strftime("%A, %d %B %Y %H:%m")
|
v['date'] = now.strftime("%A, %d %B %Y %H:%m")
|
||||||
v['post_content'] = ''
|
v['post_content'] = ''
|
||||||
|
|
||||||
|
values['content'] = self.pygmentCode(values['content'])
|
||||||
|
|
||||||
self.simpleTransform(v, dom, root, node)
|
self.simpleTransform(v, dom, root, node)
|
||||||
|
|
||||||
content_nodes = root.getElementsByTagName("div")
|
content_nodes = root.getElementsByTagName("div")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user