|
From: <mi...@us...> - 2026-01-07 07:52:11
|
Revision: 10283
http://sourceforge.net/p/docutils/code/10283
Author: milde
Date: 2026-01-07 07:52:09 +0000 (Wed, 07 Jan 2026)
Log Message:
-----------
More relaxed "include" directive.
The options :start-after: and :end-before: may now also be used
with an empty value field (standing for an empty line).
The severity of reported errors is lowered from 4: SEVERE to 3: ERROR.
Modified Paths:
--------------
trunk/docutils/HISTORY.rst
trunk/docutils/RELEASE-NOTES.rst
trunk/docutils/docs/ref/rst/directives.rst
trunk/docutils/docutils/parsers/rst/directives/misc.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py
Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst 2026-01-07 07:51:48 UTC (rev 10282)
+++ trunk/docutils/HISTORY.rst 2026-01-07 07:52:09 UTC (rev 10283)
@@ -21,6 +21,12 @@
- Add source and line info to <rubric> elements.
+* docutils/parsers/rst/directives/misc.py,
+
+ - "Include" options :start-after: and :end-before: may now also
+ be used without value (standing for an empty line).
+ - The severity of "include" problems is lowered to 3: ERROR.
+
* docutils/parsers/rst/directives/tables.py,
- Add source and line info to <table> elements.
Modified: trunk/docutils/RELEASE-NOTES.rst
===================================================================
--- trunk/docutils/RELEASE-NOTES.rst 2026-01-07 07:51:48 UTC (rev 10282)
+++ trunk/docutils/RELEASE-NOTES.rst 2026-01-07 07:52:09 UTC (rev 10283)
@@ -89,12 +89,6 @@
* The highlight language of a custom role based on "code" will default to
the role's name in Docutils 0.23.
-* Problems with the "include" directive will be reported as ERROR instead
- of SEVERE in Docutils 0.23.
-
-* The options :start-after: and :end-before: of the "include" directive
- will support empty values (standing for an empty line) in Docutils 0.23.
-
* The "rst" parser will warn if a `"figure"`_ directive is missing both
caption and legend in Docutils 1.0.
@@ -299,6 +293,11 @@
Release 0.23b.dev (unpublished)
===============================
+rST parser:
+ - Problems with the "include" directive are reported as ERROR, not SEVERE.
+ - The "include" directive options :start-after: and :end-before: may now
+ also be used without value (standing for an empty line).
+
Removed objects
`parsers.rst.directives.tables.CSVTable.check_requirements()`
not required with Python 3
Modified: trunk/docutils/docs/ref/rst/directives.rst
===================================================================
--- trunk/docutils/docs/ref/rst/directives.rst 2026-01-07 07:51:48 UTC (rev 10282)
+++ trunk/docutils/docs/ref/rst/directives.rst 2026-01-07 07:52:09 UTC (rev 10283)
@@ -1658,6 +1658,7 @@
Only the content before the first occurrence of the specified *text*
in the external data file (but after any ``start-after`` text)
will be included.
+ If no *text* is given, include content up to the next empty line.
``end-line`` : integer_
Only the content up to (but excluding) this line will be included.
@@ -1687,6 +1688,7 @@
``start-after`` : text_
Only the content after the first occurrence of the specified *text*
in the external data file will be included.
+ If no *text* is given, include content after the next empty line.
``start-line`` : integer_
Only the content starting from this line will be included.
Modified: trunk/docutils/docutils/parsers/rst/directives/misc.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/misc.py 2026-01-07 07:51:48 UTC (rev 10282)
+++ trunk/docutils/docutils/parsers/rst/directives/misc.py 2026-01-07 07:52:09 UTC (rev 10283)
@@ -63,8 +63,8 @@
'tab-width': int,
'start-line': int,
'end-line': int,
- 'start-after': directives.unchanged_required,
- 'end-before': directives.unchanged_required,
+ 'start-after': directives.unchanged,
+ 'end-before': directives.unchanged,
# ignored except for 'literal' or 'code':
'number-lines': directives.value_or((None,), int),
'class': directives.class_option,
@@ -84,8 +84,8 @@
self.tab_width = self.options.get('tab-width', settings.tab_width)
self.clip_options = (self.options.get('start-line', None),
self.options.get('end-line', None),
- self.options.get('start-after', ''),
- self.options.get('end-before', ''))
+ self.options.get('start-after', None),
+ self.options.get('end-before', None))
path = directives.path(self.arguments[0])
if path.startswith('<') and path.endswith('>'):
path = '/' + path[1:-1]
@@ -120,19 +120,19 @@
encoding=encoding,
error_handler=error_handler)
except UnicodeEncodeError:
- raise self.severe(f'Problems with "{self.name}" directive path:\n'
- f'Cannot encode input file path "{path}" '
- '(wrong locale?).')
+ raise self.error(f'Problems with "{self.name}" directive path:\n'
+ f'Cannot encode input file path "{path}" '
+ '(wrong locale?).')
except OSError as error:
- raise self.severe(f'Problems with "{self.name}" directive path:\n'
- f'{io.error_string(error)}.')
+ raise self.error(f'Problems with "{self.name}" directive path:\n'
+ f'{io.error_string(error)}.')
else:
self.settings.record_dependencies.add(path)
try:
text = include_file.read()
except UnicodeError as error:
- raise self.severe(f'Problem with "{self.name}" directive:\n'
- + io.error_string(error))
+ raise self.error(f'Problem with "{self.name}" directive:\n'
+ + io.error_string(error))
# Clip to-be-included content
startline, endline, starttext, endtext = self.clip_options
if startline or (endline is not None):
@@ -140,19 +140,29 @@
text = '\n'.join(lines[startline:endline])
# start-after/end-before: no restrictions on newlines in match-text,
# and no restrictions on matching inside lines vs. line boundaries
+ # exception: emtpy string matches an empty line
+ if starttext == "":
+ # skip content before an empty line
+ starttext = '\n\n'
if starttext:
# skip content in text before *and incl.* a matching text
after_index = text.find(starttext)
if after_index < 0:
- raise self.severe('Problem with "start-after" option of '
- f'"{self.name}" directive:\nText not found.')
- text = text[after_index + len(starttext):]
- if endtext:
+ raise self.error('Problem with "start-after" option of '
+ f'"{self.name}" directive:\nText not found.')
+ else:
+ text = text[after_index + len(starttext):]
+ if endtext == "":
+ # skip content after an empty line
+ before_index = text.find('\n\n')
+ if before_index > 0:
+ text = text[:before_index+1]
+ elif endtext:
# skip content in text after *and incl.* a matching text
before_index = text.find(endtext)
if before_index < 0:
- raise self.severe('Problem with "end-before" option of '
- f'"{self.name}" directive:\nText not found.')
+ raise self.error('Problem with "end-before" option of '
+ f'"{self.name}" directive:\nText not found.')
text = text[:before_index]
return text
@@ -253,7 +263,7 @@
if not include_log: # new document, initialize with document source
current_source = utils.relative_path(
None, self.state.document.current_source)
- include_log.append((current_source, (None, None, '', '')))
+ include_log.append((current_source, (None, None, None, None)))
if (source, self.clip_options) in include_log:
source_chain = (pth for (pth, opt) in reversed(include_log))
inclusion_chain = '\n> '.join((source, *source_chain))
@@ -315,8 +325,8 @@
encoding=encoding,
error_handler=error_handler)
except OSError as error:
- raise self.severe(f'Problems with "{self.name}" directive '
- f'path:\n{io.error_string(error)}.')
+ raise self.error(f'Problems with "{self.name}" directive '
+ f'path:\n{io.error_string(error)}.')
else:
# TODO: currently, raw input files are recorded as
# dependencies even if not used for the chosen output format.
@@ -324,8 +334,8 @@
try:
text = raw_file.read()
except UnicodeError as error:
- raise self.severe(f'Problem with "{self.name}" directive:\n'
- + io.error_string(error))
+ raise self.error(f'Problem with "{self.name}" directive:\n'
+ + io.error_string(error))
attributes['source'] = path
elif 'url' in self.options:
source = self.options['url']
@@ -332,9 +342,9 @@
try:
raw_text = urlopen(source).read()
except (URLError, OSError) as error:
- raise self.severe(f'Problems with "{self.name}" directive URL '
- f'"{self.options["url"]}":\n'
- f'{io.error_string(error)}.')
+ raise self.error(f'Problems with "{self.name}" directive URL '
+ f'"{self.options["url"]}":\n'
+ f'{io.error_string(error)}.')
raw_file = io.StringInput(source=raw_text, source_path=source,
encoding=encoding,
error_handler=error_handler)
@@ -341,8 +351,8 @@
try:
text = raw_file.read()
except UnicodeError as error:
- raise self.severe(f'Problem with "{self.name}" directive:\n'
- + io.error_string(error))
+ raise self.error(f'Problem with "{self.name}" directive:\n'
+ + io.error_string(error))
attributes['source'] = source
else:
# This will always fail because there is no content.
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2026-01-07 07:51:48 UTC (rev 10282)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2026-01-07 07:52:09 UTC (rev 10283)
@@ -315,7 +315,7 @@
<section ids="include-test" names="include\\ test">
<title>
Include Test
- <system_message level="4" line="4" source="test data" type="SEVERE">
+ <system_message level="3" line="4" source="test data" type="ERROR">
<paragraph>
Problems with "include" directive path:
InputError: [Errno 2] No such file or directory: 'nonexistent.rst'.
@@ -573,7 +573,7 @@
<document source="test data">
<paragraph>
Include file is UTF-16-encoded, and is not valid ASCII.
- <system_message level="4" line="3" source="test data" type="SEVERE">
+ <system_message level="3" line="3" source="test data" type="ERROR">
<paragraph>
Problem with "include" directive:
{utf_16_error_str}
@@ -590,7 +590,7 @@
<document source="test data">
<paragraph>
cyrillic filename:
- <system_message level="4" line="3" source="test data" type="SEVERE">
+ <system_message level="3" line="3" source="test data" type="ERROR">
<paragraph>
Problems with "include" directive path:
{errstr_8bit_path}
@@ -634,7 +634,7 @@
<system_message backrefs="hi-1" level="1" line="10" source="{include10}" type="INFO">
<paragraph>
Duplicate implicit target name: "hi".
- <system_message level="4" line="12" source="{include10}" type="SEVERE">
+ <system_message level="3" line="12" source="{include10}" type="ERROR">
<paragraph>
Problems with "include" directive path:
InputError: [Errno 2] No such file or directory: '{nonexistent}'.
@@ -916,7 +916,7 @@
<document source="test data">
<paragraph>
Nonexistent standard include data file:
- <system_message level="4" line="3" source="test data" type="SEVERE">
+ <system_message level="3" line="3" source="test data" type="ERROR">
<paragraph>
Problems with "include" directive path:
InputError: [Errno 2] No such file or directory: '{nonexistent}'.
@@ -1018,7 +1018,7 @@
<document source="test data">
<paragraph>
Include start-after/end-before multi-line test.
- <system_message level="4" line="3" source="test data" type="SEVERE">
+ <system_message level="3" line="3" source="test data" type="ERROR">
<paragraph>
Problem with "end-before" option of "include" directive:
Text not found.
@@ -1044,7 +1044,7 @@
<document source="test data">
<paragraph>
Error handling test; "end-before" error handling tested in previous test.
- <system_message level="4" line="3" source="test data" type="SEVERE">
+ <system_message level="3" line="3" source="test data" type="ERROR">
<paragraph>
Problem with "start-after" option of "include" directive:
Text not found.
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py 2026-01-07 07:51:48 UTC (rev 10282)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py 2026-01-07 07:52:09 UTC (rev 10283)
@@ -136,7 +136,7 @@
<document source="test data">
<paragraph>
Raw input file is UTF-16-encoded, and is not valid ASCII.
- <system_message level="4" line="3" source="test data" type="SEVERE">
+ <system_message level="3" line="3" source="test data" type="ERROR">
<paragraph>
Problem with "raw" directive:
{utf_16_error_str}
@@ -173,7 +173,7 @@
""",
"""\
<document source="test data">
- <system_message level="4" line="1" source="test data" type="SEVERE">
+ <system_message level="3" line="1" source="test data" type="ERROR">
<paragraph>
Problems with "raw" directive path:
InputError: [Errno 2] No such file or directory: 'non-existent.file'.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|