trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From js...@apache.org
Subject [trafficserver] 04/04: TS-5107: Changes to autolinking in Docutils 0.13
Date Wed, 25 Jan 2017 18:52:54 GMT
This is an automated email from the ASF dual-hosted git repository.

jsime pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 111e7f5b831298cb4cba446c362cfa450e83e99d
Author: Jack Bates <jack@nottheoilrig.com>
AuthorDate: Fri Jan 6 12:55:44 2017 -0700

    TS-5107: Changes to autolinking in Docutils 0.13
    
    init_customizations() was added in Docutils 0.13.
---
 doc/conf.py | 51 ++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 40 insertions(+), 11 deletions(-)

diff --git a/doc/conf.py b/doc/conf.py
index 8ee27b8..7a1ae44 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -165,25 +165,54 @@ pygments_style = 'sphinx'
 
 nitpicky=1
 
-# Autolink issue references
+# Autolink issue references.
+# See Customizing the Parser in the docutils.parsers.rst module.
 
 from docutils import nodes
 from docutils.parsers.rst import states
+from docutils.utils import punctuation_chars
 from docutils.utils import unescape
 
 # Customize parser.inliner in the only way that Sphinx supports.
 # docutils.parsers.rst.Parser takes an instance of states.Inliner or a
-# subclass but Sphinx initializes it from
-# SphinxStandaloneReader.set_parser('restructuredtext') which is called
-# from Publisher.set_components() and initializes the parser without
-# arguments.
+# subclass, but Sphinx initializes the parser without any arguments,
+# in SphinxStandaloneReader.set_parser('restructuredtext'),
+# which is called from Publisher.set_components().
 
+# states.Inliner isn't a new-style class, so super() isn't an option.
 BaseInliner = states.Inliner
-class Inliner(BaseInliner):
-  def __init__(self):
-    BaseInliner.__init__(self)
-
-    issue_pattern = re.compile(u'''
+class Inliner(states.Inliner):
+  if hasattr(states.Inliner, 'init_customizations'):
+    def init_customizations(self, settings):
+      self.__class__ = BaseInliner
+      BaseInliner.init_customizations(self, settings)
+      self.__class__ = Inliner
+
+      # Copied from states.Inliner.init_customizations().
+      # In Docutils 0.13 these are locals.
+      if settings.character_level_inline_markup:
+        self.start_string_prefix = u'(^|(?<!\x00))'
+        self.end_string_suffix = u''
+      else:
+        self.start_string_prefix = (u'(^|(?<=\\s|[%s%s]))' %
+                                    (punctuation_chars.openers,
+                                     punctuation_chars.delimiters))
+        self.end_string_suffix = (u'($|(?=\\s|[\x00%s%s%s]))' %
+                                  (punctuation_chars.closing_delimiters,
+                                   punctuation_chars.delimiters,
+                                   punctuation_chars.closers))
+
+      self.init()
+  else:
+    def __init__(self):
+      BaseInliner.__init__(self)
+      self.init()
+
+  # Called from __init__() in Docutils < 0.13, otherwise from
+  # init_customizations(), which was added in Docutils 0.13.
+  def init(self):
+    issue = re.compile(
+      ur'''
       {start_string_prefix}
       TS-\d+
       {end_string_suffix}'''.format(
@@ -191,7 +220,7 @@ class Inliner(BaseInliner):
         end_string_suffix=self.end_string_suffix),
       re.VERBOSE | re.UNICODE)
 
-    self.implicit_dispatch.append((issue_pattern, self.issue_reference))
+    self.implicit_dispatch.append((issue, self.issue_reference))
 
   def issue_reference(self, match, lineno):
     text = match.group(0)

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>.

Mime
View raw message