Skip to content

Commit

Permalink
Make md_browser support gitiles-style URLs slightly better.
Browse files Browse the repository at this point in the history
URLs in gitiles usually contain information about the repo
and the branch as part of the URL, e.g. "/chromium/src/+/master/foo".
This patch adds support to md_browser so that that will get
re-mapped to "foo" as a source-relative path in the current checkout.

R=nodir@chromium.org, andybons@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1394043002

Cr-Commit-Position: refs/heads/master@{#353001}
  • Loading branch information
dpranke authored and Commit bot committed Oct 8, 2015
1 parent 8dd499a commit ec0d910
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tools/md_browser/md_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,34 @@ def server_bind(self):

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
full_path = os.path.abspath(os.path.join(self.server.top_level,
self.path[1:]))
path = self.path

# strip off the repo and branch info, if present, for compatibility
# with gitiles.
if path.startswith('/chromium/src/+/master'):
path = path[len('/chromium/src/+/master'):]

full_path = os.path.abspath(os.path.join(self.server.top_level, path[1:]))

if not full_path.startswith(SRC_DIR):
self._DoUnknown()
elif self.path == '/doc.css':
elif path == '/doc.css':
self._WriteTemplate('doc.css')
elif not os.path.exists(full_path):
self._DoNotFound()
elif self.path.lower().endswith('.md'):
self._DoMD()
elif path.lower().endswith('.md'):
self._DoMD(path)
else:
self._DoUnknown()

def _DoMD(self):
def _DoMD(self, path):
extensions = [
'markdown.extensions.fenced_code',
'markdown.extensions.tables',
'markdown.extensions.toc',
]

contents = self._Read(self.path[1:])
contents = self._Read(path[1:])
md_fragment = markdown.markdown(contents,
extensions=extensions,
output_format='html4').encode('utf-8')
Expand Down

0 comments on commit ec0d910

Please sign in to comment.