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..282227afa5eb51d6e204f3fdd0563dcd890ba264 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): |
@@ -58,6 +61,13 @@ class ContentProvider(object): |
if mimetype is None: |
content = text |
mimetype = 'text/plain' |
+ if path.endswith(".md"): |
+ content = markdown(content, extensions=['extra', 'admonition', |
not at google - send to devlin
2013/12/20 03:56:43
do you need ToUnicode(content) here?
hukun
2013/12/20 07:41:53
yes, more safe.
|
+ 'codehilite', 'headerid', 'meta', 'nl2br', 'sane_lists', |
+ 'toc', 'wikilinks']) |
not at google - send to devlin
2013/12/20 03:56:43
what do all of these mean? can you link to some do
hukun
2013/12/20 07:41:53
Done
|
+ mimetype = 'text/html' |
+ if self._supports_templates: |
+ content = Handlebar(content, name=path) |
not at google - send to devlin
2013/12/20 03:56:43
how about doing this outside the mimetype is None?
hukun
2013/12/20 07:41:53
Done
|
elif mimetype == 'text/html': |
content = ToUnicode(text) |
if self._supports_templates: |
@@ -69,6 +79,17 @@ class ContentProvider(object): |
content = text |
return ContentAndType(content, mimetype) |
+ def _CheckHTMLFileExists(self, path): |
not at google - send to devlin
2013/12/20 03:56:43
how about _MaybeMarkdown or something? this doesn'
hukun
2013/12/20 07:41:53
Done
|
+ dir_path, file_path = posixpath.split(path) |
+ if dir_path and not dir_path.endswith('/'): |
+ dir_path += '/' |
+ |
not at google - send to devlin
2013/12/20 03:56:43
use os.path.splitext, handy, and you can optimise
hukun
2013/12/20 07:41:53
Done
|
+ dir_stat = self.file_system.Stat(dir_path) |
not at google - send to devlin
2013/12/20 03:56:43
ReadSingle would be easier than Stat here.
hukun
2013/12/20 07:41:53
Done
|
+ if not dir_stat.child_versions.get(file_path): |
+ path = path.replace('html', 'md') |
not at google - send to devlin
2013/12/20 03:56:43
the logic should be probably be that IF it's an ht
hukun
2013/12/20 07:41:53
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._CheckHTMLFileExists(path)) |
def Cron(self): |
# Running Refresh() on the file system is enough to pull GitHub content, |