From 5c26f27b2ae6d3e0c3f5103cb5b847442baa6b9a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 10 Jan 2014 16:05:38 +0800 Subject: Fix up Pygments spacing --- glyphy/glyphy_slides.py | 4 ++-- pangopygments.py | 19 ++++++++++++++++++- 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("Drivers") slide("Case study\nMesa\nsoftware\nrenderer") -source_slide(""" "Infinite loop detected in fragment program" """) +source_slide("""\n "Infinite loop detected in fragment program" \n""") slide("Case study\nNvidia+Mac") patch_slide(""" @@ -739,7 +739,7 @@ Date: Wed Apr 11 13:24:22 2012 -0700 slide("60+fps\ni965 Thinkpad") slide("Case study\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("Case study\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"' -- cgit v1.2.3