第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何獲取ckeditor 5中選定文本的HTML代碼?

如何獲取ckeditor 5中選定文本的HTML代碼?

皈依舞 2023-07-20 15:34:08
如何在 ckeditor 5 中獲取所選文本的 HTML?在 ckeditor 4 中有 getHTML() 方法。第五版中的模擬是什么?
查看完整描述

3 回答

?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊

您可以使用DataController#stringify使用getSelectedContent將文檔片段中的 HTML 字符串化

import getSelectedContent from "@ckeditor/ckeditor5-engine/src/model/utils/getselectedcontent";


export default class CK5Utils{

? ? ? ? static getSelectedHtml(ed) {

? ? ? ? ? ? const {model, data, model:{document:{selection}}} = ed;

? ? ? ? ? ? const range = selection.getFirstRange();

? ? ? ? ? ? if (range.end.isEqual(range.start)) {

? ? ? ? ? ? ? return '';

? ? ? ? ? ? }

? ? ? ? ? ? const selected = getSelectedContent(model, selection);

? ? ? ? ? ? return data.stringify(selected);

? ? ? ? }

}


查看完整回答
反對(duì) 回復(fù) 2023-07-20
?
飲歌長嘯

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊

按照 Alexandros Kyriakos 的建議,使用DataController#stringify和getSelectedContent,也可以這樣做:

let?sHtmlSelection?=?this.editor.data.stringify(this.editor.model.getSelectedContent(this.editor.model.document.selection));



查看完整回答
反對(duì) 回復(fù) 2023-07-20
?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

您可以抓取某個(gè)范圍內(nèi)的選定文本,但要獲取 HTML,就有點(diǎn)棘手了。

我能夠抓住 thenameparent通過switch語句運(yùn)行該值。

注意:下面的代碼已從此處改編:“在 CKEDITOR 5 中獲取突出顯示/選定的文本”

const resultArea = document.querySelector('.selected');


let globalEditor;


ClassicEditor

? .create(document.querySelector('#editor'))

? .then(editor => globalEditor = editor)

? .catch(error => console.error(error));


const formatNode = (node) => {

? switch (node.parent.name) {

? ? case 'heading1'? : return `<h1>${node.data}</h1>`;

? ? case 'heading2'? : return `<h2>${node.data}</h2>`;

? ? case 'heading3'? : return `<h3>${node.data}</h3>`;

? ? case 'paragraph' : return `<p>${node.data}</p>`;

? ? default? ? ? ? ? : return '';

? }

};


const getSelectedHTML = (editor) =>

? [...editor.model.document.selection.getFirstRange().getItems()]

? ? .filter(node => node.data)

? ? .map(formatNode)

? ? .join('\n');


document.querySelector('.btn').addEventListener('click', e => {

? resultArea.value = getSelectedHTML(globalEditor);

});

<!-- https://cdn.ckeditor.com/#ckeditor5 -->

<script src="https://cdn.ckeditor.com/ckeditor5/23.1.0/classic/ckeditor.js"></script>

<div id="editor">

? <h1>This is a heading</h1>

? <p>This is some sample content.</p>

</div>

<p>

? <button class="btn">Get Selected HTML</button>

</p>

<textarea class="selected" rows="8" cols="72"></textarea>


查看完整回答
反對(duì) 回復(fù) 2023-07-20
  • 3 回答
  • 0 關(guān)注
  • 373 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)