File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33< html >
44 < markdown-html
5- version ="1.20.10 "
5+ version ="1.20.11 "
66 author ="PJ568 "
77 repo ="https://github.com/PJ-568/markdown.html "
88 license ="CC BY-SA 4.0 International "
313313 return mdPath ;
314314 }
315315
316- // 判断链接是否为外链
317- function isExternalLink ( url ) {
318- if ( ! url || typeof url !== "string" ) return false ;
319-
316+ // 判断是否为其它协议(是 HTTP(S) 协议)
317+ function isProtocol ( url ) {
320318 //// 排除特殊协议
321319 const excludedProtocols = [
322320 "#" ,
323321 "javascript:" ,
324322 "mailto:" ,
325323 "tel:" ,
326324 "data:" ,
325+ "ftp:" ,
326+ "about:" ,
327327 ] ;
328328 if ( excludedProtocols . some ( ( proto ) => url . startsWith ( proto ) ) ) {
329329 return false ;
330+ } else {
331+ return true ;
332+ }
333+ }
334+
335+ // 判断链接是否为外链
336+ function isExternalLink ( url ) {
337+ if ( ! url || typeof url !== "string" ) return false ;
338+
339+ if ( ! isProtocol ( url ) ) {
340+ return false ;
330341 }
331342
332343 try {
615626 const mdLinks = linkDoc . querySelectorAll ( 'a[href]:not([href=""])' ) ;
616627 mdLinks . forEach ( ( link ) => {
617628 const href = link . getAttribute ( "href" ) ;
618- if ( ! isExternalLink ( href ) && isRelativePath ( href ) ) {
629+ //// 是相对路径
630+ if ( ! isExternalLink ( href ) && isRelativePath ( href ) && isProtocol ( href ) ) {
619631 var absolutePath = pValue
620632 ? getDirectory ( mdPath ) + href
621633 : getPath ( ) + href ;
You can’t perform that action at this time.
0 commit comments