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..4211a79286a761e2da8f1daf861f72f079f49e4d 100644 |
| --- a/chrome/common/extensions/docs/server2/content_provider.py |
| +++ b/chrome/common/extensions/docs/server2/content_provider.py |
| @@ -4,12 +4,15 @@ |
| import mimetypes |
| import os |
| +import posixpath |
| 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 +58,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': |
|
not at google - send to devlin
2014/01/07 22:36:40
posixpath.splitext
hukun
2014/01/08 17:13:41
done
On 2014/01/07 22:36:40, kalman wrote:
|
| + # See http://pythonhosted.org/Markdown/extensions |
| + # for details on "extensions=". |
| + content = markdown(ToUnicode(text), |
| + extensions=('extra', 'headerid', 'sane_lists')) |
| + 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 +80,19 @@ class ContentProvider(object): |
| content = text |
| return ContentAndType(content, mimetype) |
| + def _MaybeMarkdown(self, path): |
| + if posixpath.splitext(path)[1] != '.html': |
| + return path |
| + |
| + dirname, file_name = posixpath.split(path) |
| + file_list = self.file_system.ReadSingle(dirname + '/').Get() |
| + if file_name in file_list: |
| + return path |
| + |
| + if posixpath.splitext(file_name)[0] + '.md' in file_list: |
| + return posixpath.splitext(path)[0] + '.md' |
| + return path |
| + |
| def GetContentAndType(self, path): |
| path = path.lstrip('/') |
| base, ext = os.path.splitext(path) |
|
not at google - send to devlin
2014/01/07 22:36:40
cleanup: posixpath.splitext
then you can remove t
hukun
2014/01/08 17:13:41
done
|
| @@ -79,7 +103,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, |