How to use the prosemirror-test-builder.builders function in prosemirror-test-builder

To help you get started, we’ve selected a few prosemirror-test-builder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ProseMirror / prosemirror-transform / test / test-trans.js View on Github external
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)
    })

    it("can unwrap a body after a placed node", () => {
      let tr = new Transform(hb.doc(hb.h("Head"), hb.b(hb.p("Content"))))
      tr.replace(7, 7, tr.doc.slice(0, tr.doc.content.size))
      ist(tr.doc, hb.doc(hb.h("Head"), hb.b(hb.h("Head"), hb.p("Content"), hb.p("Content"))), eq)
    })
github ProseMirror / prosemirror-model / test / test-dom.js View on Github external
it("parses unique, non-exclusive, same-typed marks", () => {
      let commentSchema = new Schema({
        nodes: schema.spec.nodes,
        marks: schema.spec.marks.update("comment", {
          attrs: { id: { default: null }},
          parseDOM: [{
            tag: "span.comment",
            getAttrs(dom) { return { id: parseInt(dom.getAttribute('data-id'), 10) } }
          }],
          excludes: '',
          toDOM(mark) { return ["span", {class: "comment", "data-id": mark.attrs.id }, 0] }
        })
      })
      let b = builders(commentSchema)
      test(b.schema.nodes.doc.createAndFill(undefined, [
          b.schema.nodes.paragraph.createAndFill(undefined, [
            b.schema.text('double comment', [
                b.schema.marks.comment.create({ id: 1 }),
                b.schema.marks.comment.create({ id: 2 })
              ])
          ])
        ]),
           "<p><span data-id="\&quot;1\&quot;" class="\&quot;comment\&quot;"><span data-id="\&quot;2\&quot;" class="\&quot;comment\&quot;">double comment</span></span></p>")()
    })
github ProseMirror / prosemirror-model / test / test-dom.js View on Github external
it("serializes non-spanning marks correctly", () =&gt; {
      let markSchema = new Schema({
        nodes: schema.spec.nodes,
        marks: schema.spec.marks.update("test", {
          parseDOM: [{tag: "test"}],
          toDOM() { return ["test", 0] },
          spanning: false
        })
      })
      let b = builders(markSchema)
      test(b.doc(b.paragraph(b.test("a", b.image({src: "x"}), "b"))),
           "<p>a<img src="\&quot;x\&quot;">b</p>")()
    })
github ProseMirror / prosemirror-model / test / test-dom.js View on Github external
it("serializes an element and an attribute with XML namespace", () =&gt; {
      let xmlnsSchema = new Schema({
        nodes: {
          doc: { content: "svg*" }, text: {},
          "svg": {
            parseDOM: [{tag: "svg", namespace: 'http://www.w3.org/2000/svg'}],
            group: 'block',
            toDOM() { return ["http://www.w3.org/2000/svg svg", ["use", { "http://www.w3.org/1999/xlink href": "#svg-id" }]] },
          },
        },
      })

      let b = builders(xmlnsSchema)
      let d = b.doc(b.svg())
      test(d, "<svg></svg>", xmlDocument)()

      let dom = xmlDocument.createElement('div')
      dom.appendChild(DOMSerializer.fromSchema(xmlnsSchema).serializeFragment(d.content, {document: xmlDocument}))
      ist(dom.querySelector('svg').namespaceURI, 'http://www.w3.org/2000/svg')
      ist(dom.querySelector('use').namespaceURI, 'http://www.w3.org/2000/svg')
      ist(dom.querySelector('use').attributes[0].namespaceURI, 'http://www.w3.org/1999/xlink')
    })
github ProseMirror / prosemirror-model / test / test-dom.js View on Github external
it("can parse marks on block nodes", () =&gt; {
      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="\&quot;comment\&quot;"><p>two</p><p><strong>three</strong></p></div><p>four</p>")()
    })
github ProseMirror / prosemirror-tables / test / build.js View on Github external
const {TextSelection, NodeSelection} = require("prosemirror-state")
const {schema: baseSchema} = require("prosemirror-schema-basic")
const {tableNodes, cellAround, CellSelection} = require("../dist/")

