Skip to main content

Python implementation of core ProseMirror modules for collaborative editing

Project description

prosemirror-py

CI Code Coverage PyPI Package License Fellow Careers

This package provides Python implementations of the following ProseMirror packages:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prosemirror-0.5.2.tar.gz (66.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prosemirror-0.5.2-py3-none-any.whl (61.7 kB view details)

Uploaded Python 3

File details

Details for the file prosemirror-0.5.2.tar.gz.

File metadata

  • Download URL: prosemirror-0.5.2.tar.gz
  • Upload date:
  • Size: 66.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.5

File hashes

Hashes for prosemirror-0.5.2.tar.gz
Algorithm Hash digest
SHA256 719c2aa0a43e07b774ed1db47574e20ec881218613c9a59ad929c6b3ca3c1e5f
MD5 c463b3b92d7f728af63e542cc7cafcaf
BLAKE2b-256 eafecfecf8a00202e284dd92dd33e3a451d5dea24ab477a216428fd8e5713a79

See more details on using hashes here.

File details

Details for the file prosemirror-0.5.2-py3-none-any.whl.

File metadata

File hashes

Hashes for prosemirror-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b1d78d8793c12554e464e662104b2d7448b2e606bb4212471224bb310124ea56
MD5 779a61791e38360f4c2147b8d7ed36b9
BLAKE2b-256 23a3720c78f77ec2f1d7c9a20280ab46609a9acf4628d21964cf4eedbaf22d55

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page