Skip to content

An operational transformation library for rich text documents

License

Notifications You must be signed in to change notification settings

kochelmonster/richtextpy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

richtextpy

An operational transformation library for rich text documents. It enables optimistic conflict-free collaborative editing scenarios (like Google Docs) by providing a rich text document format as well as compose() and transform() methods for managing changes according to the OT algorithm.

This is a Python version of the Javascript Rich Text ottype and can be used in conjunction to support both client-side and server-side operations.

To fully support collaborative editing, you'll also need a rich text editor that produces Delta objects on user changes as well as a server that implements the full OT collaboration protocol. See the references for details on the protocol and some libraries that provide these additional capabilities.

Example

from richtextpy import Delta

delta = Delta([
  {'insert': 'The quick '},
  {'insert': 'brown', 'attributes': {'color': 'brown'}},
  {'insert': ' fox'}
])

# keep the first 10 characters, delete the next 5, and insert a red 'red'
change = Delta().retain(10).delete(5).insert('red', {'color': 'red'})

"""
change is:

[
	{'retain': 10},
	{'delete': 5},
	{'insert': 'red', 'attributes': {'color': 'red'}},
]
"""

composed = delta.compose(change)

"""
composed is:

[
  {'insert': 'The quick '},
  {'insert': 'red', 'attributes': {'color': 'red'}},
  {'insert': ' fox'}
]
"""

Installation

(install from Pypi)

pip install richtextpy

OR

(install from GitHub source download)

python setup.py install

Dependencies

Requires Google's diff-match-patch library for efficient string diffing, which is automatically installed during installation.

Running Tests

(from GitHub source download directory)

python setup.py test

API Reference

Fully implements the original ottypes/rich-text interface. So feel free to use its API reference.

References

License

The MIT License (MIT)

Copyright (c) 2016 Sachin Rekhi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

An operational transformation library for rich text documents

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%