diff options
-rwxr-xr-x | glyphy/glyphy_slides.py | 4 | ||||
-rwxr-xr-x | 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("<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"' |