public
Description: A full featured and opinionated blogging solution using Django
Homepage: http://lethain.com/projects/lifeflow/
Clone URL: git://github.com/lethain/lifeflow.git
(Courtesy of Rageev Sebastian.) Fixed rendering of syntax colored code segments 
at non base levels.
lethain (author)
Sat Jul 05 06:54:38 -0700 2008
commit  f16e09d68bd81e7c032de37bbe6515f68aa1f80a
tree    51a178d68e58a393659975c4ae83b1c47bf07680
parent  36f7cc63f3ce03ca0bcdd3f7d5634b41a9f00df7
...
16
17
18
19
 
20
21
22
23
24
25
 
26
27
 
 
28
29
 
30
31
32
...
16
17
18
 
19
20
21
22
23
24
25
26
27
 
28
29
30
 
31
32
33
34
0
@@ -16,17 +16,19 @@ class CodeExtension (markdown.Extension):
0
         md.textPreprocessors.insert(0, preprocessor)
0
 
0
 
0
-CODE_BLOCK_REGEX = re.compile(r"@@ (?P<syntax>[a-zA-Z0-9_+-]+)\r?\n(?P<code>.*?)@@\r?\n", re.DOTALL)
0
+CODE_BLOCK_REGEX = re.compile(r"(?P<spaces>[ ]*)@@ (?P<syntax>[a-zA-Z0-9_+-]+)\r?\n(?P<code>.*?)@@\r?\n", re.DOTALL)
0
 
0
 class CodeBlockPreprocessor :
0
     def run (self, text):
0
         while  1:
0
             m = CODE_BLOCK_REGEX.search(text)
0
             if not m: break;
0
+            spaces = len(m.group('spaces'))
0
             lexer = get_lexer_by_name(m.group('syntax'))
0
-            color = highlight(m.group('code'), lexer, HtmlFormatter())
0
+            unspaced = [x[spaces:] for x in re.split('\r?\n', m.group('code'))]
0
+            color = highlight("\n".join(unspaced), lexer, HtmlFormatter())
0
             placeholder = self.md.htmlStash.store(color, safe=True)
0
-            text = '%s\n%s\n%s'% (text[:m.start()], placeholder, text[m.end():])
0
+            text = '%s\n%s\n%s'% (text[:m.start()], (' '*spaces)+placeholder, text[m.end():])
0
         return text
0
 
0
 

Comments