Python implementation of core ProseMirror modules for collaborative editing
Project description
prosemirror-py
This package provides Python implementations of the following ProseMirror packages:
prosemirror-model
version 1.18.1prosemirror-transform
version 1.8.0prosemirror-test-builder
prosemirror-schema-basic
version 1.1.2prosemirror-schema-list
The original implementation has been followed as closely as possible during translation to simplify keeping this package up-to-date with any upstream changes.
Why?
ProseMirror provides a powerful toolkit for building rich-text editors, but it's JavaScript-only. Until now, the only option for manipulating and working with ProseMirror documents from Python was to embed a JS runtime. With this translation, you can now define schemas, parse documents, and apply transforms directly via a native Python API.
Status
The full ProseMirror test suite has been translated and passes. This project only supports Python 3. The code has type annotations to support mypy or other typechecking tools.
Usage
Since this library is a direct port, the best place to learn how to use it is the official ProseMirror documentation. Here is a simple example using the included "basic" schema:
from prosemirror.transform import Transform
from prosemirror.schema.basic import schema
# Create a document containing a single paragraph with the text "Hello, world!"
doc = schema.node("doc", {}, [
schema.node("paragraph", {}, [
schema.text("Hello, world!")
])
])
# Create a Transform which will be applied to the document.
tr = Transform(doc)
# Delete the text from position 3 to 5. Adds a ReplaceStep to the transform.
tr.delete(3, 5)
# Make the first three characters bold. Adds an AddMarkStep to the transform.
tr.add_mark(1, 4, schema.mark("strong"))
# This transform can be converted to JSON to be sent and applied elsewhere.
assert [step.to_json() for step in tr.steps] == [{
'stepType': 'replace',
'from': 3,
'to': 5
}, {
'stepType': 'addMark',
'mark': {'type': 'strong', 'attrs': {}},
'from': 1,
'to': 4
}]
# The resulting document can also be converted to JSON.
assert tr.doc.to_json() == {
'type': 'doc',
'content': [{
'type': 'paragraph',
'content': [{
'type': 'text',
'marks': [{'type': 'strong', 'attrs': {}}],
'text': 'Heo'
}, {
'type': 'text',
'text': ', world!'
}]
}]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file prosemirror-0.5.1.tar.gz
.
File metadata
- Download URL: prosemirror-0.5.1.tar.gz
- Upload date:
- Size: 71.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08e8c253ffdfac97f630d81a033e5a422cdb8d1b05df2a581574ba6838eaac85 |
|
MD5 | 7a74e7750004fdc50df5cc6ebafe0139 |
|
BLAKE2b-256 | 83824b303ac63b7396cf3fa9481d6a0e06a345cde8f36fd2c0608f6f1f5d8392 |
Provenance
The following attestation bundles were made for prosemirror-0.5.1.tar.gz
:
Publisher:
release.yml
on fellowapp/prosemirror-py
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
prosemirror-0.5.1.tar.gz
- Subject digest:
08e8c253ffdfac97f630d81a033e5a422cdb8d1b05df2a581574ba6838eaac85
- Sigstore transparency entry: 149591516
- Sigstore integration time:
- Permalink:
fellowapp/prosemirror-py@7f16822de9ab22539a8df3d1c49dbba48daff821
- Branch / Tag:
refs/tags/v0.5.1
- Owner: https://github.com/fellowapp
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
release.yml@7f16822de9ab22539a8df3d1c49dbba48daff821
- Trigger Event:
release
- Statement type:
File details
Details for the file prosemirror-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: prosemirror-0.5.1-py3-none-any.whl
- Upload date:
- Size: 61.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a30902657893906ddc1803d3e0b0b318dc7a082c5a1a3c44c3f6697371539bb5 |
|
MD5 | 637a39b4c64a67e1c47616fbda5cb38b |
|
BLAKE2b-256 | a7c420294e196b2161a1f57753871ca9c6f062184ccb6c25e7bcdccddb292154 |
Provenance
The following attestation bundles were made for prosemirror-0.5.1-py3-none-any.whl
:
Publisher:
release.yml
on fellowapp/prosemirror-py
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
prosemirror-0.5.1-py3-none-any.whl
- Subject digest:
a30902657893906ddc1803d3e0b0b318dc7a082c5a1a3c44c3f6697371539bb5
- Sigstore transparency entry: 149591517
- Sigstore integration time:
- Permalink:
fellowapp/prosemirror-py@7f16822de9ab22539a8df3d1c49dbba48daff821
- Branch / Tag:
refs/tags/v0.5.1
- Owner: https://github.com/fellowapp
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
release.yml@7f16822de9ab22539a8df3d1c49dbba48daff821
- Trigger Event:
release
- Statement type: