Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/content_provider.py |
| diff --git a/chrome/common/extensions/docs/server2/content_provider.py b/chrome/common/extensions/docs/server2/content_provider.py |
| index f757023bff256369b64a6c6ddf178819e8accb79..90c16950d845ae9debb38d1ad22cdf987ff1b6f1 100644 |
| --- a/chrome/common/extensions/docs/server2/content_provider.py |
| +++ b/chrome/common/extensions/docs/server2/content_provider.py |
| @@ -1,15 +1,16 @@ |
| # Copyright 2013 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| - |
|
not at google - send to devlin
2014/01/03 03:18:01
leave this here
hukun
2014/01/06 08:25:19
Done
|
| import mimetypes |
| import os |
| from compiled_file_system import SingleFile |
| from directory_zipper import DirectoryZipper |
| from docs_server_utils import ToUnicode |
| +from file_system import FileNotFoundError |
| from future import Gettable, Future |
| from third_party.handlebar import Handlebar |
| +from third_party.markdown import markdown |
| class ContentAndType(object): |
| @@ -55,7 +56,15 @@ class ContentProvider(object): |
| def _CompileContent(self, path, text): |
| assert text is not None, path |
| mimetype = mimetypes.guess_type(path)[0] |
| - if mimetype is None: |
| + if os.path.splitext(path)[1] == '.md': |
| + # markdown extensions' introduction in the following url |
| + # http://pythonhosted.org/Markdown/extensions/index.html |
|
not at google - send to devlin
2014/01/03 03:18:01
I can't really parse the comment. How about:
# Se
hukun
2014/01/06 08:25:19
Done
|
| + content = markdown(ToUnicode(text), extensions=('extra', 'headerid', |
| + 'sane_lists')) |
|
not at google - send to devlin
2014/01/03 03:18:01
indentation:
content = markdown(ToUnicode(text),
hukun
2014/01/06 08:25:19
Done
|
| + if self._supports_templates: |
| + content = Handlebar(content, name=path) |
| + mimetype = 'text/html' |
| + elif mimetype is None: |
| content = text |
| mimetype = 'text/plain' |
| elif mimetype == 'text/html': |
| @@ -69,6 +78,18 @@ class ContentProvider(object): |
| content = text |
| return ContentAndType(content, mimetype) |
| + def _MaybeMarkdown(self, path): |
| + if os.path.splitext(path)[1] != '.html': |
|
not at google - send to devlin
2014/01/03 03:21:41
use posixpath.splitext
hukun
2014/01/06 08:25:19
Done
|
| + return path |
| + |
|
not at google - send to devlin
2014/01/03 03:18:01
Use posixpath not os.path since the latter will br
hukun
2014/01/06 08:25:19
Done
|
| + file_list = self.file_system.ReadSingle(os.path.dirname(path) + '/').Get() |
| + file_name = os.path.basename(path) |
| + if file_name not in file_list: |
|
not at google - send to devlin
2014/01/03 03:18:01
prefer early return like "if file_name in file_lis
hukun
2014/01/06 08:25:19
Done
|
| + md_file_name = file_name.replace('html', 'md') |
|
not at google - send to devlin
2014/01/03 03:18:01
replace .html -> .md not html -> md in case the fi
not at google - send to devlin
2014/01/03 03:21:41
Actually even better may be to write more like
ba
hukun
2014/01/06 08:25:19
Done
hukun
2014/01/06 08:25:19
Done
|
| + if md_file_name in file_list: |
| + return path.replace('html', 'md') |
|
not at google - send to devlin
2014/01/03 03:18:01
ditto.
hukun
2014/01/06 08:25:19
Done
|
| + return path |
| + |
| def GetContentAndType(self, path): |
| path = path.lstrip('/') |
| base, ext = os.path.splitext(path) |
| @@ -79,7 +100,7 @@ class ContentProvider(object): |
| return Future(delegate=Gettable( |
| lambda: ContentAndType(zip_future.Get(), 'application/zip'))) |
| - return self._content_cache.GetFromFile(path) |
| + return self._content_cache.GetFromFile(self._MaybeMarkdown(path)) |
| def Cron(self): |
| # Running Refresh() on the file system is enough to pull GitHub content, |