Skip to content

Commit d0f8208

Browse files
committed
Fix handling of target elements in rst; fixes #1680.
All Docutils elements with "ids" attribute can serve as internal target. The "ids" attribute is indirectly specified, via the rST "refname" (in a preceding *empty* target `.. _refname:` or as "name" option in rST directives). This means: * Not all elements with ID have a matching <target> element. * If rST `<target>` elements refer to another element (via the "refid", "refuri", or "refname" attribute), they can be safely ignored. Add an optional argument "node" to `rst_in.NodeVisitor.open_moin_page_node()` Every ID of the passed Docutils node adds an empty `<span>` with the ID. (IDs on the "moinpage node" would be prefereable but may don't always reach the HTML and don't survive an rST -> rST round-trip.) Use an "attention" type admonition for the "generic admonition". Add/Update test cases. TODO: some IDs are still dropped.
1 parent 718db73 commit d0f8208

File tree

2 files changed

+88
-57
lines changed

2 files changed

+88
-57
lines changed

src/moin/converters/_tests/test_rst_in.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def setup_class(self):
3737
("**Text**", "<page><body><p><strong>Text</strong></p></body></page>"),
3838
("*Text*", "<page><body><p><emphasis>Text</emphasis></p></body></page>"),
3939
("``Text``", "<page><body><p><code>Text</code></p></body></page>"),
40+
("a _`Link`", '<page><body><p>a <span id="link">Link</span></p></body></page>'),
4041
(
4142
"`Text <javascript:alert('xss')>`_",
4243
'<page><body><p><admonition type="error">Text</admonition></p></body></page>',
@@ -107,12 +108,14 @@ def test_definition_list(self, input, output):
107108
'<page><body><xinclude:include xinclude:href="wiki.local:images/biohazard.png" /></body></page>',
108109
),
109110
(
110-
""".. image:: images/biohazard.png
111+
"""
112+
.. image:: images/biohazard.png
113+
:name: biohazard-logo
111114
:height: 100
112115
:width: 200
113116
:scale: 50
114117
:alt: alternate text""",
115-
'<page><body><xinclude:include xhtml:alt="alternate text" xhtml:height="50" xhtml:width="100" xinclude:href="wiki.local:images/biohazard.png" /></body></page>',
118+
'<page><body><span id="biohazard-logo" /><xinclude:include xhtml:alt="alternate text" xhtml:height="50" xhtml:width="100" xinclude:href="wiki.local:images/biohazard.png" /></body></page>',
116119
),
117120
(
118121
"abc |test| cba\n\n.. |test| image:: test.png",
@@ -215,8 +218,14 @@ def test_field_list(self, input, output):
215218
'<page><body><p>Abra</p><span id="example" /><p>Abra <a xlink:href="wiki.local:#example">example</a> arba</p></body></page>',
216219
),
217220
(
218-
"Abra example_ arba\n\n.. _example:\n\ntext",
219-
'<page><body><p>Abra <a xlink:href="wiki.local:#example">example</a> arba</p><span id="example" /><p>text</p></body></page>',
221+
"""
222+
Abra example_ arba
223+
224+
.. _example:
225+
.. _alias:
226+
227+
text""",
228+
'<page><body><p>Abra <a xlink:href="wiki.local:#example">example</a> arba</p><span id="alias" /><span id="example" /><p>text</p></body></page>',
220229
),
221230
(
222231
"A reference_ with no matching target links to a local Wiki item.",
@@ -226,7 +235,7 @@ def test_field_list(self, input, output):
226235
"`Whitespace is\nnormalized & Case is KEPT.`_",
227236
'<page><body><p><a xlink:href="wiki.local:Whitespace%20is%20normalized%20&amp;%20Case%20is%20KEPT.">Whitespace is\nnormalized &amp; Case is KEPT.</a></p></body></page>',
228237
),
229-
( # in rST, matching the reference text is case insensitive:
238+
( # in rST, reference-name matching is case insensitive:
230239
"Chapter 1\n===============\n\nA reference to `chapter 1`_.\n",
231240
'<page><body><h outline-level="1">Chapter 1</h><p>A reference to <a xlink:href="wiki.local:#Chapter_1">chapter 1</a>.</p></body></page>',
232241
),
@@ -303,7 +312,8 @@ def test_directive(self, input, output):
303312
"<page><body><table><table-body><table-row><table-cell><p><strong>A</strong></p></table-cell><table-cell><p><strong>B</strong></p></table-cell><table-cell><p><strong>C</strong></p></table-cell></table-row><table-row><table-cell><p>1</p></table-cell><table-cell><p>2</p></table-cell><table-cell><p>3</p></table-cell></table-row></table-body></table></body></page>",
304313
),
305314
(
306-
"""+--------------------+-------------------------------------+
315+
"""
316+
+--------------------+-------------------------------------+
307317
|cell spanning 2 rows|cell in the 2nd column |
308318
+ +-------------------------------------+
309319
| |cell in the 2nd column of the 2nd row|
@@ -329,7 +339,6 @@ def test_directive(self, input, output):
329339
+----------------------------------------------------------+
330340
|test |
331341
+----------------------------------------------------------+
332-
333342
""",
334343
'<page><body><table><table-header><table-row><table-cell><p>AAAAAAAAAAAAAAAAAA</p></table-cell><table-cell><p>BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB</p></table-cell></table-row></table-header><table-body><table-row><table-cell number-rows-spanned="2"><p>cell spanning 2 rows</p></table-cell><table-cell><p>cell in the 2nd column</p></table-cell></table-row><table-row><table-cell><p>cell in the 2nd column of the 2nd row</p></table-cell></table-row><table-row><table-cell number-columns-spanned="2"><p>test</p></table-cell></table-row><table-row><table-cell number-columns-spanned="2"><p>test</p></table-cell></table-row></table-body></table></body></page>',
335344
),
@@ -343,7 +352,16 @@ def test_table(self, input, output):
343352
(
344353
":Author: Test\n:Version: $Revision: 1.17 $\n:Copyright: c\n:Test: t",
345354
"<page><body><table><table-body><table-row><table-cell><strong>Author:</strong></table-cell><table-cell>Test</table-cell></table-row><table-row><table-cell><strong>Version:</strong></table-cell><table-cell>1.17</table-cell></table-row><table-row><table-cell><strong>Copyright:</strong></table-cell><table-cell>c</table-cell></table-row><table-row><table-cell><strong>Test:</strong></table-cell><table-cell><p>t</p></table-cell></table-row></table-body></table></body></page>",
346-
)
355+
),
356+
(
357+
"""
358+
.. note::
359+
:name: note-id
360+
361+
An admonition of type "note"
362+
""",
363+
'<page><body><span id="note-id" /><admonition type="note"><p>An admonition of type "note"</p></admonition></body></page>',
364+
),
347365
]
348366

349367
@pytest.mark.parametrize("input,output", data)

0 commit comments

Comments
 (0)