Permalink
Browse files

At least it runs again.

  • Loading branch information...
1 parent fb84c58 commit 1d6d0807e11da66d00043d67c51b69f01d20e459 @fredreichbier fredreichbier committed May 4, 2012
Showing with 92 additions and 90 deletions.
  1. +6 −6 sphinx_ooc/desc.py
  2. +86 −84 sphinx_ooc/roles.py
View
@@ -5,7 +5,7 @@
from sphinx import addnodes
from sphinx.roles import xfileref_role
-from sphinx.directives.desc import DescDirective
+from sphinx.directives import DescDirective
from sphinx.util.compat import Directive, directive_dwim
ooc_sig_re = re.compile(
@@ -21,11 +21,11 @@ class OOCDesc(DescDirective):
"""
Description of a ooc object.
"""
- doc_fields_without_arg = DescDirective.doc_fields_without_arg.copy()
- doc_fields_without_arg.update({
- 'extends': 'extends',
- 'from': 'from',
- })
+# doc_fields_without_arg = DescDirective.doc_fields_without_arg.copy()
+# doc_fields_without_arg.update({
+# 'extends': 'extends',
+# 'from': 'from',
+# })
def get_signature_prefix(self, sig):
return ''
View
@@ -4,7 +4,7 @@
from sphinx import addnodes
from sphinx.environment import BuildEnvironment
from sphinx.util import ws_re, caption_ref_re
-from sphinx.roles import innernodetypes
+from sphinx.roles import XRefRole
def _fix_parens(typ, text, env):
if typ in ('func', 'meth', 'cfunc'):
@@ -16,30 +16,33 @@ def _fix_parens(typ, text, env):
text += '()'
return text
-def ooc_xfileref_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
- env = inliner.document.settings.env
- if not typ:
- typ = env.config.default_role
- else:
- typ = typ.lower()
- text = utils.unescape(text)
- # if the first character is a bang, don't cross-reference at all
- if text[0:1] == '!':
- text = _fix_parens(typ, text[1:], env)
- return [innernodetypes.get(typ, nodes.literal)(
- rawtext, text, classes=['xref'])], []
- # we want a cross-reference, create the reference node
- nodeclass = (typ == 'download') and addnodes.download_reference or \
- addnodes.pending_xref
- pnode = nodeclass(rawtext, reftype=typ, refcaption=False,
- modname=env.currmodule, classname=env.currclass)
- # we may need the line number for warnings
- pnode.line = lineno
- # the link title may differ from the target, but by default
- # they are the same
- title = target = text
- titleistarget = True
- # look if explicit title and target are given with `foo <bar>` syntax
+class XOOCRefRole(XRefRole):
+ def __call__(self, typ, rawtext, text, lineno, inliner, options={}, content=[]):
+ env = inliner.document.settings.env
+ if not typ:
+ typ = env.config.default_role
+ else:
+ typ = typ.lower()
+ text = utils.unescape(text)
+ # if the first character is a bang, don't cross-reference at all
+ if text[0:1] == '!':
+ text = utils.unescape(text)[1:]
+ if self.fix_parens:
+ text, tgt = self._fix_parens(env, False, text, "")
+ innernode = self.innernodeclass(rawtext, text, classes=classes)
+ return self.result_nodes(inliner.document, env, innernode, is_ref=False)
+ # we want a cross-reference, create the reference node
+ nodeclass = (typ == 'download') and addnodes.download_reference or \
+ addnodes.pending_xref
+ pnode = nodeclass(rawtext, reftype=typ, refcaption=False,
+ modname=env.currmodule, classname=env.currclass)
+ # we may need the line number for warnings
+ pnode.line = lineno
+ # the link title may differ from the target, but by default
+ # they are the same
+ title = target = text
+ titleistarget = True
+ # look if explicit title and target are given with `foo <bar>` syntax
# brace = text.find('<')
# if brace != -1:
# titleistarget = False
@@ -52,65 +55,64 @@ def ooc_xfileref_role(typ, rawtext, text, lineno, inliner, options={}, content=[
# # fallback: everything after '<' is the target
# target = text[brace+1:]
# title = text[:brace]
- # TODO: kicked for generics. aarrrrghhh.
- # special target for Python object cross-references
- if typ in ('data', 'exc', 'func', 'class', 'const', 'field',
- 'meth', 'mod', 'obj', 'cover', 'var'):
- # fix-up parentheses in link title
- if titleistarget:
- title = title.lstrip('.') # only has a meaning for the target
- target = target.lstrip('~') # only has a meaning for the title
- title = _fix_parens(typ, title, env)
- # if the first character is a tilde, don't display the module/class
- # parts of the contents
- if title[0:1] == '~':
- title = title[1:]
- dot = title.rfind(' ')
- if dot != -1:
- title = title[dot+1:]
- # remove parentheses from the target too
- if target.endswith('()'):
- target = target[:-2]
- # if the first character is a dot, search more specific namespaces first
- # else search builtins first
- if target[0:1] == '.':
- target = target[1:]
- pnode['refspecific'] = True
- # some other special cases for the target
- elif typ == 'option':
- program = env.currprogram
- if titleistarget:
- if ' ' in title and not (title.startswith('/') or
- title.startswith('-')):
- program, target = re.split(' (?=-|--|/)', title, 1)
+ # TODO: kicked for generics. aarrrrghhh.
+ # special target for Python object cross-references
+ if typ in ('data', 'exc', 'func', 'class', 'const', 'field',
+ 'meth', 'mod', 'obj', 'cover', 'var'):
+ # fix-up parentheses in link title
+ if titleistarget:
+ title = title.lstrip('.') # only has a meaning for the target
+ target = target.lstrip('~') # only has a meaning for the title
+ title = _fix_parens(typ, title, env)
+ # if the first character is a tilde, don't display the module/class
+ # parts of the contents
+ if title[0:1] == '~':
+ title = title[1:]
+ dot = title.rfind(' ')
+ if dot != -1:
+ title = title[dot+1:]
+ # remove parentheses from the target too
+ if target.endswith('()'):
+ target = target[:-2]
+ # if the first character is a dot, search more specific namespaces first
+ # else search builtins first
+ if target[0:1] == '.':
+ target = target[1:]
+ pnode['refspecific'] = True
+ # some other special cases for the target
+ elif typ == 'option':
+ program = env.currprogram
+ if titleistarget:
+ if ' ' in title and not (title.startswith('/') or
+ title.startswith('-')):
+ program, target = re.split(' (?=-|--|/)', title, 1)
+ program = ws_re.sub('-', program)
+ target = target.strip()
+ elif ' ' in target:
+ program, target = re.split(' (?=-|--|/)', target, 1)
program = ws_re.sub('-', program)
- target = target.strip()
- elif ' ' in target:
- program, target = re.split(' (?=-|--|/)', target, 1)
- program = ws_re.sub('-', program)
- pnode['refprogram'] = program
- elif typ == 'term':
- # normalize whitespace in definition terms (if the term reference is
- # broken over a line, a newline will be in target)
- target = ws_re.sub(' ', target).lower()
- elif typ == 'ref':
- # reST label names are always lowercased
- target = ws_re.sub('', target).lower()
- elif typ == 'cfunc':
- # fix-up parens for C functions too
- if titleistarget:
- title = _fix_parens(typ, title, env)
- # remove parentheses from the target too
- if target.endswith('()'):
- target = target[:-2]
- else:
- # remove all whitespace to avoid referencing problems
- target = ws_re.sub('', target)
- pnode['reftarget'] = target
- pnode += innernodetypes.get(typ, nodes.literal)(rawtext, title,
- classes=['xref'])
- return [pnode], []
+ pnode['refprogram'] = program
+ elif typ == 'term':
+ # normalize whitespace in definition terms (if the term reference is
+ # broken over a line, a newline will be in target)
+ target = ws_re.sub(' ', target).lower()
+ elif typ == 'ref':
+ # reST label names are always lowercased
+ target = ws_re.sub('', target).lower()
+ elif typ == 'cfunc':
+ # fix-up parens for C functions too
+ if titleistarget:
+ title = _fix_parens(typ, title, env)
+ # remove parentheses from the target too
+ if target.endswith('()'):
+ target = target[:-2]
+ else:
+ # remove all whitespace to avoid referencing problems
+ target = ws_re.sub('', target)
+ pnode['reftarget'] = target
+ pnode += self.innernodeclass(rawtext, title, classes=['xref'])
+ return [pnode], []
for role in ('cover', 'class', 'func', 'meth', 'field', 'var'):
- roles.register_local_role(role, ooc_xfileref_role)
-BuildEnvironment.descroles = frozenset(set(BuildEnvironment.descroles) | set(('cover',)))
+ roles.register_local_role(role, XOOCRefRole())
+#BuildEnvironment.descroles = frozenset(set(BuildEnvironment.descroles) | set(('cover',)))

0 comments on commit 1d6d080

Please sign in to comment.