File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -56,8 +56,8 @@ def extract_excerpt(s: Snippet) -> str:
56
56
elif isinstance (s , Section ) and s .title is not None :
57
57
return '[' + s .title .text + ']'
58
58
elif isinstance (s , Code ):
59
- excerpt = s .desc .astext () if s .desc else s .caption or '' # FIXME
60
- return '`' + s .language + ':' + excerpt + '`'
59
+ excerpt = s .desc .astext () if isinstance ( s .desc , nodes . paragraph ) else s .desc
60
+ return '`' + s .lang + ':' + excerpt + '`'
61
61
return ''
62
62
63
63
@@ -66,10 +66,10 @@ def extract_keywords(s: Snippet) -> list[str]:
66
66
if isinstance (s , WithTitle ) and s .title is not None :
67
67
keywords .extend (extractor .extract (s .title .text , strip_stopwords = False ))
68
68
if isinstance (s , Code ):
69
- if s .desc :
69
+ if isinstance ( s .desc , nodes . paragraph ) :
70
70
keywords .extend (extractor .extract (s .desc .astext (), strip_stopwords = False ))
71
- if s . caption :
72
- keywords .extend (extractor .extract (s .caption , strip_stopwords = False ))
71
+ else :
72
+ keywords .extend (extractor .extract (s .desc , strip_stopwords = False ))
73
73
return keywords
74
74
75
75
Original file line number Diff line number Diff line change @@ -94,15 +94,14 @@ def __init__(self, node: nodes.Node) -> None:
94
94
self .text = node .astext ()
95
95
96
96
97
- class Code (Text ):
97
+ class Code (Snippet ):
98
98
#: Language of code block
99
99
lang : str
100
100
#: Description of code block, usually the text of preceding paragraph
101
101
desc : nodes .paragraph | str
102
102
103
103
def __init__ (self , node : nodes .literal_block ) -> None :
104
104
assert isinstance (node , nodes .literal_block )
105
- super ().__init__ (node )
106
105
107
106
self .lang = node ['language' ]
108
107
@@ -121,11 +120,14 @@ def __init__(self, node: nodes.literal_block) -> None:
121
120
# of the code block. This convention also applies to the code,
122
121
# code-block, sourcecode directive.
123
122
self .desc = para
123
+ print ('>>>>>>>>>>>>>>>>>>>>>>>>>>>>' )
124
+ super ().__init__ (para , node )
124
125
elif caption := node .get ('caption' ):
125
126
# Use caption as descritpion.
126
127
# In sphinx, code-block, sourcecode and code may have caption option.
127
128
# https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-code-block
128
129
self .desc = caption
130
+ super ().__init__ (node )
129
131
else :
130
132
raise ValueError ('Lack of description: preceding paragraph or caption' )
131
133
You can’t perform that action at this time.
0 commit comments