Test the viewcode extension; decode the source files before highlighting them.

This commit is contained in:
Georg Brandl 2010-05-26 19:29:44 +02:00
parent 8d1235d7ad
commit d3d93a54f0
2 changed files with 7 additions and 4 deletions

View File

@ -31,7 +31,7 @@ def doctree_read(app, doctree):
env._viewcode_modules[modname] = False env._viewcode_modules[modname] = False
return return
analyzer.find_tags() analyzer.find_tags()
entry = analyzer.code, analyzer.tags, {} entry = analyzer.code.decode(analyzer.encoding), analyzer.tags, {}
env._viewcode_modules[modname] = entry env._viewcode_modules[modname] = entry
elif entry is False: elif entry is False:
return return
@ -41,7 +41,7 @@ def doctree_read(app, doctree):
return True return True
for objnode in doctree.traverse(addnodes.desc): for objnode in doctree.traverse(addnodes.desc):
if objnode['domain'] != 'py': if objnode.get('domain') != 'py':
continue continue
names = set() names = set()
for signode in objnode: for signode in objnode:
@ -87,7 +87,10 @@ def collect_pages(app):
app.builder.info(' (%d module code pages)' % app.builder.info(' (%d module code pages)' %
len(env._viewcode_modules), nonl=1) len(env._viewcode_modules), nonl=1)
for modname, (code, tags, used) in env._viewcode_modules.iteritems(): for modname, entry in env._viewcode_modules.iteritems():
if not entry:
continue
code, tags, used = entry
# construct a page name for the highlighted source # construct a page name for the highlighted source
pagename = '_modules/' + modname.replace('.', '/') pagename = '_modules/' + modname.replace('.', '/')
# highlight the source using the builder's highlighter # highlight the source using the builder's highlighter

View File

@ -7,7 +7,7 @@ sys.path.append(os.path.abspath('.'))
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.jsmath', 'sphinx.ext.todo', extensions = ['sphinx.ext.autodoc', 'sphinx.ext.jsmath', 'sphinx.ext.todo',
'sphinx.ext.coverage', 'sphinx.ext.autosummary', 'sphinx.ext.coverage', 'sphinx.ext.autosummary',
'sphinx.ext.doctest', 'sphinx.ext.extlinks', 'sphinx.ext.doctest', 'sphinx.ext.extlinks',
'sphinx.ext.oldcmarkup', 'ext'] 'sphinx.ext.viewcode', 'sphinx.ext.oldcmarkup', 'ext']
jsmath_path = 'dummy.js' jsmath_path = 'dummy.js'