@@ -106,7 +106,7 @@ def strip_comments(markdown):
106
106
markdown = re .sub (r'%%(.*)%%' , '' , markdown , flags = re .DOTALL )
107
107
return markdown
108
108
109
- def cite (md_link_path , link , soup , citation_part , config , callouts , custom_attr ) -> BeautifulSoup :
109
+ def cite (md_link_path , link , soup , citation_part , config , callouts , custom_attr , msg ) -> BeautifulSoup :
110
110
"""Append the content of the founded file to the original file.
111
111
112
112
Args:
@@ -138,8 +138,11 @@ def cite(md_link_path, link, soup, citation_part, config, callouts, custom_attr)
138
138
contents = frontmatter .loads (text ).content
139
139
quote = search_in_file (citation_part , contents )
140
140
tooltip_template = (
141
- "<div class='not_found'>" +
142
- str (unquote (link ['alt' ].replace ('/' , '' ))) + '</div>'
141
+ "<div class='citation'> <a href='"
142
+ + str (link ['src' ])
143
+ + "' class='link_citation'><i class='fas fa-link'></i> </a>"
144
+ + str (link ['alt' ]) + ' not exists.'
145
+ + '</div>'
143
146
)
144
147
if len (quote ) > 0 :
145
148
if callouts :
@@ -178,20 +181,19 @@ def cite(md_link_path, link, soup, citation_part, config, callouts, custom_attr)
178
181
)
179
182
+ '</div>'
180
183
)
184
+ new_soup = str (soup ).replace (str (link ), str (tooltip_template ))
185
+ soup = BeautifulSoup (new_soup , 'html.parser' )
186
+ return soup
181
187
else :
182
188
print ('**** Citation not found **** : ' + unquote (citation_part ), 'for : ' , str (md_link_path ), ' with link: ' + str (link ) + ' and new_uri: ' + str (new_uri ), ' and quote: ' + str (quote ))
183
- tooltip_template = (
184
- "<div class='not_found'>" +
185
- str (unquote (link ['alt' ].replace ('/' , '' ))) + '</div>'
186
- )
187
- new_soup = str (soup ).replace (str (link ), str (tooltip_template ))
188
- soup = BeautifulSoup (new_soup , 'html.parser' )
189
- return soup
189
+ return tooltip_not_found (link , soup , msg )
190
+
190
191
191
- def tooltip_not_found (link , soup ) -> BeautifulSoup :
192
+ def tooltip_not_found (link , soup , msg ) -> BeautifulSoup :
192
193
tooltip_template = (
193
- "<div class='not_found'>" +
194
- str (unquote (link ['alt' ].replace ('/' , '' ))) + '</div>'
194
+ "<div class='citation'> <a class='link_citation'><i class='fas fa-link'></i> </a>"
195
+ + '<p style="text-align: center; display: block"><i class="not_found">' + str (link ['alt' ]) + f'</i> { msg } </p>'
196
+ + '</div>'
195
197
)
196
198
new_soup = str (soup ).replace (str (link ), str (tooltip_template ))
197
199
soup = BeautifulSoup (new_soup , 'html.parser' )
@@ -215,7 +217,8 @@ def search_file_in_documentation(link: Union[Path,str], config_dir: Path) -> Uni
215
217
class EmbedFile (BasePlugin ):
216
218
config_scheme = (
217
219
('callouts' , config_options .Type (bool , default = False )),
218
- ('custom-attributes' , config_options .Type (str , default = '' ))
220
+ ('custom-attributes' , config_options .Type (str , default = '' )),
221
+ ('language_message' , config_options .Type (str , default = 'file not exists' )),
219
222
)
220
223
221
224
def __init__ (self ):
@@ -227,6 +230,7 @@ def on_post_page(self, output_content, page, config) -> str:
227
230
docs = Path (config ['docs_dir' ])
228
231
md_link_path = ''
229
232
callout = self .config ['callouts' ]
233
+ language_message = self .config ['language_message' ]
230
234
for link in soup .findAll (
231
235
'img' ,
232
236
src = lambda src : src is not None
@@ -270,7 +274,7 @@ def on_post_page(self, output_content, page, config) -> str:
270
274
)
271
275
md_link_path = Path (unquote (md_link_path )).resolve ()
272
276
if (md_link_path == 0 ):
273
- soup = tooltip_not_found (link , soup )
277
+ soup = tooltip_not_found (link , soup , language_message )
274
278
if (md_link_path != '' or md_link_path == 0 ) and len (link ['src' ]) > 0 :
275
279
if '#' in link .get ('alt' , '' ):
276
280
# heading
@@ -284,10 +288,10 @@ def on_post_page(self, output_content, page, config) -> str:
284
288
285
289
if os .path .isfile (md_link_path ):
286
290
soup = cite (md_link_path , link , soup ,
287
- citation_part , config , callout , self .config ['custom-attributes' ])
291
+ citation_part , config , callout , self .config ['custom-attributes' ], language_message )
288
292
else :
289
293
link_found = search_file_in_documentation (md_link_path , docs )
290
294
if link_found != 0 :
291
295
soup = cite (link_found , link , soup ,
292
- citation_part , config , callout , self .config ['custom-attributes' ])
296
+ citation_part , config , callout , self .config ['custom-attributes' ], language_message )
293
297
return str (soup )
0 commit comments