How to use the prosemirror-model.Schema 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 cosmocode / dokuwiki-plugin-prosemirror / script / nodeviews / FootnoteView.js View on Github external
open() {
        jQuery(this.tooltip).dialog({
            minWidth: 1100,
            minHeight: 550,
            title: LANG.plugins.prosemirror.footnoteViewTitle,
            modal: true,
            appendTo: '.dokuwiki',
            close: this.dispatchOuter.bind(this),
        });
        // And put a sub-ProseMirror into that
        const footnoteSchema = new Schema(getFootnoteSpec());
        const mi = new MenuInitializer(footnoteSchema);
        this.innerView = new EditorView(this.tooltip, {
            // You can use any node as an editor document
            state: EditorState.create({
                doc: Node.fromJSON(footnoteSchema, JSON.parse(this.node.attrs.contentJSON)),
                footnoteSchema,
                plugins: [
                    mi.getMenuPlugin(),
                    getKeymapPlugin(footnoteSchema),
                ],
            }),
            // This is the magic part
            dispatchTransaction: this.dispatchInner.bind(this),
            handleDOMEvents: {
                mousedown: () => {
                    // Kludge to prevent issues due to the fact that the whole
github chanzuckerberg / czi-prosemirror / demo / SimpleEditor.js View on Github external
[DOC]: DocNodeSpec,
  [PARAGRAPH]: ParagraphNodeSpec,
  [TEXT]: TextNodeSpec,
  [HARD_BREAK]: HardBreakNodeSpec,
};

// Creates the marks mapping for schema. Please see `EditorMarks` for all the
// marks available.
const MARKS = {
  [MARK_LINK]: LinkMarkSpec,
  [MARK_STRONG]: StrongMarkSpec,
};

// Create the schema.
// See https://prosemirror.net/examples/schema/
const SCHEMA = new Schema({nodes: NODES, marks: MARKS});

// Define the plugins. Please see `EditorPlugins` for all the plugins
// available.
const PLUGINS = [
  // Plugin to let user edit link's url inline.
  new LinkTooltipPlugin(),

  // Plugin to persist user's text selection visible when the is not focsued.
  new SelectionPlaceholderPlugin(),

  // Basic behaviors.
  buildInputRules(SCHEMA),
  dropCursor(),
  gapCursor(),
  history(),
github ProseMirror / prosemirror-markdown / src / schema.js View on Github external
import {Schema} from "prosemirror-model"

// ::Schema Document schema for the data model used by CommonMark.
export const schema = new Schema({
  nodes: {
    doc: {
      content: "block+"
    },

    paragraph: {
      content: "inline*",
      group: "block",
      parseDOM: [{tag: "p"}],
      toDOM() { return ["p", 0] }
    },

    blockquote: {
      content: "block+",
      group: "block",
      parseDOM: [{tag: "blockquote"}],
github ProseMirror / prosemirror-commands / test / test-commands.js View on Github external
apply(doc(h1("foo<a>bar")), splitBlock, doc(h1("foo"), h1("bar"))))

  it("deletes selected content", () =&gt;
     apply(doc(p("fo</a><a>ob<b>ar")), splitBlock, doc(p("fo"), p("ar"))))

  it("splits a parent block when a node is selected", () =&gt;
     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", () =&gt;
     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", () =&gt;
     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", () =&gt;
     apply(hDoc(4), splitBlock,</a></b>
github ProseMirror / prosemirror-transform / test / test-structure.js View on Github external
it("doesn't return true when the split-off content doesn't fit in the given node type", () => {
    let s = new Schema({nodes: schema.spec.nodes.addBefore("heading", "title", {content: "text*"})
                        .addToEnd("chapter", {content: "title scene+"})
                        .addToEnd("scene", {content: "para+"})
                        .update("doc", {content: "chapter+"})})
    ist(!canSplit(s.node("doc", null, s.node("chapter", null, [
      s.node("title", null, s.text("title")),
      s.node("scene", null, s.node("para", null, s.text("scene")))
    ])), 4, 1, [{type: s.nodes.scene}]))
  })
})
github ProseMirror / prosemirror-transform / test / test-structure.js View on Github external
const {Schema, Slice} = require("prosemirror-model")
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: {}
github pubpub / pubpub / src / components / AtomTypes / Document / proseEditor / schema.js View on Github external
childNodes: null,
			};
		}
	}],
	inline: false,
	group: 'block',
	draggable: false,
	isTextblock: true,
	locked: true,
};

const schemaNodes = basicSchema.nodeSpec.addBefore('image', 'embed', Embed).addBefore('image', 'block_embed', BlockEmbed).addBefore('horizontal_rule', 'page_break', PageBreak).addBefore('image', 'emoji', Emoji);
const listSchema = addListNodes(schemaNodes, "paragraph block*", "block");
const tableSchema = addTableNodes(listSchema, "paragraph block*", "block");

export const schema = new Schema({
	nodes: tableSchema,
	marks: basicSchema.markSpec.addBefore('code', 'sub', SubMark).addBefore('code', 'sup', SupMark).addBefore('code', 'strike', StrikeThroughMark)
});

export const createSchema = () => {
  return new Schema({
  	nodes: tableSchema,
  	marks: basicSchema.markSpec.addBefore('code', 'sub', SubMark).addBefore('code', 'sup', SupMark).addBefore('code', 'strike', StrikeThroughMark)
  });
}


const EmbedType = schema.nodes.embed;

exports.Embed = EmbedType;
github guardian / prosemirror-invisibles / pages / index.js View on Github external
import { EditorState } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
import { Schema, DOMParser } from 'prosemirror-model';
import { schema } from 'prosemirror-schema-basic';
import { addListNodes } from 'prosemirror-schema-list';
import { exampleSetup } from 'prosemirror-example-setup';
import invisibles, { hardBreak, paragraph, space } from '../src/js';

import 'prosemirror-view/style/prosemirror.css';
import 'prosemirror-menu/style/menu.css';
import 'prosemirror-example-setup/style/style.css';
import '../src/css/invisibles.scss';

const mySchema = new Schema({
  nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
  marks: schema.spec.marks
});

new EditorView(document.querySelector('#editor'), {
  state: EditorState.create({
    doc: DOMParser.fromSchema(mySchema).parse(
      document.querySelector('#content')
    ),
    plugins: [
      ...exampleSetup({ schema: mySchema }),
      invisibles([hardBreak(), paragraph(), space()])
    ]
  })
});
github zodiac-team / zodiac-ui / libs / editor / src / lib / utils / create-schema.ts View on Github external
},
            {} as { [nodeName: string]: MarkSpec },
        ),
    )
    const nodes = sanitizeNodes(
        editorConfig.nodes.sort(sortByOrder("nodes")).reduce(
            (acc, node) => {
                acc[node.name] = node.node
                return acc
            },
            {} as { [nodeName: string]: NodeSpec },
        ),
        marks,
    )

    return new Schema({ nodes, marks })
}
github cosmocode / dokuwiki-plugin-prosemirror / script / plugins / Menu / MenuItems / FootnoteMenuItemDispatcher.js View on Github external
command: (state, dispatch) => {
                const { $from } = state.selection;

                const index = $from.index();
                if (!$from.parent.canReplaceWith(index, index, schema.nodes.footnote)) {
                    return false;
                }

                const selectedContent = state.selection.content().content.toJSON();
                const footnoteDoc = {
                    type: 'doc',
                    content: selectedContent || [{ type: 'paragraph' }],
                };
                try {
                    const footnoteSchema = new Schema(getFootnoteSpec());
                    footnoteSchema.nodeFromJSON(footnoteDoc);
                } catch (e) {
                    return false;
                }

                if (dispatch) {
                    const footnoteNode = schema.nodes.footnote.create({ contentJSON: JSON.stringify(footnoteDoc) });
                    dispatch(state.tr.replaceSelectionWith(footnoteNode));
                }

                return true;
            },
            icon: svgIcon('note-plus-outline'),