File tree Expand file tree Collapse file tree 6 files changed +38
-15
lines changed
apps/chrome-extension/src Expand file tree Collapse file tree 6 files changed +38
-15
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @dolphin/lark ' : patch
3+ ---
4+
5+ fix: text highlight missing in invalid children of table cell
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ export class UniqueFileName {
7575
7676export const transformInvalidTablesToHtml = (
7777 invalidTables : InvalidTable [ ] ,
78+ options : { allowDangerousHtml : boolean } = { allowDangerousHtml : false } ,
7879) : void => {
7980 invalidTables . forEach ( invalidTable => {
8081 const invalidTableIndex = invalidTable . parent ?. children . findIndex (
@@ -84,17 +85,25 @@ export const transformInvalidTablesToHtml = (
8485 invalidTable . parent ?. children . splice ( invalidTableIndex , 1 , {
8586 type : 'html' ,
8687 value : toHtml (
87- toHast ( {
88- ...invalidTable . inner ,
89- // @ts -expect-error non-phrasing content can be supported.
90- children : invalidTable . inner . children . map ( row => ( {
91- ...row ,
92- children : row . children . map ( cell => ( {
93- ...cell ,
94- children : cell . data ?. invalidChildren ?? cell . children ,
88+ toHast (
89+ {
90+ ...invalidTable . inner ,
91+ // @ts -expect-error non-phrasing content can be supported.
92+ children : invalidTable . inner . children . map ( row => ( {
93+ ...row ,
94+ children : row . children . map ( cell => ( {
95+ ...cell ,
96+ children : cell . data ?. invalidChildren ?? cell . children ,
97+ } ) ) ,
9598 } ) ) ,
96- } ) ) ,
97- } ) ,
99+ } ,
100+ {
101+ allowDangerousHtml : options . allowDangerousHtml ,
102+ } ,
103+ ) ,
104+ {
105+ allowDangerousHtml : options . allowDangerousHtml ,
106+ } ,
98107 ) ,
99108 } )
100109 }
Original file line number Diff line number Diff line change @@ -92,7 +92,9 @@ const main = async () => {
9292 settings [ SettingKey . TableWithNonPhrasingContent ] ===
9393 TableWithNonPhrasingContent . ToHTML
9494 ) {
95- transformInvalidTablesToHtml ( invalidTables )
95+ transformInvalidTablesToHtml ( invalidTables , {
96+ allowDangerousHtml : true ,
97+ } )
9698 }
9799
98100 const markdown = Docx . stringify ( root )
Original file line number Diff line number Diff line change @@ -526,7 +526,9 @@ const main = async (options: { signal?: AbortSignal } = {}) => {
526526 settings [ SettingKey . TableWithNonPhrasingContent ] ===
527527 TableWithNonPhrasingContent . ToHTML
528528 ) {
529- transformInvalidTablesToHtml ( invalidTables )
529+ transformInvalidTablesToHtml ( invalidTables , {
530+ allowDangerousHtml : true ,
531+ } )
530532 }
531533
532534 const markdown = Docx . stringify ( root )
@@ -588,7 +590,9 @@ const main = async (options: { signal?: AbortSignal } = {}) => {
588590 settings [ SettingKey . TableWithNonPhrasingContent ] ===
589591 TableWithNonPhrasingContent . ToHTML
590592 ) {
591- transformInvalidTablesToHtml ( invalidTables )
593+ transformInvalidTablesToHtml ( invalidTables , {
594+ allowDangerousHtml : true ,
595+ } )
592596 }
593597
594598 const markdown = Docx . stringify ( root )
Original file line number Diff line number Diff line change @@ -94,7 +94,9 @@ const main = async () => {
9494 settings [ SettingKey . TableWithNonPhrasingContent ] ===
9595 TableWithNonPhrasingContent . ToHTML
9696 ) {
97- transformInvalidTablesToHtml ( invalidTables )
97+ transformInvalidTablesToHtml ( invalidTables , {
98+ allowDangerousHtml : true ,
99+ } )
98100 }
99101
100102 const markdown = Docx . stringify ( root )
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import {
2424} from './utils/mdast'
2525import { resolveFileDownloadUrl } from './file'
2626import isString from 'lodash-es/isString'
27+ import escape from 'lodash-es/escape'
2728
2829declare module 'mdast' {
2930 interface ImageData {
@@ -720,7 +721,7 @@ export const transformOperationsToPhrasingContents = (
720721 if ( options . highlight && ( textHighlight || textHighlightBackground ) ) {
721722 return {
722723 type : 'html' ,
723- value : `<span style="color: ${ textHighlight ?? 'inherit' } ; background-color: ${ textHighlightBackground ?? 'inherit' } ">${ insert } </span>` ,
724+ value : `<span style="color: ${ textHighlight ?? 'inherit' } ; background-color: ${ textHighlightBackground ?? 'inherit' } ">${ escape ( insert ) } </span>` ,
724725 }
725726 }
726727
You can’t perform that action at this time.
0 commit comments