Skip to content

Commit 293b9f5

Browse files
authored
Merge pull request #2019 from gmilde/rst-fixes
rST in: keep leading slash in wiki-local references
2 parents 8d1f354 + fb790fc commit 293b9f5

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/moin/converters/_tests/test_rst_in.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,17 @@ def test_field_list(self, input, output):
227227
text""",
228228
'<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>',
229229
),
230-
(
231-
"A reference_ with no matching target links to a local Wiki item.",
232-
'<page><body><p>A <a xlink:href="wiki.local:reference">reference</a> with no matching target links to a local Wiki item.</p></body></page>',
230+
( # A reference_ with no matching target links to a local Wiki item.
231+
"wiki references: `item`_, `namespace/item`_, `ns/item/subitem`_, `../sibling`_, `/subitem`_",
232+
'<page><body><p>wiki references: <a xlink:href="wiki.local:item">item</a>,'
233+
' <a xlink:href="wiki.local:namespace/item">namespace/item</a>,'
234+
' <a xlink:href="wiki.local:ns/item/subitem">ns/item/subitem</a>,'
235+
' <a xlink:href="wiki.local:../sibling">../sibling</a>,'
236+
' <a xlink:href="wiki.local:/subitem">/subitem</a></p></body></page>',
233237
),
234238
(
235-
"`Whitespace is\nnormalized & Case is KEPT.`_",
236-
'<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>',
239+
"`Whitespace is\nnormalized\xA0& CÄSE is Kept.`_",
240+
'<page><body><p><a xlink:href="wiki.local:Whitespace%20is%20normalized%20&amp;%20CÄSE%20is%20Kept.">Whitespace is\nnormalized\xA0&amp; CÄSE is Kept.</a></p></body></page>',
237241
),
238242
( # in rST, reference-name matching is case insensitive:
239243
"Chapter 1\n===============\n\nA reference to `chapter 1`_.\n",
@@ -357,7 +361,7 @@ def test_table(self, input, output):
357361
"""
358362
.. note::
359363
:name: note-id
360-
364+
361365
An admonition of type "note"
362366
""",
363367
'<page><body><span id="note-id" /><admonition type="note"><p>An admonition of type "note"</p></admonition></body></page>',

src/moin/converters/rst_in.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from moin.utils.iri import Iri
3232
from moin.utils.tree import html, moin_page, xlink, xinclude
3333
from moin.utils.mime import Type, type_moin_document
34-
from moin.wikiutil import anchor_name_from_text, normalize_pagename
34+
from moin.wikiutil import anchor_name_from_text
3535

3636
from . import default_registry
3737
from ._util import allowed_uri_scheme, decode_data, normalize_split_text
@@ -410,7 +410,8 @@ def visit_image(self, node):
410410
"left": "left",
411411
"center": "center",
412412
"right": "right",
413-
"top": "top", # rst parser creates error messages for top, bottom, and middle
413+
# only for inline images:
414+
"top": "top",
414415
"bottom": "bottom",
415416
"middle": "middle",
416417
}
@@ -825,28 +826,29 @@ def get_transforms(self):
825826
class WikiReferences(transforms.Transform):
826827
"""Resolve references without matching target as local wiki references.
827828
828-
Set the "refuri" attribute to refer to a local wiki item.
829-
The value is derived from the node's text content with
830-
`moin.wikiutil.normalize_pagename()`.
829+
Set the "refuri" attribute to the whitespace-normalized (but NOT case
830+
normalized) link text (`visit_reference()` adds the "wiki.local" scheme.)
831831
832-
Cf. https://docutils.sourceforge.io/docs/api/transforms.html#docinfo.
832+
Cf. https://docutils.sourceforge.io/docs/api/transforms.html.
833833
"""
834834

835835
default_priority = 775
836836
# Apply between `InternalTargets` (660) and `DanglingReferences` (850)
837837

838838
def apply(self) -> None:
839839
for node in self.document.findall(nodes.reference):
840-
# Skip resolved references, unresolvable references, and references with matching target:
840+
# Skip resolved references, unresolvable references,
841+
# and references with matching target:
841842
if node.resolved or "refname" not in node or self.document.nameids.get(node["refname"]):
842843
continue
843-
# Get the name from the link text (the "refname" attribute is lowercased).
844-
wikiname = normalize_pagename(node.astext(), None) # second arg is ignored
845-
# Skip references whose "refname" attribute differs from the wikiname (exept for case):
846-
if normalize_pagename(node["refname"], None) != wikiname.lower():
844+
# Get the refuri from the link text (keep case)
845+
refuri = nodes.whitespace_normalize_name(node.astext())
846+
# Skip references whose "refname" attribute differs from the
847+
# refuri by more than case:
848+
if node["refname"] != refuri.lower():
847849
continue
848-
# Resolve the reference:
849-
node["refuri"] = wikiname
850+
node["refuri"] = refuri
851+
# Mark as resolved:
850852
del node["refname"]
851853
node.resolved = True
852854

0 commit comments

Comments
 (0)