2424 */
2525
2626import KernelApi from "../api/kernel-api"
27- import { dataDir } from "../Constants"
27+ import { dataDir } from "../Constants"
2828
2929/**
3030 * 文件是否存在
@@ -75,40 +75,40 @@ export const removeEmptyLines = (str: string): string => str.replace(/^#+\s*\n|\
7575 */
7676function convertPathToUnixStyle ( path ) {
7777 // 使用 replace() 函数将所有反斜杠替换为斜杠
78- return path . replace ( / \\ / g, '/' ) ;
78+ return path . replace ( / \\ / g, "/" )
7979}
8080
8181export function replaceImagePath ( mdText ) {
82- const regex = / ! \[ ( .* ?) \] \( ( [ ^ \s ] * ?) \) / g;
82+ const regex = / ! \[ ( .* ?) \] \( ( [ ^ \s ] * ?) \) / g
8383 return mdText . replace ( regex , ( match , p1 , p2 ) => {
84- let imagePath = p2 ;
84+ const imagePath = p2
8585
8686 if ( ! imagePath . startsWith ( dataDir ) ) {
87- return match ;
87+ return match
8888 }
8989
90- const relativePath = convertPathToUnixStyle (
91- imagePath . substring ( dataDir . length )
92- ) ;
90+ const relativePath = convertPathToUnixStyle ( imagePath . substring ( dataDir . length ) )
9391
94- return `` ;
95- } ) ;
92+ return ``
93+ } )
9694}
9795
9896// 将字符串中形如"xxx^yyy"的部分替换成"xxx"
9997export function removeFootnotes ( text ) {
100- const regex = / \^ \( \[ .* [ 0 - 9 ] .* \ ]\( \ # .* \ # .* \) \) / g; // 匹配格式为 ^[[数字]](#链接) 的脚注
101- return text . replace ( regex , '' ) ; // 使用空字符串替换匹配到的脚注
98+ const regex = / \^ \( \[ .* [ 0 - 9 ] .* ] \( # .* # .* \) \) / g // 匹配格式为 ^[[数字]](#链接) 的脚注
99+ return text . replace ( regex , "" ) // 使用空字符串替换匹配到的脚注
102100}
103101
104102// 删除目录中的内部链接
105103export function removeLinks ( text ) {
106104 const regex = / \[ ( [ ^ \] ] + ) ] \( ( [ ^ ) ] + ) \) / g
107- return text . replace ( regex , ( match , p1 , p2 ) => {
108- if ( p2 . includes ( './Text' ) ) {
105+ return text . replace ( regex , ( match , p1 , p2 ) => {
106+ console . log ( p2 )
107+ console . log ( typeof p2 )
108+ if ( p2 . includes ( "./Text" ) || p2 . includes ( "#" ) || p2 . includes ( "kindle:" ) ) {
109109 return p1
110110 } else {
111111 return match
112112 }
113113 } )
114- }
114+ }
0 commit comments