File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 7
7
"""
8
8
9
9
from __future__ import annotations
10
- from typing import List , Tuple , Optional
10
+ from typing import List , Tuple , Optional , TYPE_CHECKING
11
11
import itertools
12
12
13
13
from docutils import nodes
14
14
15
+ if TYPE_CHECKING :
16
+ from sphinx .environment import BuildEnvironment
17
+
15
18
__version__ = '1.1.1'
16
19
17
20
@@ -22,6 +25,10 @@ class Snippet(object):
22
25
:param nodes: Document nodes that make up this snippet
23
26
"""
24
27
28
+ #: docname where the snippet is located, can be referenced by
29
+ # :rst:role:`doc`.
30
+ docname : str
31
+
25
32
#: Source file path of snippet
26
33
file : str
27
34
@@ -41,7 +48,9 @@ class Snippet(object):
41
48
def __init__ (self , * nodes : nodes .Node ) -> None :
42
49
assert len (nodes ) != 0
43
50
51
+ env : BuildEnvironment = nodes [0 ].document .settings .env
44
52
self .file = nodes [0 ].source
53
+ self .docname = env .path2doc (self .file )
45
54
46
55
lineno = [float ('inf' ), - float ('inf' )]
47
56
for node in nodes :
Original file line number Diff line number Diff line change @@ -100,6 +100,9 @@ def main(argv: List[str] = sys.argv[1:]):
100
100
formatter_class = HelpFormatter ,
101
101
help = 'get information of snippet by index ID' ,
102
102
)
103
+ getparser .add_argument (
104
+ '--docname' , '-d' , action = 'store_true' , help = 'get docname of snippet'
105
+ )
103
106
getparser .add_argument (
104
107
'--file' , '-f' , action = 'store_true' , help = 'get source file path of snippet'
105
108
)
@@ -216,6 +219,8 @@ def _on_command_get(args: argparse.Namespace):
216
219
sys .exit (1 )
217
220
if args .text :
218
221
print ('\n ' .join (item .snippet .rst ))
222
+ if args .docname :
223
+ print (item .snippet .docname )
219
224
if args .file :
220
225
print (item .snippet .file )
221
226
if args .url :
You can’t perform that action at this time.
0 commit comments