summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2014-01-10 16:05:38 +0800
committerBehdad Esfahbod <behdad@behdad.org>2014-01-10 16:05:38 +0800
commit5c26f27b2ae6d3e0c3f5103cb5b847442baa6b9a (patch)
tree04d124c0faca851c64fec1cd85484c97c2602c04
parent3ce3c18890bc1a1215d98d1a92ce32d7a849d918 (diff)
Fix up Pygments spacing
-rwxr-xr-xglyphy/glyphy_slides.py4
-rwxr-xr-xpangopygments.py19
2 files changed, 20 insertions, 3 deletions
diff --git a/glyphy/glyphy_slides.py b/glyphy/glyphy_slides.py
index f541144..7f1d4e0 100755
--- a/glyphy/glyphy_slides.py
+++ b/glyphy/glyphy_slides.py
@@ -645,7 +645,7 @@ def commit_slide(s, who=None):
slide_noone("<b>Drivers</b>")
slide("<b>Case study</b>\nMesa\nsoftware\nrenderer")
-source_slide(""" "Infinite loop detected in fragment program" """)
+source_slide("""\n "Infinite loop detected in fragment program" \n""")
slide("<b>Case study</b>\nNvidia+Mac")
patch_slide("""
@@ -739,7 +739,7 @@ Date: Wed Apr 11 13:24:22 2012 -0700
slide("60+fps\ni965 Thinkpad")
slide("<b>Case study</b>\niPod 3G")
-source_slide(""" "Demo runs SLOW on my iPod 3G. ~3 FPS" """)
+source_slide("""\n "Demo runs SLOW on my iPod 3G. ~3 FPS" \n""")
slide("<b>Case study</b>\nAndroid 4.3+LGE")
patch_slide("""
diff --git a/pangopygments.py b/pangopygments.py
index 1dec314..05685a7 100755
--- a/pangopygments.py
+++ b/pangopygments.py
@@ -77,7 +77,24 @@ def highlight(snippet, lang):
print('Language %s is not supported.' % lang)
return snippet
- return pygments.highlight(snippet, __LEXERS[lang](), PangoFormatter())
+ # Pygments messes up initial and final newlines; fix up
+ begin = ''
+ if snippet[0] == '\n':
+ begin = '\n'
+ snippet = snippet[1:]
+ end = ''
+ if snippet[-1] == '\n':
+ end = '\n'
+ snippet = snippet[:-1]
+
+ snippet = pygments.highlight(snippet, __LEXERS[lang](), PangoFormatter())
+
+ if snippet[0] == '\n' and start == '\n':
+ start = ''
+ if snippet[-1] == '\n' and end == '\n':
+ end = ''
+
+ return begin + snippet + end
if __name__ == '__main__':
code = 'print "Hello World"'