Skip to content

Commit ea1d838

Browse files
Nícolas F. R. A. PradoJonathan Corbet
authored andcommitted
docs: Enable usage of relative paths to docs on automarkup
Previously, a cross-reference to another document could only be created by writing the full path to the document starting from the Documentation/ directory. Extend this to also allow relative paths to be used. A relative path would be just the path, like ../filename.rst, while the absolute path still needs to start from Documentation, like Documentation/filename.rst. As part of this change, the .rst extension is now required for both types of paths, since not requiring it would cause the regex to be too generic. Suggested-by: Jonathan Corbet <[email protected]> Signed-off-by: Nícolas F. R. A. Prado <[email protected]> Link: https://lore.kernel.org/r/[email protected] [jc: Tweaked the regex to recognize .txt too] Signed-off-by: Jonathan Corbet <[email protected]>
1 parent 8fa4e93 commit ea1d838

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Documentation/sphinx/automarkup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# Detects a reference to a documentation page of the form Documentation/... with
5252
# an optional extension
5353
#
54-
RE_doc = re.compile(r'\bDocumentation(/[\w\-_/]+)(\.\w+)*')
54+
RE_doc = re.compile(r'(\bDocumentation/)?((\.\./)*[\w\-/]+)\.(rst|txt)')
5555

5656
RE_namespace = re.compile(r'^\s*..\s*c:namespace::\s*(\S+)\s*$')
5757

@@ -234,7 +234,10 @@ def markup_doc_ref(docname, app, match):
234234
#
235235
# Go through the dance of getting an xref out of the std domain
236236
#
237-
target = match.group(1)
237+
absolute = match.group(1)
238+
target = match.group(2)
239+
if absolute:
240+
target = "/" + target
238241
xref = None
239242
pxref = addnodes.pending_xref('', refdomain = 'std', reftype = 'doc',
240243
reftarget = target, modname = None,

0 commit comments

Comments
 (0)