GithubHelp home page GithubHelp logo

mohitanand001 / richtextpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sachinrekhi/richtextpy

0.0 1.0 0.0 53 KB

An operational transformation library for rich text documents

License: MIT License

Python 100.00%

richtextpy's Introduction

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.

richtextpy's People

Contributors

sachinrekhi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.