@@ -145,6 +145,45 @@ def run(self):
145145 return ret
146146
147147
148+ # Support for including Misc/NEWS
149+
150+ import re
151+ import codecs
152+ from docutils .statemachine import string2lines
153+ from sphinx .util .nodes import nested_parse_with_titles
154+
155+ issue_re = re .compile ('Issue #([0-9]+)' )
156+
157+ class MiscNews (Directive ):
158+ has_content = False
159+ required_arguments = 1
160+ optional_arguments = 0
161+ final_argument_whitespace = False
162+ option_spec = {}
163+
164+ def run (self ):
165+ fname = self .arguments [0 ]
166+ source = self .state_machine .input_lines .source (
167+ self .lineno - self .state_machine .input_offset - 1 )
168+ source_dir = path .dirname (path .abspath (source ))
169+ try :
170+ fp = codecs .open (path .join (source_dir , fname ), encoding = 'utf-8' )
171+ try :
172+ content = fp .read ()
173+ finally :
174+ fp .close ()
175+ except Exception :
176+ text = 'The NEWS file is not available.'
177+ node = nodes .strong (text , text )
178+ return [node ]
179+ content = issue_re .sub (r'`Issue #\1 <http://bugs.python.org/\1>`__' ,
180+ content )
181+ # remove first 3 lines as they are the main heading
182+ lines = content .splitlines ()[3 :]
183+ self .state_machine .insert_input (lines , fname )
184+ return []
185+
186+
148187# Support for building "topic help" for pydoc
149188
150189pydoc_topic_labels = [
@@ -276,3 +315,4 @@ def setup(app):
276315 app .add_description_unit ('2to3fixer' , '2to3fixer' , '%s (2to3 fixer)' )
277316 app .add_directive_to_domain ('py' , 'decorator' , PyDecoratorFunction )
278317 app .add_directive_to_domain ('py' , 'decoratormethod' , PyDecoratorMethod )
318+ app .add_directive ('miscnews' , MiscNews )
0 commit comments