| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Simple Markdown browser for a Git checkout.""" | 5 """Simple Markdown browser for a Git checkout.""" |
| 6 from __future__ import print_function | 6 from __future__ import print_function |
| 7 | 7 |
| 8 import SimpleHTTPServer | 8 import SimpleHTTPServer |
| 9 import SocketServer | 9 import SocketServer |
| 10 import argparse | 10 import argparse |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 elif path.lower().endswith('.md'): | 67 elif path.lower().endswith('.md'): |
| 68 self._DoMD(path) | 68 self._DoMD(path) |
| 69 else: | 69 else: |
| 70 self._DoUnknown() | 70 self._DoUnknown() |
| 71 | 71 |
| 72 def _DoMD(self, path): | 72 def _DoMD(self, path): |
| 73 extensions = [ | 73 extensions = [ |
| 74 'markdown.extensions.fenced_code', | 74 'markdown.extensions.fenced_code', |
| 75 'markdown.extensions.tables', | 75 'markdown.extensions.tables', |
| 76 'markdown.extensions.toc', | 76 'markdown.extensions.toc', |
| 77 'gitiles_ext_blocks', |
| 77 ] | 78 ] |
| 78 | 79 |
| 79 contents = self._Read(path[1:]) | 80 contents = self._Read(path[1:]) |
| 80 md_fragment = markdown.markdown(contents, | 81 md_fragment = markdown.markdown(contents, |
| 81 extensions=extensions, | 82 extensions=extensions, |
| 82 output_format='html4').encode('utf-8') | 83 output_format='html4').encode('utf-8') |
| 83 try: | 84 try: |
| 84 self._WriteTemplate('header.html') | 85 self._WriteTemplate('header.html') |
| 85 self.wfile.write(md_fragment) | 86 self.wfile.write(md_fragment) |
| 86 self._WriteTemplate('footer.html') | 87 self._WriteTemplate('footer.html') |
| (...skipping 13 matching lines...) Expand all Loading... |
| 100 with codecs.open(path, encoding='utf-8') as fp: | 101 with codecs.open(path, encoding='utf-8') as fp: |
| 101 return fp.read() | 102 return fp.read() |
| 102 | 103 |
| 103 def _WriteTemplate(self, template): | 104 def _WriteTemplate(self, template): |
| 104 contents = self._Read(os.path.join('tools', 'md_browser', template)) | 105 contents = self._Read(os.path.join('tools', 'md_browser', template)) |
| 105 self.wfile.write(contents.encode('utf-8')) | 106 self.wfile.write(contents.encode('utf-8')) |
| 106 | 107 |
| 107 | 108 |
| 108 if __name__ == '__main__': | 109 if __name__ == '__main__': |
| 109 sys.exit(main(sys.argv[1:])) | 110 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |