Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
prosemirror-model
Advanced tools
The prosemirror-model package is a part of the ProseMirror toolkit, which provides a powerful, flexible, and customizable framework for building rich text editors. The prosemirror-model package specifically deals with the document model, which includes defining schemas, creating and manipulating documents, and working with nodes and marks.
Defining a Schema
This feature allows you to define a schema for your document. A schema specifies the types of nodes and marks that can appear in the document, as well as their attributes and how they should be serialized to and from DOM.
const { Schema } = require('prosemirror-model');
const mySchema = new Schema({
nodes: {
doc: { content: 'block+' },
paragraph: { content: 'text*', toDOM: () => ['p', 0] },
text: { inline: true }
},
marks: {
strong: { toDOM: () => ['strong', 0] }
}
});
Creating a Document
This feature allows you to create a document using the schema you defined. The document is created from a JSON representation that matches the schema.
const { Node } = require('prosemirror-model');
const doc = Node.fromJSON(mySchema, {
type: 'doc',
content: [
{ type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }
]
});
Manipulating Nodes
This feature allows you to manipulate nodes within the document. You can create new nodes, copy existing nodes, and create fragments of nodes.
const { Fragment } = require('prosemirror-model');
const paragraph = mySchema.nodes.paragraph.createAndFill();
const textNode = mySchema.text('New text');
const newParagraph = paragraph.copy(Fragment.from(textNode));
Slate is another framework for building rich text editors. It provides a more flexible and less opinionated approach compared to ProseMirror. While ProseMirror uses a schema-based approach to define the document structure, Slate allows for more dynamic and custom data models.
Draft.js is a framework for building rich text editors developed by Facebook. It uses a content state model to represent the document and provides a set of immutable data structures for manipulating the content. Draft.js is more opinionated and less flexible compared to ProseMirror, but it integrates well with React.
Quill is a rich text editor that provides a simple and easy-to-use API. It is less flexible compared to ProseMirror and Slate, but it is very easy to set up and use. Quill is suitable for applications that need a basic rich text editor without much customization.
[ WEBSITE | ISSUES | FORUM | GITTER | CHANGELOG ]
ProseMirror is a well-behaved rich semantic content editor based on contentEditable, with support for collaborative editing and custom document schemas.
This module implements ProseMirror's document model, along with the mechanisms needed to support schemas.
The project page has more information, a number of examples and the documentation.
This code is released under an MIT license. There's a forum for general discussion and support requests, and the Github bug tracker is the place to report issues.
0.23.0 (2017-09-13)
ResolvedPos.marks
no longer takes a parameter (you probably want marksAcross
if you were passing true there).
Attribute and mark constraints in content expressions are no longer supported (this also means the prosemirror-schema-table
package, which relied on them, is no longer supported). In this release, mark constraints are still (approximately) recognized with a warning, when present.
ContentMatch
objects lost a number of methods: matchNode
, matchToEnd
, findWrappingFor
(which can be easily emulated using the remaining API), and allowsMark
, which is now the responsibility of node types instead.
ContentMatch.validEnd
is now a property rather than a method.
ContentMatch.findWrapping
now returns an array of plain node types, with no attribute information (since this is no longer necessary).
The compute
method for attributes is no longer supported.
Fragments no longer have an offsetAt
method.
DOMParser.schemaRules
is no longer public (use fromSchema
and get the resulting parser's rules
property instead).
The DOM parser option topStart
has been replaced by topMatch
.
The DOMSerializer
methods nodesFromSchema
and marksFromSchema
are no longer public (construct a serializer with fromSchema
and read its nodes
and marks
properties instead).
Fix issue where whitespace at node boundaries was sometimes dropped during content parsing.
Attribute default values of undefined
are now allowed.
contentElement
in parse rules may now be a function.
The new method ResolvedPos.marksAcross
can be used to find the set of marks that should be preserved after a deletion.
Content expressions are now a regular language, meaning all the operators can be nested and composed as desired, and a bunch of constraints on what could appear next to what have been lifted.
The starting content match for a node type now lives in NodeType.contentMatch
.
Allowed marks are now specified per node, rather than in content expressions, using the marks
property on the node spec.
Node types received new methods allowsMarkType
, allowsMarks
, and allowedMarks
, which tell you about the marks that node supports.
The style
property on parse rules may now have the form "font-style=italic"
to only match styles that have the value after the equals sign.
FAQs
ProseMirror's document model
The npm package prosemirror-model receives a total of 1,327,306 weekly downloads. As such, prosemirror-model popularity was classified as popular.
We found that prosemirror-model demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.