Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("produces sensible screen coordinates in corner cases", () => {
let view = tempEditor({doc: doc(p("one", em("two", strong("three"), img), br, code("foo")), p())})
return new Promise(ok => {
setTimeout(() => {
allPositions(view.state.doc).forEach(pos => {
let coords = view.coordsAtPos(pos)
let found = view.posAtCoords({top: coords.top + 1, left: coords.left}).pos
ist(found, pos)
setSel(view, pos)
})
ok()
}, 20)
})
})
it("can render marks with complex structure", () => {
let deepEm = new DOMSerializer(serializer.nodes, Object.assign({}, serializer.marks, {
em() { return ["em", ["i", {"data-emphasis": true}, 0]] }
}))
ist(deepEm.serializeNode(p(strong("foo", code("bar"), em(code("baz"))), em("quux"), "xyz"), {document}).innerHTML,
"<strong>foo<code>bar</code></strong><em><i data-emphasis="\"true\""><strong><code>baz</code></strong>quux</i></em>xyz")
})
})
it("doesn't split other marks for omitted marks", () => {
ist(noEm.serializeNode(p("foo", code("bar"), em(code("baz"), "quux"), "xyz"), {document}).innerHTML,
"foo<code>barbaz</code>quuxxyz")
})
"<ol><li><p>one</p></li><li><p>two</p></li><li><p>three<strong>!</strong></p></li></ol><p>after</p>"))
it("can represent a blockquote",
test(doc(blockquote(p("hello"), p("bye"))),
"<blockquote><p>hello</p><p>bye</p></blockquote>"))
it("can represent a nested blockquote",
test(doc(blockquote(blockquote(blockquote(p("he said"))), p("i said"))),
"<blockquote><blockquote><blockquote><p>he said</p></blockquote></blockquote><p>i said</p></blockquote>"))
it("can represent headings",
test(doc(h1("one"), h2("two"), p("text")),
"<h1>one</h1><h2>two</h2><p>text</p>"))
it("can represent inline code",
test(doc(p("text and ", code("code that is ", em("emphasized"), "..."))),
"<p>text and <code>code that is </code><em><code>emphasized</code></em><code>...</code></p>"))
it("can represent a code block",
test(doc(blockquote(pre("some code")), p("and")),
"<blockquote><pre><code>some code</code></pre></blockquote><p>and</p>"))
it("supports leaf nodes in marks",
test(doc(p(em("hi", br, "x"))),
"<p><em>hi<br>x</em></p>"))
it("doesn't collapse non-breaking spaces",
test(doc(p("\u00a0 \u00a0hello\u00a0")),
"<p>\u00a0 \u00a0hello\u00a0</p>"))
it("can parse marks on block nodes", () => {
let commentSchema = new Schema({
it("can add a mark in a nested node", () =>
add(doc(p("before"), blockquote(p("the variable is called <a>i<b>")), p("after")),
schema.mark("code"),
doc(p("before"), blockquote(p("the variable is called ", code("i"))), p("after"))))
</b></a>
it("preserves marks", () =>
cut(doc(p("foo", em("ba<a>r", img, strong("baz"), br), "qu<b>ux", code("xyz"))),
doc(p(em("r", img, strong("baz"), br), "qu"))))
})</b></a>
it("handles composition in a multi-child mark with a cursor wrapper", () => {
let pm = requireFocus(tempEditor({doc: doc(p("one ", em("two<a>", strong(" three"))))}))
pm.dispatch(pm.state.tr.addStoredMark(schema.marks.code.create()))
let emNode = pm.dom.querySelector("em")
compose(pm, () => edit(emNode.insertBefore(document.createTextNode(""), emNode.querySelector("strong")), "o"), [
n => edit(n, "o"),
n => edit(n, "w")
], {node: true})
ist(pm.state.doc, doc(p("one ", em("two", code("oow"), strong(" three")))), eq)
})
</a>
it("shows marks", () => {
ist(doc(p("foo", em("bar", strong("quux")), code("baz"))).toString(),
'doc(paragraph("foo", em("bar"), em(strong("quux")), code("baz")))')
})
})
it("iterates over inline nodes", () =>
between(doc(p(em("x"), "f<a>oo", em("bar", img, strong("baz"), br), "quux", code("xy<b>z"))),
"paragraph", "foo", "bar", "image", "baz", "hard_break", "quux", "xyz"))
})</b></a>