UNPKG

@vericus/slate-kit-highlight-text

Version:

plugin that provide a way to color/highlight a group of text on slate

39 lines 1.13 kB
import { Set } from "immutable"; import { Mark, Data } from "slate"; function getLeafNode(el) { if (el.hasAttributes()) { var parentNode = el.parentNode; if (el.getAttribute("data-slate-leaf") === "true") { return el; } if (parentNode) { return getLeafNode(parentNode); } } return null; } export default function getData(type, data, el) { var _a; var marks = Set(); var node = getLeafNode(el) || el; while (node) { var firstChild = node.firstChild; if (node.hasAttributes && node.hasAttributes()) { var color = node.getAttribute("data-slate-kit-" + type.toLowerCase()); if (color) { marks = marks.add(new Mark({ type: type, data: Data.create((_a = {}, _a[data] = color, _a)), })); } } node = firstChild; } if (marks && marks.size > 0) { return { marks: marks.toArray() }; } return {}; } //# sourceMappingURL=getData.js.map