项目作者: sachinrekhi

项目描述 :
An operational transformation library for rich text documents
高级语言: Python
项目地址: git://github.com/sachinrekhi/richtextpy.git
创建时间: 2016-04-11T05:17:31Z
项目社区:https://github.com/sachinrekhi/richtextpy

开源协议:MIT License

下载


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

  1. from richtextpy import Delta
  2. delta = Delta([
  3. {'insert': 'The quick '},
  4. {'insert': 'brown', 'attributes': {'color': 'brown'}},
  5. {'insert': ' fox'}
  6. ])
  7. # keep the first 10 characters, delete the next 5, and insert a red 'red'
  8. change = Delta().retain(10).delete(5).insert('red', {'color': 'red'})
  9. """
  10. change is:
  11. [
  12. {'retain': 10},
  13. {'delete': 5},
  14. {'insert': 'red', 'attributes': {'color': 'red'}},
  15. ]
  16. """
  17. composed = delta.compose(change)
  18. """
  19. composed is:
  20. [
  21. {'insert': 'The quick '},
  22. {'insert': 'red', 'attributes': {'color': 'red'}},
  23. {'insert': ' fox'}
  24. ]
  25. """

Installation

  1. (install from Pypi)
  2. pip install richtextpy
  3. OR
  4. (install from GitHub source download)
  5. python setup.py install

Dependencies

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

Running Tests

  1. (from GitHub source download directory)
  2. 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.