@@ -62,24 +62,27 @@ def mini_ez_links(urlo, base, end, url_whitespace, url_case):
62
62
if os .path .isfile (internal_link ):
63
63
internal_link = str (internal_link ).replace (base , '' )
64
64
else : # fallback to searching
65
- file_name = urlo [2 ].replace ('index' , '' )
66
- file_name = file_name .replace ('../' , '' )
67
- file_name = file_name .replace ('./' , '' )
65
+ if urlo [2 ].endswith ('.md' ):
66
+ internal_link = str (search_file_in_documentation (Path (urlo [2 ]).resolve (), Path (md_link_path ).parent ))
67
+ if not os .path .isfile (internal_link ):
68
+ file_name = urlo [2 ].replace ('index' , '' )
69
+ file_name = file_name .replace ('../' , '' )
70
+ file_name = file_name .replace ('./' , '' )
68
71
69
- all_docs = [
70
- re .sub (rf"(.*)({ url_blog_path } )?/docs/*" , '' , x .replace ('\\ ' , '/' )).replace (
71
- '.md' , ''
72
- )
73
- for x in iglob (str (base ) + os .sep + '**' , recursive = True )
74
- if os .path .isfile (x )
75
- ]
76
- file_found = [
77
- '/' + x for x in all_docs if os .path .basename (x ) == file_name or x == file_name
78
- ]
79
- if file_found :
80
- internal_link = file_found [0 ]
81
- else :
82
- return file_name
72
+ all_docs = [
73
+ re .sub (rf"(.*)({ url_blog_path } )?/docs/*" , '' , x .replace ('\\ ' , '/' )).replace (
74
+ '.md' , ''
75
+ )
76
+ for x in iglob (str (base ) + os .sep + '**' , recursive = True )
77
+ if os .path .isfile (x )
78
+ ]
79
+ file_found = [
80
+ '/' + x for x in all_docs if os .path .basename (x ) == file_name or x == file_name
81
+ ]
82
+ if file_found :
83
+ internal_link = file_found [0 ]
84
+ else :
85
+ return file_name
83
86
file_path = internal_link .replace (base , '' )
84
87
url = file_path .replace ('\\ ' , '/' ).replace ('.md' , '' )
85
88
url = url .replace ('//' , '/' )
@@ -122,6 +125,10 @@ def cite(md_link_path, link, soup, citation_part, config, callouts, custom_attr)
122
125
123
126
contents = frontmatter .loads (text ).content
124
127
quote = search_in_file (citation_part , contents )
128
+ tooltip_template = (
129
+ "<div class='not_found'>" +
130
+ str (link ['src' ].replace ('/' , '' )) + '</div>'
131
+ )
125
132
if len (quote ) > 0 :
126
133
if callouts :
127
134
quote = CalloutsPlugin ().on_page_markdown (quote , None , None , None )
@@ -167,32 +174,23 @@ def cite(md_link_path, link, soup, citation_part, config, callouts, custom_attr)
167
174
return soup
168
175
169
176
170
- def search_doc (md_link_path , all_docs ):
171
- """
172
- Search a file in the docs
173
- Args:
174
- md_link_path: Path to check
175
- all_docs: a list containing all path to the file
176
- Returns: Path to link found or 0 otherwise
177
-
178
- """
179
- if os .path .basename (md_link_path ) == '.md' :
180
- md_link_path = str (md_link_path ).replace (
181
- f'{ os .sep } .md' , f'{ os .sep } index.md' )
182
- else :
183
- md_link_path = str (md_link_path ).replace (f'{ os .sep } .md' , '' )
184
- file = [x for x in all_docs if Path (x ) == Path (md_link_path )]
185
- if len (file ) > 0 :
186
- return file [0 ]
187
- return 0
188
-
189
-
190
177
def create_link (link ):
191
178
if link .endswith ('/' ):
192
179
return link [:- 1 ] + '.md'
193
180
else :
194
181
return link + '.md'
195
182
183
+ def search_file_in_documentation (link : Path | str , config_dir : Path ):
184
+ file_name = os .path .basename (link )
185
+ if not file_name .endswith ('.md' ):
186
+ file_name = file_name + '.md'
187
+ for p in config_dir .rglob (f"*{ file_name } " ):
188
+ print (p )
189
+ return p
190
+ return 0
191
+
192
+
193
+
196
194
197
195
class EmbedFile (BasePlugin ):
198
196
config_scheme = (
@@ -215,14 +213,17 @@ def on_post_page(self, output_content, page, config):
215
213
for link in soup .findAll (
216
214
'img' ,
217
215
src = lambda src : src is not None and 'favicon' not in src and not src .endswith (
218
- ('png' , 'jpg' , 'jpeg' , 'gif' )),
216
+ ('png' , 'jpg' , 'jpeg' , 'gif' , 'svg' )),
219
217
):
220
218
if len (link ['src' ]) > 0 :
221
219
222
220
if link ['src' ][0 ] == '.' : # relative links
223
221
md_src = create_link (unquote (link ['src' ]))
224
222
md_link_path = Path (
225
223
os .path .dirname (page .file .abs_src_path ), md_src ).resolve ()
224
+ if not os .path .isfile (md_link_path ):
225
+ md_link_path = search_file_in_documentation (md_link_path , docs )
226
+
226
227
227
228
elif link ['src' ][0 ] == '/' :
228
229
md_src_path = create_link (unquote (link ['src' ]))
@@ -261,12 +262,7 @@ def on_post_page(self, output_content, page, config):
261
262
soup = cite (md_link_path , link , soup ,
262
263
citation_part , config , callout , self .config ['custom-attributes' ])
263
264
else :
264
- all_docs = [
265
- x
266
- for x in iglob (str (docs ) + os .sep + '**' , recursive = True )
267
- if x .endswith ('.md' )
268
- ]
269
- link_found = search_doc (md_link_path , all_docs )
265
+ link_found = search_file_in_documentation (md_link_path , docs )
270
266
if link_found != 0 :
271
267
soup = cite (link_found , link , soup ,
272
268
citation_part , config , callout , self .config ['custom-attributes' ])
0 commit comments