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..3ceac51087f7dc240c5654e988a95d610900d85e 100644 |
| --- a/chrome/common/extensions/docs/server2/content_provider.py |
| +++ b/chrome/common/extensions/docs/server2/content_provider.py |
| @@ -1,15 +1,17 @@ |
| # 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. |
| - |
| +import logging |
| 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 +57,16 @@ 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
2013/12/20 11:50:41
Thanks for linking to this! Reading through them,
hukun
2013/12/23 05:12:58
Done
|
| + content = markdown(ToUnicode(text), extensions=['extra', |
| + 'admonition', 'codehilite', 'headerid', 'meta', 'nl2br', |
| + 'sane_lists', 'toc', 'wikilinks']) |
| + 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,23 @@ class ContentProvider(object): |
| content = text |
| return ContentAndType(content, mimetype) |
| + def _MaybeMarkdown(self, path): |
| + if os.path.splitext(path)[1] != '.html': |
| + return path |
| + |
| + try: |
| + self.file_system.ReadSingle(path).Get() |
|
not at google - send to devlin
2013/12/20 11:50:41
I would prefer not to implement this with exceptio
hukun
2013/12/23 05:12:58
Done
|
| + return path |
| + except FileNotFoundError: |
| + md_file_path = path.replace('html', 'md') |
| + try: |
| + self.file_system.ReadSingle(md_file_path).Get() |
| + logging.info('%s not found, try markdown templates at %s' % (path, |
| + md_file_path)) |
|
not at google - send to devlin
2013/12/20 11:50:41
don't worry about logging or anything, just let th
hukun
2013/12/23 05:12:58
Done
|
| + return md_file_path |
| + except FileNotFoundError: |
| + return path |
| + |
| def GetContentAndType(self, path): |
| path = path.lstrip('/') |
| base, ext = os.path.splitext(path) |
| @@ -79,7 +107,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, |