How to use the prosemirror-test-builder.img 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-view / test / test-domchange.js View on Github external
const ist = require("ist")
const {eq, doc, p, pre, h1, a, em, img: img_, br, strong, blockquote} = require("prosemirror-test-builder")
const {EditorState, TextSelection} = require("prosemirror-state")
const {tempEditor, findTextNode} = require("./view")

const img = img_({src: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="})

function setSel(aNode, aOff, fNode, fOff) {
  let r = document.createRange(), s = window.getSelection()
  r.setEnd(fNode || aNode, fNode ? fOff : aOff)
  r.setStart(aNode, aOff)
  s.removeAllRanges()
  s.addRange(r)
}

function flush(view) {
  view.domObserver.flush()
}

describe("DOM change", () => {
  it("notices when text is added", () => {
    let view = tempEditor({doc: doc(p("hello"))})
github ProseMirror / prosemirror-transform / test / test-trans.js View on Github external
it("can change an inline node", () =>
       markup(doc(p("foo<a>", img, "bar")),
              doc(p("foo", img({src: "bar", alt: "y"}), "bar")),
              "image", {src: "bar", alt: "y"}))
  })</a>
github ProseMirror / prosemirror-transform / test / test-trans.js View on Github external
it("can replace content with an inline node", () =&gt;
       repl(doc(p("<a>fo<b>o")), img(), doc(p("</b></a><b><a>", img, "o"))))
</a></b>
github ProseMirror / prosemirror-model / test / test-dom.js View on Github external
ist(derivedDOM.innerHTML, declaredDOM.innerHTML)
        ist(DOMParser.fromSchema(schema).parse(derivedDOM), doc, eq)
      }
    }

    it("can represent simple node",
       test(doc(p("hello")),
            "<p>hello</p>"))

    it("can represent a line break",
       test(doc(p("hi", br, "there")),
            "<p>hi<br>there</p>"))

    it("can represent an image",
       test(doc(p("hi", img({alt: "x"}), "there")),
            '<p>hi<img alt="x" src="img.png">there</p>'))

    it("joins styles",
       test(doc(p("one", strong("two", em("three")), em("four"), "five")),
            "<p>one<strong>two</strong><em><strong>three</strong>four</em>five</p>"))

    it("can represent links",
       test(doc(p("a ", a({href: "foo"}, "big ", a({href: "bar"}, "nested"), " link"))),
            "<p>a <a href="\&quot;foo\&quot;">big </a><a href="\&quot;bar\&quot;">nested</a><a href="\&quot;foo\&quot;"> link</a></p>"))

    it("can represent and unordered list",
       test(doc(ul(li(p("one")), li(p("two")), li(p("three", strong("!")))), p("after")),
            "<ul><li><p>one</p></li><li><p>two</p></li><li><p>three<strong>!</strong></p></li></ul><p>after</p>"))

    it("can represent an ordered list",
       test(doc(ol(li(p("one")), li(p("two")), li(p("three", strong("!")))), p("after")),
github ProseMirror / prosemirror-view / test / test-selection.js View on Github external
const {doc, blockquote, p, em, img: img_, strong, code, br, hr, ul, li} = require("prosemirror-test-builder")
const ist = require("ist")
const {Selection, NodeSelection} = require("prosemirror-state")
const {tempEditor, findTextNode} = require("./view")
const {Decoration, DecorationSet} = require("..")

const img = img_({src: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="})

function allPositions(doc) {
  let found = []
  function scan(node, start) {
    if (node.isTextblock) {
      for (let i = 0; i &lt;= node.content.size; i++) found.push(start + i)
    } else {
      node.forEach((child, offset) =&gt; scan(child, start + offset + 1))
    }
  }
  scan(doc, 0)
  return found
}

function setDOMSel(node, offset) {
  let range = document.createRange()