diff --git a/generators/index.py b/generators/index.py index df8e1f1..f2eb85b 100644 --- a/generators/index.py +++ b/generators/index.py @@ -117,6 +117,28 @@ class Index(DynastieGenerator): root.replaceChild(node, date_elem) + def pygmentCode(self, code): + while True: + start = code.find('') + + if end < start: + self.addError('Invalid 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('') - - if end < start: - self.addError('Invalid 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) diff --git a/generators/post.py b/generators/post.py index 4ff7f26..03b9ef5 100644 --- a/generators/post.py +++ b/generators/post.py @@ -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")