SF.net SVN: docutils:[10279 ] trunk/docutils
milde--- via Docutils-checkins <[email protected]> Tue, 06 Jan 2026 17:29:53 +0000
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 10279
http://sourceforge.net/p/docutils/code/10279
Author: milde
Date: 2026-01-06 17:29:53 +0000 (Tue, 06 Jan 2026)
Log Message:
-----------
Add internal source and line attributes to "rubric" and "table" nodes.
The rST parser now also adds internal source and line attributes to
`<rubric>` and `<table>` nodes.
TODO: line numbers for content of CSV Tables are wrong
(every cell starts with line nr 1).
Modified Paths:
--------------
trunk/docutils/HISTORY.rst
trunk/docutils/docutils/parsers/rst/directives/body.py
trunk/docutils/docutils/parsers/rst/directives/tables.py
trunk/docutils/docutils/parsers/rst/states.py
trunk/docutils/test/test_parsers/test_rst/test_source_line.py
Modified: trunk/docutils/HISTORY.rst
===================================================================
--- trunk/docutils/HISTORY.rst 2025-12-18 19:35:38 UTC (rev 10278)
+++ trunk/docutils/HISTORY.rst 2026-01-06 17:29:53 UTC (rev 10279)
@@ -17,9 +17,16 @@
Release 0.22.5b1.dev (unpublished)
==================================
-.
+* docutils/parsers/rst/directives/body.py
+ - Add source and line info to <rubric> elements.
+* docutils/parsers/rst/directives/tables.py,
+ docutils/parsers/rst/states.py
+
+ - Add source and line info to <table> elements.
+
+
Release 0.22.4 (2025-12-18)
===========================
Modified: trunk/docutils/docutils/parsers/rst/directives/body.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/body.py 2025-12-18 19:35:38 UTC (rev 10278)
+++ trunk/docutils/docutils/parsers/rst/directives/body.py 2026-01-06 17:29:53 UTC (rev 10279)
@@ -250,6 +250,8 @@
rubric_text = self.arguments[0]
textnodes, messages = self.state.inline_text(rubric_text, self.lineno)
rubric = nodes.rubric(rubric_text, '', *textnodes, **options)
+ (rubric.source,
+ rubric.line) = self.state_machine.get_source_and_line(self.lineno)
self.add_name(rubric)
return [rubric] + messages
Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py 2025-12-18 19:35:38 UTC (rev 10278)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2026-01-06 17:29:53 UTC (rev 10279)
@@ -150,6 +150,9 @@
table_node = node[0]
table_node['classes'] += self.options.get('class', [])
self.set_table_width(table_node)
+ # update line-nr to point to the start of the directive
+ table_node.line = self.state_machine.get_source_and_line(
+ self.lineno)[1]
if 'align' in self.options:
table_node['align'] = self.options.get('align')
if isinstance(self.widths, list):
@@ -316,6 +319,8 @@
self.add_name(table_node)
if title:
table_node.insert(0, title)
+ (table_node.source,
+ table_node.line) = self.state_machine.get_source_and_line(self.lineno)
return [table_node] + messages
def get_csv_data(self):
@@ -491,6 +496,8 @@
def build_table_from_list(self, table_data,
col_widths, header_rows, stub_columns):
table = nodes.table()
+ (table.source,
+ table.line) = self.state_machine.get_source_and_line(self.lineno)
if self.widths == 'auto':
table['classes'] += ['colwidths-auto']
elif self.widths: # explicitly set column widths
Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py 2025-12-18 19:35:38 UTC (rev 10278)
+++ trunk/docutils/docutils/parsers/rst/states.py 2026-01-06 17:29:53 UTC (rev 10279)
@@ -1911,6 +1911,8 @@
def build_table(self, tabledata, tableline, stub_columns=0, widths=None):
colwidths, headrows, bodyrows = tabledata
table = nodes.table()
+ (table.source,
+ table.line) = self.state_machine.get_source_and_line(tableline)
if widths == 'auto':
table['classes'] += ['colwidths-auto']
elif widths: # "grid" or list of integers
Modified: trunk/docutils/test/test_parsers/test_rst/test_source_line.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_source_line.py 2025-12-18 19:35:38 UTC (rev 10278)
+++ trunk/docutils/test/test_parsers/test_rst/test_source_line.py 2026-01-06 17:29:53 UTC (rev 10279)
@@ -296,7 +296,7 @@
container content at line 23
-Final paragraph at line 25
+.. rubric:: at line 25
""",
"""\
<document source="test data">
@@ -329,9 +329,102 @@
<container internal:line="21" internal:source="test data">
<paragraph internal:line="23" internal:source="test data">
container content at line 23
- <paragraph internal:line="25" internal:source="test data">
- Final paragraph at line 25
+ <rubric internal:line="25" internal:source="test data">
+ at line 25
"""],
+["""\
+==== ===
+line 2
+==== ===
+
+.. table:: test table
+
+ +--------+
+ | line 8 |
+ +--------+
+ | line 10|
+ +--------+
+""",
+"""\
+<document source="test data">
+ <table internal:line="1" internal:source="test data">
+ <tgroup cols="2">
+ <colspec colwidth="4">
+ <colspec colwidth="3">
+ <tbody>
+ <row>
+ <entry>
+ <paragraph internal:line="2" internal:source="test data">
+ line
+ <entry>
+ <paragraph internal:line="2" internal:source="test data">
+ 2
+ <table internal:line="5" internal:source="test data">
+ <title internal:line="5" internal:source="test data">
+ test table
+ <tgroup cols="1">
+ <colspec colwidth="8">
+ <tbody>
+ <row>
+ <entry>
+ <paragraph internal:line="8" internal:source="test data">
+ line 8
+ <row>
+ <entry>
+ <paragraph internal:line="10" internal:source="test data">
+ line 10
+"""],
+["""\
+.. list-table:: list table
+
+ * - line 3
+""",
+"""\
+<document source="test data">
+ <table internal:line="1" internal:source="test data">
+ <title internal:line="1" internal:source="test data">
+ list table
+ <tgroup cols="1">
+ <colspec colwidth="100">
+ <tbody>
+ <row>
+ <entry>
+ <paragraph internal:line="3" internal:source="test data">
+ line 3
+"""],
+["""\
+.. csv-table:: csv table
+
+ line, 3
+ ".. tip::
+ 5", 5
+""",
+# TODO: in CSV tables, every cell starts with line-number 1!
+"""\
+<document source="test data">
+ <table internal:line="1" internal:source="test data">
+ <title internal:line="1" internal:source="test data">
+ csv table
+ <tgroup cols="2">
+ <colspec colwidth="50">
+ <colspec colwidth="50">
+ <tbody>
+ <row>
+ <entry>
+ <paragraph internal:line="1" internal:source="test data">
+ line
+ <entry>
+ <paragraph internal:line="1" internal:source="test data">
+ 3
+ <row>
+ <entry>
+ <tip internal:line="1" internal:source="test data">
+ <paragraph internal:line="2" internal:source="test data">
+ 5
+ <entry>
+ <paragraph internal:line="1" internal:source="test data">
+ 5
+"""],
])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.