How to use the prosemirror-model.DOMParser.fromSchema function in prosemirror-model

To help you get started, we’ve selected a few prosemirror-model 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 / website / example / dino / index.js View on Github external
}
  }]
}
// }

// schema{
import {Schema, DOMParser} from "prosemirror-model"
import {schema} from "prosemirror-schema-basic"

const dinoSchema = new Schema({
  nodes: schema.spec.nodes.addBefore("image", "dino", dinoNodeSpec),
  marks: schema.spec.marks
})

let content = document.querySelector("#content")
let startDoc = DOMParser.fromSchema(dinoSchema).parse(content)
// }

// command{
let dinoType = dinoSchema.nodes.dino

function insertDino(type) {
  return function(state, dispatch) {
    let {$from} = state.selection, index = $from.index()
    if (!$from.parent.canReplaceWith(index, index, dinoType))
      return false
    if (dispatch)
      dispatch(state.tr.replaceSelectionWith(dinoType.create({type})))
    return true
  }
}
// }
github ProseMirror / website / example / menu / index.js View on Github external
{command: toggleMark(schema.marks.em), dom: icon("i", "em")},
  {command: setBlockType(schema.nodes.paragraph), dom: icon("p", "paragraph")},
  heading(1), heading(2), heading(3),
  {command: wrapIn(schema.nodes.blockquote), dom: icon(">", "blockquote")}
])
// }

import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {baseKeymap} from "prosemirror-commands"
import {keymap} from "prosemirror-keymap"
import {DOMParser} from "prosemirror-model"

window.view = new EditorView(document.querySelector("#editor"), {
  state: EditorState.create({
    doc: DOMParser.fromSchema(schema).parse(document.querySelector("#content")),
    plugins: [keymap(baseKeymap), menu]
  })
})
github scrumpy / tiptap / packages / tiptap / src / Editor.js View on Github external
}

    if (typeof content === 'object') {
      try {
        return this.schema.nodeFromJSON(content)
      } catch (error) {
        console.warn('[tiptap warn]: Invalid content.', 'Passed value:', content, 'Error:', error)
        return this.schema.nodeFromJSON(this.options.emptyDocument)
      }
    }

    if (typeof content === 'string') {
      const element = document.createElement('div')
      element.innerHTML = content.trim()

      return DOMParser.fromSchema(this.schema).parse(element, parseOptions)
    }

    return false
  }
github ProseMirror / website / src / demo / basic.js View on Github external
const {addListNodes} = require("prosemirror-schema-list")
const {exampleSetup} = require("prosemirror-example-setup")

const schema = new Schema({
  nodes: addListNodes(baseSchema.spec.nodes, "paragraph block*", "block"),
  marks: baseSchema.spec.marks
})

let content = document.querySelector("#content")
content.style.display = "none"

let tip = document.querySelector(".demotip")

let view = new MenuBarEditorView(document.querySelector("#editor"), {
  state: EditorState.create({
    doc: DOMParser.fromSchema(schema).parse(content),
    plugins: exampleSetup({schema})
  }),
  onFocus() {
    if (tip) {
      tip.innerHTML = "<a style="text-decoration: none; pointer-events: auto; color: inherit" href="#demos">Find more demos below ↓</a>"
      tip = null
    }
  }
})
window.view = view.editor
github pubpub / pubpub-editor / src / SimpleEditor.js View on Github external
createEditor() {
		const simpleSchema = new Schema({
			nodes: {
				doc: nodes.doc,
				paragraph: nodes.paragraph,
				text: nodes.text,
			},
			marks: marks,
		});
		
		const wrapperElem = document.createElement('div');
		wrapperElem.innerHTML = this.props.initialHtmlString;

		const editorState = EditorState.create({
			doc: DOMParser.fromSchema(simpleSchema).parse(wrapperElem),
			schema: simpleSchema,
			plugins: getBasePlugins({
				schema: simpleSchema,
				placeholder: this.props.placeholder,
			})
		});
		this.view = new EditorView(document.getElementById(this.containerId), {
			state: editorState,
			dispatchTransaction: this._onAction,
		});
	}
github pubpub / pubpub-editor / src / utils / index.js View on Github external
export const getDocForHtmlString = (htmlString, schema) => {
	const wrapperElem = document.createElement('div');
	wrapperElem.innerHTML = htmlString;
	return DOMParser.fromSchema(schema).parse(wrapperElem);
};
github ProseMirror / website / example / schema / index.js View on Github external
function start(place, content, schema, plugins = []) {
  let doc = DOMParser.fromSchema(schema).parse(content)
  return new EditorView(place, {
    state: EditorState.create({
      doc,
      plugins: plugins.concat([histKeymap, keymap(baseKeymap), history()])
    })
  })
}
github taktik / icure-backend / web / icure-ht / app / src / elements / prose-editor / prose-editor / prose-editor.ts View on Github external
}
                })
              } else if (n.type == view.state.schema.nodes.tab) {
              }
              return true
            })
            return true
          },
          destroy: () => {
          }
        }
      })
    });

    let state = EditorState.create({
      doc: DOMParser.fromSchema(this.editorSchema).parse(this.$.content),
      plugins: [
        keymap({
          "Tab": (state: EditorState, dispatch: any, editorView: EditorView) => {
            let tabType = this.editorSchema.nodes.tab
            let {$from} = state.selection, index = $from.index()
            if (!$from.parent.canReplaceWith(index, index, this.editorSchema.nodes.tab))
              return false
            if (dispatch)
              dispatch(state.tr.replaceSelectionWith(tabType.create()))
            return true
          }
        }),
        keymap(baseKeymap),
        history(),
        columnResizing({}),
        tableEditing(),
github nib-edit / Nib / packages / converter / index.js View on Github external
const convertFromHTML = (html = "<p></p>") =&gt; {
  if (!document)
    throw new Error("Document object is required to convert from html.");
  const contentWrapper = document.createElement("div");
  document.body.appendChild(contentWrapper);
  contentWrapper.innerHTML = html;
  const parser = DOMParser.fromSchema(schema);
  const content = parser.parse(contentWrapper);
  document.body.removeChild(contentWrapper);
  return {
    doc: content.toJSON(),
    selection: {
      type: "text",
      anchor: 0,
      head: 0
    }
  };
};