UNPKG

907 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7require('slate');
8
9var _utils = require('../utils');
10
11/**
12 * Wrap a block into a code block.
13 */
14function wrapCodeBlockByKey(opts, change, key) {
15 var value = change.value;
16 var document = value.document;
17
18
19 var startBlock = document.getDescendant(key);
20 var text = startBlock.text;
21
22 // Remove all child
23 startBlock.nodes.forEach(function (node) {
24 change.removeNodeByKey(node.key, { normalize: false });
25 });
26
27 // Insert new text
28 var toInsert = (0, _utils.deserializeCode)(opts, text);
29
30 toInsert.nodes.forEach(function (node, i) {
31 change.insertNodeByKey(startBlock.key, i, node, { normalize: false });
32 });
33
34 // Set node type
35 change.setNodeByKey(startBlock.key, {
36 type: opts.containerType
37 });
38
39 return change;
40}
41
42exports.default = wrapCodeBlockByKey;
\No newline at end of file