let schema = new Schema({
  nodes: baseSchema.spec.nodes.append(tableNodes({
    tableGroup: "block",
    cellContent: "block+",
    cellAttributes: {
      test: {default: "default"}
    }
  })),
  marks: baseSchema.spec.marks
})

let e = module.exports = require("prosemirror-test-builder").builders(schema, {
  p: {nodeType: "paragraph"},
  tr: {nodeType: "table_row"},
  td: {nodeType: "table_cell"},
  th: {nodeType: "table_header"}
})

e.c = function(colspan, rowspan) {
  return e.td({colspan, rowspan}, e.p("x"))
}
e.c11 = e.c(1, 1)
e.cEmpty = e.td(e.p())
e.cCursor = e.td(e.p("x"))
e.cAnchor = e.td(e.p("x"))
e.cHead = e.td(e.p("x"))

e.h = function(colspan, rowspan) {
github ProseMirror / prosemirror-markdown / test / build.js View on Github external
const {builders} = require("prosemirror-test-builder")
const {schema} = require("..")

module.exports = builders(schema, {
  p: {nodeType: "paragraph"},
  h1: {nodeType: "heading", level: 1},
  h2: {nodeType: "heading", level: 2},
  hr: {nodeType: "horizontal_rule"},
  li: {nodeType: "list_item"},
  ol: {nodeType: "ordered_list"},
  ol3: {nodeType: "ordered_list", order: 3},
  ul: {nodeType: "bullet_list"},
  pre: {nodeType: "code_block"},
  a: {markType: "link", href: "foo"},
  br: {nodeType: "hard_break"},
  img: {nodeType: "image", src: "img.png", alt: "x"}
})
github guardian / prosemirror-noting / test / prosemirror-noter-plugin.spec.js View on Github external
})
    ),
    flag: createNoteMark(
      {
        flag: "gu-flag",
        correct: "gu-correct"
      },
      meta => ({
        class: meta.hidden ? "note--collapsed" : "",
        title: "Test"
      })
    ),
  })
});

const build = builders(noteSchema, {
  p: {
    markType: "paragraph"
  }
});

const { doc, p } = build;

const note = (attrs = {}, content) =>
  build.note(Object.assign({}, { meta: { type: "note" } }, attrs), content);

const flag = (attrs = {}, content) =>
  build.flag(Object.assign({}, { meta: { type: "flag" } }, attrs), content);

const t = (...content) => doc(...content);

const selFor = initDoc => {
github ifiokjr / remirror / packages / jest-prosemirror / src / jest-prosemirror-nodes.ts View on Github external
&gt;,
  GNodes extends string = string,
  GMarks extends string = string
&gt;(
  testSchema: Schema,
  names: GObj,
) =&gt; {
  return pm.builders(testSchema, {
    doc: { nodeType: 'doc' },
    p: { nodeType: 'paragraph' },
    text: { nodeType: 'text' },
    ...names,
  });
};

const built = pm.builders(schema, {
  doc: { nodeType: 'doc' },
  p: { nodeType: 'paragraph' },
  text: { nodeType: 'text' },
  atomInline: { nodeType: 'atomInline' },
  atomBlock: { nodeType: 'atomBlock' },
  atomContainer: { nodeType: 'atomContainer' },
  li: { nodeType: 'listItem' },
  ul: { nodeType: 'bulletList' },
  ol: { nodeType: 'orderedList' },
  table: { nodeType: 'table' },
  tr: { nodeType: 'table_row' },
  td: { nodeType: 'table_cell' },
  th: { nodeType: 'table_cell' },
  blockquote: { nodeType: 'blockquote' },
  h1: { nodeType: 'heading', level: 1 },
  h2: { nodeType: 'heading', level: 2 },
github ifiokjr / remirror / packages / jest-prosemirror / src / jest-prosemirror-nodes.ts View on Github external
export const pmBuild = &lt;
  GObj extends Record = Record&lt;
    string,
    NodeTypeAttributes | MarkTypeAttributes
  &gt;,
  GNodes extends string = string,
  GMarks extends string = string
&gt;(
  testSchema: Schema,
  names: GObj,
) =&gt; {
  return pm.builders(testSchema, {
    doc: { nodeType: 'doc' },
    p: { nodeType: 'paragraph' },
    text: { nodeType: 'text' },
    ...names,
  });
};