Skip to main content

Python implementation of core ProseMirror modules for collaborative editing

Project description

prosemirror-py

CI Code Coverage Python Version 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. There are no type annotations at the moment, although the original has annotations available in doc comments.

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.3.2.tar.gz (36.0 kB view details)

Uploaded Source

Built Distribution

prosemirror-0.3.2-py3-none-any.whl (43.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prosemirror-0.3.2.tar.gz
  • Upload date:
  • Size: 36.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.79.1-microsoft-standard-WSL2

File hashes

Hashes for prosemirror-0.3.2.tar.gz
Algorithm Hash digest
SHA256 6d1aa42380078ade7c6e1a01ace26988eb8bbb009b9e17be5e4841e4aa90014d
MD5 6bac9881abfade93a6e7b8f7d2c28567
BLAKE2b-256 a25d048ba6038f193e9693a125ea9fcd2325975447817dbd8bf9604ae9284966

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prosemirror-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 43.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.79.1-microsoft-standard-WSL2

File hashes

Hashes for prosemirror-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4ea83857444c6fb03cba43f6cdbfe355b396e873ce9f254301c72b5a7f9853db
MD5 a86483d13bcf1fe4f2ce50e637babd1b
BLAKE2b-256 2690a1718d95f85482231b9bda91768531d35d5d8c4dc44dfb65d4fa5200997c

See more details on using hashes here.

Supported by

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