MCPcopy
hub / github.com/codex-team/editor.js / processText

Method processText

src/components/modules/paste.ts:233–261  ·  view source on GitHub ↗

* Process pasted text and divide them into Blocks * * @param {string} data - text to process. Can be HTML or plain. * @param {boolean} isHTML - if passed string is HTML, this parameter should be true

(data: string, isHTML = false)

Source from the content-addressed store, hash-verified

231 * @param {boolean} isHTML - if passed string is HTML, this parameter should be true
232 */
233 public async processText(data: string, isHTML = false): Promise<void> {
234 const { Caret, BlockManager } = this.Editor;
235 const dataToInsert = isHTML ? this.processHTML(data) : this.processPlain(data);
236
237 if (!dataToInsert.length) {
238 return;
239 }
240
241 if (dataToInsert.length === 1) {
242 if (!dataToInsert[0].isBlock) {
243 this.processInlinePaste(dataToInsert.pop());
244 } else {
245 this.processSingleBlock(dataToInsert.pop());
246 }
247
248 return;
249 }
250
251 const isCurrentBlockDefault = BlockManager.currentBlock && BlockManager.currentBlock.tool.isDefault;
252 const needToReplaceCurrentBlock = isCurrentBlockDefault && BlockManager.currentBlock.isEmpty;
253
254 dataToInsert.map(
255 async (content, i) => this.insertBlock(content, i === 0 && needToReplaceCurrentBlock)
256 );
257
258 if (BlockManager.currentBlock) {
259 Caret.setToBlock(BlockManager.currentBlock, Caret.positions.END);
260 }
261 }
262
263 /**
264 * Set onPaste callback handler

Callers 2

processDataTransferMethod · 0.95
renderFromHTMLMethod · 0.80

Calls 7

processHTMLMethod · 0.95
processPlainMethod · 0.95
processInlinePasteMethod · 0.95
processSingleBlockMethod · 0.95
insertBlockMethod · 0.95
popMethod · 0.80
setToBlockMethod · 0.65

Tested by

no test coverage detected