1
1
import codecs
2
+ from typing import Union , List , Tuple , Dict , Any
2
3
import os
3
4
import re
4
5
from glob import iglob
12
13
from mkdocs .config import config_options
13
14
from mkdocs .plugins import BasePlugin
14
15
from mkdocs_callouts .plugin import CalloutsPlugin
15
- from custom_attributes .plugin import read_custom , convert_hashtags , convert_text_attributes
16
+ from custom_attributes .plugin import convert_text_attributes
16
17
17
18
18
- def search_in_file (citation_part : str , contents : str ):
19
+ def search_in_file (citation_part : str , contents : str ) -> Union [ str , None ] :
19
20
"""
20
21
Search a part in the file
21
22
Args:
@@ -52,7 +53,7 @@ def search_in_file(citation_part: str, contents: str):
52
53
for i in data :
53
54
if citation_part in i .upper ():
54
55
return i .replace (citation_part , '' )
55
- return []
56
+ return None
56
57
57
58
58
59
def mini_ez_links (urlo , base , end , url_whitespace , url_case ):
@@ -104,7 +105,7 @@ def strip_comments(markdown):
104
105
markdown = re .sub (r'%%(.*)%%' , '' , markdown , flags = re .DOTALL )
105
106
return markdown
106
107
107
- def cite (md_link_path , link , soup , citation_part , config , callouts , custom_attr ):
108
+ def cite (md_link_path , link , soup , citation_part , config , callouts , custom_attr ) -> BeautifulSoup :
108
109
"""Append the content of the founded file to the original file.
109
110
110
111
Args:
@@ -191,7 +192,7 @@ def create_link(link):
191
192
else :
192
193
return link + '.md'
193
194
194
- def search_file_in_documentation (link : Path | str , config_dir : Path ):
195
+ def search_file_in_documentation (link : Union [ Path , str ] , config_dir : Path ) -> Union [ Path , int ] :
195
196
file_name = os .path .basename (link )
196
197
if not file_name .endswith ('.md' ):
197
198
file_name = file_name + '.md'
@@ -200,30 +201,25 @@ def search_file_in_documentation(link: Path|str, config_dir: Path):
200
201
return 0
201
202
202
203
203
-
204
-
205
204
class EmbedFile (BasePlugin ):
206
205
config_scheme = (
207
- ('callouts' , config_options .Type (str | bool , default = 'false' )),
206
+ ('callouts' , config_options .Type (bool , default = False )),
208
207
('custom-attributes' , config_options .Type (str , default = '' ))
209
208
)
210
209
211
210
def __init__ (self ):
212
211
self .enabled = True
213
212
self .total_time = 0
214
213
215
- def on_post_page (self , output_content , page , config ):
214
+ def on_post_page (self , output_content , page , config ) -> str :
216
215
soup = BeautifulSoup (output_content , 'html.parser' )
217
216
docs = Path (config ['docs_dir' ])
218
217
md_link_path = ''
219
218
callout = self .config ['callouts' ]
220
- if isinstance (callout , str ):
221
- callout = ast .literal_eval (callout .title ())
222
-
223
219
for link in soup .findAll (
224
220
'img' ,
225
221
src = lambda src : src is not None and 'favicon' not in src and not src .endswith (
226
- ('png' , 'jpg' , 'jpeg' , 'gif' , 'svg' )),
222
+ ('png' , 'jpg' , 'jpeg' , 'gif' , 'svg' )) and not 'www' in src and not 'http' in src ,
227
223
):
228
224
if len (link ['src' ]) > 0 :
229
225
0 commit comments