Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: tools/md_browser/md_browser.py

Issue 2754663002: Add png and jpg support to md_browser. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/md_browser/md_browser.py
diff --git a/tools/md_browser/md_browser.py b/tools/md_browser/md_browser.py
index 2c4164330aefb9a89452788c0e7e4cda08af205b..d3594bfe520c97ad810e9c63151122ab90c69824 100755
--- a/tools/md_browser/md_browser.py
+++ b/tools/md_browser/md_browser.py
@@ -138,6 +138,10 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self._DoMD(path)
elif os.path.exists(full_path + '/README.md'):
self._DoMD(path + '/README.md')
+ elif path.lower().endswith('.png'):
+ self._DoImage(full_path, 'image/png')
+ elif path.lower().endswith('.jpg'):
+ self._DoImage(full_path, 'image/jpeg')
else:
self._DoDirListing(full_path)
@@ -223,6 +227,12 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self._WriteTemplate('footer.html')
+ def _DoImage(self, full_path, mime_type):
+ self._WriteHeader(mime_type)
+ with open(full_path) as f:
+ self.wfile.write(f.read())
+ f.close()
+
def _Read(self, relpath, relative_to=None):
if relative_to is None:
relative_to = self.server.top_level
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698