如何在TinyMCE中选择多个文本并实现带有跟踪更改的删除线功能?

How to select multiple text and implement strikethrough functionality with track changes in TinyMCE?

提问人:Pratick 提问时间:11/1/2023 更新时间:11/1/2023 访问量:6

问:

如果我在多个标签中选择文本(例如两个连续的 p 标签),那么所选内容会在新行中删除,我知道我将它们包装在 div 中,但还有什么其他方法可以正确地放置删除线功能。

 if (
                        editor.selection.getContent() !== "" ||
                        (editor.selection.getContent() !== "" && event.key === " ")
                      ) {

                        const selectedBlocks = editor.selection.getSelectedBlocks();
                        const selectedContent = editor.selection.getContent({ format: "text" });
                         // Iterate over selected blocks to handle them individually
                        
                        if (selectedBlocks.length > 1) {
                          selectedBlocks.forEach((block) => {
                            const selectedContent = editor.selection.getContent({ format: "html" });
                            console.log(block.nodeName)
                            // Wraping the selected content within its original block tag

                            const modifiedContent = `<div class="del-input" id="deleted-${track_id}><${block.nodeName.toLowerCase()}">${selectedContent}</${block.nodeName.toLowerCase()}></div>`;
                            console.log(modifiedContent)
                            
                            editor.insertContent(modifiedContent);
  
                          });
                        }
                         
                        
                        else {
                          const selectedContent = editor.selection.getContent({ format: "html" });
                          editor.insertContent(`<span class="del-input" id=deleted-${track_id}>${selectedContent}</span>`);
                          
                        }

我尝试了多种方法,但没有帮助。

打字稿 tinymce react-typescript tinymce-5

评论


答: 暂无答案