Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tr.replace(2, 7, tr.doc.slice(2, 7))
ist(tr.doc, tr.before, eq)
})
it("preserves marks on open slice block nodes", () => {
let tr = new Transform(ms.node("doc", null, [ms.node("paragraph", null, [ms.text("a")])]))
tr.replace(3, 3, ms.node("doc", null, [
ms.node("paragraph", null, [ms.text("b")], [ms.mark("em")])
]).slice(1, 3))
ist(tr.doc.childCount, 2)
ist(tr.doc.lastChild.marks.length, 1)
})
// A schema that enforces a heading and a body at the top level
let hbSchema = new Schema({
nodes: schema.spec.nodes.append({
doc: Object.assign({}, schema.spec.nodes.get("doc"), {content: "heading body"}),
body: {content: "block+"}
})
})
let hb = builders(hbSchema, {
p: {nodeType: "paragraph"},
b: {nodeType: "body"},
h: {nodeType: "heading", level: 1},
})
it("can unwrap a paragraph when replacing into a strict schema", () => {
let tr = new Transform(hb.doc(hb.h("Head"), hb.b(hb.p("Content"))))
tr.replace(0, tr.doc.content.size, tr.doc.slice(7, 16))
ist(tr.doc, hb.doc(hb.h("Content"), hb.b(hb.p())), eq)
})
doc(ul(li(p("ABCD")), li(p("EFGH")))).slice(5, 13, true),
doc(ul(li(p("abCD")), li(p("EFgh"))))))
it("will auto-close a list item when it fits in a list", () =>
repl(doc(ul(li(p("foo")), "<a>", li(p("bar")))),
ul(li(p("a</a><a>bc")), li(p("de<b>f"))),
doc(ul(li(p("foo")), li(p("bc")), li(p("de")), li(p("bar"))))))
it("finds the proper openEnd value when unwrapping a deep slice", () =>
repl(doc("</b></a><b><a>", p(), "<b>"),
doc(blockquote(blockquote(blockquote(p("hi"))))).slice(3, 6, true),
doc(p("hi"))))
// A schema that allows marks on top-level block nodes
let ms = new Schema({
nodes: schema.spec.nodes.update("doc", Object.assign({}, schema.spec.nodes.get("doc"), {marks: "_"})),
marks: schema.spec.marks
})
it("preserves marks on block nodes", () => {
let tr = new Transform(ms.node("doc", null, [
ms.node("paragraph", null, [ms.text("hey")], [ms.mark("em")]),
ms.node("paragraph", null, [ms.text("ok")], [ms.mark("strong")])
]))
tr.replace(2, 7, tr.doc.slice(2, 7))
ist(tr.doc, tr.before, eq)
})
it("preserves marks on open slice block nodes", () => {
let tr = new Transform(ms.node("doc", null, [ms.node("paragraph", null, [ms.text("a")])]))
tr.replace(3, 3, ms.node("doc", null, [
ms.node("paragraph", null, [ms.text("b")], [ms.mark("em")])</b></a></b>
const {canSplit, liftTarget, findWrapping, Transform} = require("..")
const {eq, schema: baseSchema} = require("prosemirror-test-builder")
const ist = require("ist")
const schema = new Schema({
nodes: {
doc: {content: "head? block* sect* closing?"},
para: {content: "text*", group: "block"},
head: {content: "text*", marks: ""},
figure: {content: "caption figureimage", group: "block"},
quote: {content: "block+", group: "block"},
figureimage: {},
caption: {content: "text*", marks: ""},
sect: {content: "head block* sect*"},
closing: {content: "text*"},
text: baseSchema.spec.nodes.get("text"),
fixed: {content: "head para closing", group: "block"}
},
marks: {
em: {}
}
})
function n(name, ...content) { return schema.nodes[name].create(null, content) }
function t(str, em) { return schema.text(str, em ? [schema.mark("em")] : null) }
const doc = n("doc", // 0
n("head", t("Head")), // 6
n("para", t("Intro")), // 13
n("sect", // 14
n("head", t("Section head")), // 28
it("can update with a state using a different schema", () => {
let testSchema = new Schema({nodes: schema.spec.nodes})
let view = tempEditor({doc: doc(p(strong("foo")))})
view.updateState(EditorState.create({doc: testSchema.nodes.doc.createAndFill()}))
ist(!view.dom.querySelector("strong"))
})
find("<p>hi</p><var></var>foo<p>ok</p>",
doc(p("hi"), "<a>", p("ok"))))
it("can find a position between nodes",
find("<ul><li>foo</li><var></var><li>bar</li></ul>",
doc(ul(li(p("foo")), "</a><a>", li(p("bar"))))))
it("can find a position at the start of the document",
find("<var></var><p>hi</p>",
doc("</a><a>", p("hi"))))
it("can find a position at the end of the document",
find("<p>hi</p><var></var>",
doc(p("hi"), "</a><a>")))
let quoteSchema = new Schema({nodes: schema.spec.nodes, marks: schema.spec.marks, topNode: "blockquote"})
it("uses a custom top node when parsing",
test(quoteSchema.node("blockquote", null, quoteSchema.node("paragraph", null, quoteSchema.text("hello"))),
"<p>hello</p>"))
function contextParser(context) {
return new DOMParser(schema, [{tag: "foo", node: "horizontal_rule", context}].concat(DOMParser.schemaRules(schema)))
}
it("recognizes context restrictions", () => {
ist(contextParser("blockquote/").parse(domFrom("<blockquote><p></p></blockquote>")),
doc(blockquote(hr, p())), eq)
})
it("accepts group names in contexts", () => {
ist(contextParser("block/").parse(domFrom("<blockquote><p></p></blockquote>")),</a>
it("deletes selected content", () =>
apply(doc(p("fo<a>ob<b>ar")), splitBlock, doc(p("fo"), p("ar"))))
it("splits a parent block when a node is selected", () =>
apply(doc(ol(li(p("a")), "</b></a><b><a>", li(p("b")), li(p("c")))), splitBlock,
doc(ol(li(p("a"))), ol(li(p("b")), li(p("c"))))))
it("doesn't split the parent block when at the start", () =>
apply(doc(ol("</a><a>", li(p("a")), li(p("b")), li(p("c")))), splitBlock, null))
it("splits off a normal paragraph when splitting at the start of a textblock", () =>
apply(doc(h1("</a><a>foo")), splitBlock, doc(p(), h1("foo"))))
const hSchema = new Schema({
nodes: schema.spec.nodes.update("heading", {
content: "inline*"
}).update("doc", {
content: "heading block*"
})
})
function hDoc(a) {
const hDoc = hSchema.node("doc", null, [
hSchema.node("heading", {level: 1}, hSchema.text("foobar"))
])
hDoc.tag = {a}
return hDoc
}
it("splits a paragraph from a heading when a double heading isn't allowed", () =>
apply(hDoc(4), splitBlock,
hSchema.node("doc", null, [</a></b>
it("can parse marks on block nodes", () => {
let commentSchema = new Schema({
nodes: schema.spec.nodes.update("doc", Object.assign({marks: "comment"}, schema.spec.nodes.get("doc"))),
marks: schema.spec.marks.update("comment", {
parseDOM: [{tag: "div.comment"}],
toDOM() { return ["div", {class: "comment"}, 0] }
})
})
let b = builders(commentSchema)
test(b.doc(b.paragraph("one"), b.comment(b.paragraph("two"), b.paragraph(b.strong("three"))), b.paragraph("four")),
"<p>one</p><div class="\"comment\""><p>two</p><p><strong>three</strong></p></div><p>four</p>")()
})