Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2013 The Native Client Authors. All rights reserved. | 1 # Copyright (c) 2013 The Native Client 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 # | 5 # |
| 6 # This is a Sphinx extension. | 6 # This is a Sphinx extension. |
| 7 # | 7 # |
| 8 | 8 |
| 9 import codecs | 9 import codecs |
| 10 import os | 10 import os |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 self.section_level -= 1 | 138 self.section_level -= 1 |
| 139 self.body.append('</section>') | 139 self.body.append('</section>') |
| 140 | 140 |
| 141 def visit_image(self, node): | 141 def visit_image(self, node): |
| 142 # Paths to images in .rst sources should be absolute. This visitor does the | 142 # Paths to images in .rst sources should be absolute. This visitor does the |
| 143 # required transformation for the path to be correct in the final HTML. | 143 # required transformation for the path to be correct in the final HTML. |
| 144 if self.builder.devsite_production_mode: | 144 if self.builder.devsite_production_mode: |
| 145 node['uri'] = '/native-client/' + node['uri'] | 145 node['uri'] = '/native-client/' + node['uri'] |
| 146 HTMLTranslator.visit_image(self, node) | 146 HTMLTranslator.visit_image(self, node) |
| 147 | 147 |
| 148 def visit_reference(self, node): | |
| 149 # In "kill_internal_links" mode, we don't emit the actual links for internal | |
| 150 # nodes. | |
| 151 if self.builder.kill_internal_links and node.get('internal'): | |
| 152 pass | |
| 153 else: | |
| 154 HTMLTranslator.visit_reference(self, node) | |
| 155 | |
| 156 def depart_reference(self, node): | |
| 157 if self.builder.kill_internal_links and node.get('internal'): | |
| 158 pass | |
| 159 else: | |
| 160 HTMLTranslator.depart_reference(self, node) | |
| 161 | |
| 148 def visit_title(self, node): | 162 def visit_title(self, node): |
| 149 # Why this? | 163 # Why this? |
| 150 # | 164 # |
| 151 # Sphinx insists on inserting a <h1>Page Title</h1> into the page, but this | 165 # Sphinx insists on inserting a <h1>Page Title</h1> into the page, but this |
| 152 # is not how the devsite wants it. The devsite inserts the page title on | 166 # is not how the devsite wants it. The devsite inserts the page title on |
| 153 # its own, the the extra h1 is duplication. | 167 # its own, the the extra h1 is duplication. |
| 154 # | 168 # |
| 155 # Killing the doctree title node in a custom transform doesn't work, because | 169 # Killing the doctree title node in a custom transform doesn't work, because |
| 156 # Sphinx explicitly looks for it when writing a document. So instead we rig | 170 # Sphinx explicitly looks for it when writing a document. So instead we rig |
| 157 # the HTML produced. | 171 # the HTML produced. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 """ | 228 """ |
| 215 name = 'devsite' | 229 name = 'devsite' |
| 216 out_suffix = '.html' | 230 out_suffix = '.html' |
| 217 link_suffix = '.html' | 231 link_suffix = '.html' |
| 218 | 232 |
| 219 # Disable the addition of "pi"-permalinks to each section header | 233 # Disable the addition of "pi"-permalinks to each section header |
| 220 add_permalinks = False | 234 add_permalinks = False |
| 221 | 235 |
| 222 def init(self): | 236 def init(self): |
| 223 self.devsite_production_mode = int(self.config.devsite_production_mode) == 1 | 237 self.devsite_production_mode = int(self.config.devsite_production_mode) == 1 |
| 238 self.kill_internal_links = int(self.config.kill_internal_links) == 1 | |
| 224 print "----> Devsite builder with production mode = %d" % ( | 239 print "----> Devsite builder with production mode = %d" % ( |
| 225 self.devsite_production_mode,) | 240 self.devsite_production_mode,) |
| 226 self.config_hash = '' | 241 self.config_hash = '' |
| 227 self.tags_hash = '' | 242 self.tags_hash = '' |
| 228 self.theme = None # no theme necessary | 243 self.theme = None # no theme necessary |
| 229 self.templates = None # no template bridge necessary | 244 self.templates = None # no template bridge necessary |
| 230 self.init_translator_class() | 245 self.init_translator_class() |
| 231 self.init_highlighter() | 246 self.init_highlighter() |
| 232 | 247 |
| 233 def get_target_uri(self, docname, typ=None): | 248 def get_target_uri(self, docname, typ=None): |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 | 316 |
| 302 | 317 |
| 303 def setup(app): | 318 def setup(app): |
| 304 """ Extension registration hook. | 319 """ Extension registration hook. |
| 305 """ | 320 """ |
| 306 app.add_directive('naclcode', NaclCodeDirective) | 321 app.add_directive('naclcode', NaclCodeDirective) |
| 307 app.add_builder(DevsiteBuilder) | 322 app.add_builder(DevsiteBuilder) |
| 308 | 323 |
| 309 # "Production mode" for local testing vs. on-server documentation. | 324 # "Production mode" for local testing vs. on-server documentation. |
| 310 app.add_config_value('devsite_production_mode', default='1', rebuild='html') | 325 app.add_config_value('devsite_production_mode', default='1', rebuild='html') |
| 326 | |
| 327 app.add_config_value('kill_internal_links', default='0', rebuild='html') | |
| 328 | |
|
Sam Clegg
2013/10/01 23:45:46
Kill extra line.
| |
| OLD | NEW |