[Python-checkins] r56643 - in doctools/trunk: converter/newfiles/conf.py converter/newfiles/doc_sphinx.rst converter/util.py sphinx/roles.py

georg.brandl python-checkins at python.org
Wed Aug 1 17:31:11 CEST 2007


Author: georg.brandl
Date: Wed Aug  1 17:31:10 2007
New Revision: 56643

Modified:
   doctools/trunk/converter/newfiles/conf.py
   doctools/trunk/converter/newfiles/doc_sphinx.rst
   doctools/trunk/converter/util.py
   doctools/trunk/sphinx/roles.py
Log:
Strip parentheses during conversion, add them during build.


Modified: doctools/trunk/converter/newfiles/conf.py
==============================================================================
--- doctools/trunk/converter/newfiles/conf.py	(original)
+++ doctools/trunk/converter/newfiles/conf.py	Wed Aug  1 17:31:10 2007
@@ -37,5 +37,5 @@
 # typographically correct entities.
 use_smartypants = True
 
-# If true, trailing '()' will be stripped from :func: etc. cross-references.
-strip_trailing_parentheses = False
+# If true, '()' will be appended to :func: etc. cross-reference text.
+add_function_parentheses = True

Modified: doctools/trunk/converter/newfiles/doc_sphinx.rst
==============================================================================
--- doctools/trunk/converter/newfiles/doc_sphinx.rst	(original)
+++ doctools/trunk/converter/newfiles/doc_sphinx.rst	Wed Aug  1 17:31:10 2007
@@ -50,6 +50,6 @@
    If true, use SmartyPants to convert quotes and dashes to the typographically
    correct entities.
 
-strip_trailing_parentheses : bool
-   If true, trailing parentheses will be stripped from ``:func:`` etc.
-   crossreferences.
\ No newline at end of file
+add_function_parentheses : bool
+   If true, ``()`` will be appended to the content of ``:func:``, ``:meth:`` and
+   ``:cfunc:`` cross-references.
\ No newline at end of file

Modified: doctools/trunk/converter/util.py
==============================================================================
--- doctools/trunk/converter/util.py	(original)
+++ doctools/trunk/converter/util.py	Wed Aug  1 17:31:10 2007
@@ -70,6 +70,7 @@
 wordchars_e = alphanum + u'+`(-'
 bad_markup_re = re.compile(r'(:[a-zA-Z0-9_-]+:)?(`{1,2})[ ]*(.+?)[ ]*(\2)')
 quoted_code_re = re.compile(r'\\`(``.+?``)\'')
+paren_re = re.compile(r':(func|meth|cfunc):`(.*?)\(\)`')
 
 def repair_bad_inline_markup(text):
     # remove quoting from `\code{x}'
@@ -80,6 +81,9 @@
     # special: literal backquotes
     xtext = xtext.replace('``````', '\x02')
 
+    # remove () from function markup
+    xtext = paren_re.sub(r':\1:`\2`', xtext)
+
     ntext = []
     lasti = 0
     l = len(xtext)

Modified: doctools/trunk/sphinx/roles.py
==============================================================================
--- doctools/trunk/sphinx/roles.py	(original)
+++ doctools/trunk/sphinx/roles.py	Wed Aug  1 17:31:10 2007
@@ -98,9 +98,9 @@
     # 'token' is the default role inside 'productionlist' directives
     if typ == '':
         typ = 'token'
-    if env.config.get('strip_trailing_parentheses', False):
-        if text[-2:] == '()':
-            text = text[:-2]
+    if typ in ('func', 'meth', 'cfunc') and \
+           env.config.get('add_function_parentheses', True):
+        text += '()'
     pnode = addnodes.pending_xref(rawtext)
     pnode['reftype'] = typ
     pnode['reftarget'] = ws_re.sub('', text)


More information about the Python-checkins mailing list