File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,12 @@ def role(
84
84
link_text = text
85
85
link = text
86
86
87
+ line_ref = ""
88
+ line_match = re .search (r"(.+?)(?:#(L\d+(?:-L\d+)?))?$" , link )
89
+ if line_match and line_match .group (2 ):
90
+ link = line_match .group (1 )
91
+ line_ref = f"?plain=1#{ line_match .group (2 )} "
92
+
87
93
module_match = re .search (r"(.+?):\s*(.+)" , link )
88
94
if module_match :
89
95
module = module_match .group (1 ).strip ()
@@ -124,7 +130,7 @@ def role(
124
130
f"{ link } not found in { config .link_roles_manifest_project } { trace } "
125
131
)
126
132
127
- url = f"{ baseurl } /{ format } /{ rev } /{ link } "
133
+ url = f"{ baseurl } /{ format } /{ rev } /{ link } { line_ref } "
128
134
node = nodes .reference (rawtext , link_text , refuri = url , ** options )
129
135
return [node ], []
130
136
Original file line number Diff line number Diff line change @@ -942,7 +942,26 @@ very file can be done using the :rst:role:`zephyr_file` role.
942
942
943
943
Check out :zephyr_file: `doc/contribute/documentation/guidelines.rst ` for more information.
944
944
945
- You may use the :rst:role: `zephyr_raw ` role instead if you want to reference the "raw" content.
945
+ You can reference specific lines or line ranges in a file by appending :samp: `#L{ line_number } ` or
946
+ :samp: `#L{ start_line } -L{ end_line } ` to the file path::
947
+
948
+ See :zephyr_file:`doc/contribute/documentation/guidelines.rst#L3` for the main heading of
949
+ this document.
950
+
951
+ Will render as:
952
+
953
+ See :zephyr_file: `doc/contribute/documentation/guidelines.rst#L3 ` for the main heading of
954
+ this document.
955
+
956
+ The role automatically verifies that the referenced file exists in the Zephyr tree and will
957
+ generate a warning during documentation build if the file is not found.
958
+
959
+ .. note ::
960
+
961
+ Use the line references sparingly as keeping them accurate over time can be challenging as the
962
+ content of the linked file is subject to change.
963
+
964
+ You may use the :rst:role: `zephyr_raw ` role instead if you want to reference the "raw" content.
946
965
947
966
.. rst :role :: zephyr_raw
948
967
@@ -964,6 +983,7 @@ You may use the :rst:role:`zephyr_raw` role instead if you want to reference the
964
983
965
984
Check out :module_file: `hal_stm32:CMakeLists.txt ` for more information.
966
985
986
+ Similar to :rst:role: `zephyr_file `, you can reference specific lines or line ranges in a file.
967
987
968
988
Cross-referencing GitHub issues and pull requests
969
989
=================================================
You can’t perform that action at this time.
0 commit comments