File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,21 @@ export const encodeBase64 = (text: string): string => {
2424} ;
2525
2626export const getTextSiyuanFromTextHTML = ( html : string ) => {
27+ const trimmedHtml = html . trimStart ( ) ;
28+ if ( trimmedHtml . startsWith ( "<html" ) ) {
29+ const htmlTagEnd = trimmedHtml . indexOf ( ">" ) ;
30+ if ( htmlTagEnd > 0 ) {
31+ const htmlTag = trimmedHtml . substring ( 0 , htmlTagEnd ) ;
32+ // 兼容 Microsoft Excel 应用,HTML 以包含 Excel 命名空间声明的 html 元素开头(备注:从 WPS 复制也有这个命名空间)
33+ if ( htmlTag . includes ( 'xmlns:x="urn:schemas-microsoft-com:office:excel"' ) ) {
34+ // 粘贴表格不需要解析 textSiyuan https://ld246.com/article/1763027417781/comment/1763032527460#comments
35+ return {
36+ textSiyuan : "" ,
37+ textHtml : html . replace ( / < ! - - d a t a - s i y u a n = ' [ ^ ' ] + ' - - > / g, "" )
38+ } ;
39+ }
40+ }
41+ }
2742 const siyuanMatch = html . match ( / < ! - - d a t a - s i y u a n = ' ( [ ^ ' ] + ) ' - - > / ) ;
2843 let textSiyuan = "" ;
2944 let textHtml = html ;
@@ -38,7 +53,7 @@ export const getTextSiyuanFromTextHTML = (html: string) => {
3853 textSiyuan = decoder . decode ( bytes ) ;
3954 }
4055 // 移除注释节点,保持原有的 text/html 内容
41- textHtml = html . replace ( / < ! - - d a t a - s i y u a n = ' [ ^ ' ] + ' - - > / , "" ) ;
56+ textHtml = html . replace ( / < ! - - d a t a - s i y u a n = ' [ ^ ' ] + ' - - > / g , "" ) ;
4257 } catch ( e ) {
4358 console . log ( "Failed to decode siyuan data from HTML comment:" , e ) ;
4459 }
You can’t perform that action at this time.
0 commit comments