MCPcopy Create free account
hub / github.com/TruthHun/BookStack / domTextBetween

Function domTextBetween

static/editor.md/lib/codemirror/lib/codemirror.js:1867–1906  ·  view source on GitHub ↗
(cm, from, to, fromLine, toLine)

Source from the content-addressed store, hash-verified

1865 }
1866
1867 function domTextBetween(cm, from, to, fromLine, toLine) {
1868 var text = "", closing = false;
1869 function recognizeMarker(id) { return function(marker) { return marker.id == id; }; }
1870 function walk(node) {
1871 if (node.nodeType == 1) {
1872 var cmText = node.getAttribute("cm-text");
1873 if (cmText != null) {
1874 if (cmText == "") cmText = node.textContent.replace(/\u200b/g, "");
1875 text += cmText;
1876 return;
1877 }
1878 var markerID = node.getAttribute("cm-marker"), range;
1879 if (markerID) {
1880 var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
1881 if (found.length && (range = found[0].find()))
1882 text += getBetween(cm.doc, range.from, range.to).join("\n");
1883 return;
1884 }
1885 if (node.getAttribute("contenteditable") == "false") return;
1886 for (var i = 0; i < node.childNodes.length; i++)
1887 walk(node.childNodes[i]);
1888 if (/^(pre|div|p)$/i.test(node.nodeName))
1889 closing = true;
1890 } else if (node.nodeType == 3) {
1891 var val = node.nodeValue;
1892 if (!val) return;
1893 if (closing) {
1894 text += "\n";
1895 closing = false;
1896 }
1897 text += val;
1898 }
1899 }
1900 for (;;) {
1901 walk(from);
1902 if (from == to) break;
1903 from = from.nextSibling;
1904 }
1905 return text;
1906 }
1907
1908 CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
1909

Callers 1

codemirror.jsFile · 0.70

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected