Created
February 17, 2016 13:59
-
-
Save raghavrv/0326d6212c1f20df3db8 to your computer and use it in GitHub Desktop.
Display CPP code with syntax highlighting in Jupyter Notebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import Markdown, HTML, display_markdown | |
from glob import glob | |
cpp_markdown_template = """```cpp\n%s\n```\n<hr>""" | |
for i, problem in enumerate( | |
glob("/media/rvraghav93/code/projects/competitive_programming/codechef/*.cpp")): | |
with open(problem) as f: | |
code = f.read().splitlines() | |
url = code[0] | |
code_md = cpp_markdown_template % "\n".join(code[1:]) | |
print i+1, url.strip('/ ') | |
display_markdown(Markdown(code_md)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment