def _CompileContent(self, path, text):
   assert text is not None, path
   try:
     _, ext = posixpath.splitext(path)
     mimetype = _MIMETYPE_OVERRIDES.get(ext, mimetypes.guess_type(path)[0])
     if ext == '.md':
       # See http://pythonhosted.org/Markdown/extensions
       # for details on "extensions=".
       content = markdown(ToUnicode(text),
                          extensions=('extra', 'headerid', 'sane_lists'))
       mimetype = 'text/html'
       if self._supports_templates:
         content = Motemplate(content, name=path)
     elif mimetype is None:
       content = text
       mimetype = 'text/plain'
     elif mimetype == 'text/html':
       content = ToUnicode(text)
       if self._supports_templates:
         content = Motemplate(content, name=path)
     elif (mimetype.startswith('text/') or
           mimetype in ('application/javascript', 'application/json')):
       content = ToUnicode(text)
     else:
       content = text
     return ContentAndType(content,
                           mimetype,
                           self.file_system.Stat(path).version)
   except Exception as e:
     logging.warn('In file %s: %s' % (path, e.message))
     return ContentAndType('', mimetype, self.file_system.Stat(path).version)
 def _CompileContent(self, path, text):
     assert text is not None, path
     _, ext = posixpath.splitext(path)
     mimetype = _MIMETYPE_OVERRIDES.get(ext, mimetypes.guess_type(path)[0])
     if ext == '.md':
         # 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':
         content = ToUnicode(text)
         if self._supports_templates:
             content = Handlebar(content, name=path)
     elif (mimetype.startswith('text/')
           or mimetype in ('application/javascript', 'application/json')):
         content = ToUnicode(text)
     else:
         content = text
     return ContentAndType(content, mimetype,
                           self.file_system.Stat(path).version)
Beispiel #3
0
 def _CompileContent(self, path, text):
   assert text is not None, path
   _, ext = posixpath.splitext(path)
   mimetype = _MIMETYPE_OVERRIDES.get(ext, mimetypes.guess_type(path)[0])
   if ext == '.md':
     # 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':
     content = ToUnicode(text)
     if self._supports_templates:
       content = Handlebar(content, name=path)
   elif (mimetype.startswith('text/') or
         mimetype in ('application/javascript', 'application/json')):
     content = ToUnicode(text)
   else:
     content = text
   return ContentAndType(content, mimetype)
Beispiel #4
0
 def _CompileContent(self, path, text):
     assert text is not None, path
     mimetype = mimetypes.guess_type(path)[0]
     if posixpath.splitext(path)[1] == ".md":
         # 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":
         content = ToUnicode(text)
         if self._supports_templates:
             content = Handlebar(content, name=path)
     elif mimetype.startswith("text/") or mimetype in ("application/javascript", "application/json"):
         content = ToUnicode(text)
     else:
         content = text
     return ContentAndType(content, mimetype)