All Projects → BowlingX → Marklib

BowlingX / Marklib

Licence: mit
A small library to wrap serializable TextSelections.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Marklib

Hprose Nodejs
Hprose is a cross-language RPC. This project is Hprose 2.0 for Node.js
Stars: ✭ 297 (-20.8%)
Mutual labels:  serialization
Kim
Kim: A JSON Serialization and Marshaling framework
Stars: ✭ 326 (-13.07%)
Mutual labels:  serialization
Extended text
A powerful extended official text for Flutter, which supports Speical Text(Image,@somebody), Custom Background, Custom overFlow, Text Selection.
Stars: ✭ 345 (-8%)
Mutual labels:  selection
React Native Walkthrough Tooltip
An inline wrapper for calling out React Native components via tooltip
Stars: ✭ 299 (-20.27%)
Mutual labels:  highlighting
Messagepack Csharp
Extremely Fast MessagePack Serializer for C#(.NET, .NET Core, Unity, Xamarin). / msgpack.org[C#]
Stars: ✭ 3,668 (+878.13%)
Mutual labels:  serialization
Metastuff
Code I use in my game for all serialization/deserialization/introspection stuff
Stars: ✭ 337 (-10.13%)
Mutual labels:  serialization
Vue Highlightjs
Syntax highlighting with highlight.js for Vue.js 2.x
Stars: ✭ 295 (-21.33%)
Mutual labels:  highlighting
Leopotamgrouplibraryunity
Tools library for unity 3d game engine: animator graph helpers, serialization (json), localization, event routing (eventbus, ui actions), embedded scripting, uGui xml markup, threading, tweening, in-memory protection and other helpers (pure C#)
Stars: ✭ 373 (-0.53%)
Mutual labels:  serialization
Ictextview
UITextView subclass supporting string/regex search and highlighting
Stars: ✭ 321 (-14.4%)
Mutual labels:  highlighting
Velocypack
A fast and compact format for serialization and storage
Stars: ✭ 347 (-7.47%)
Mutual labels:  serialization
Markserv
🏁 serve markdown as html (GitHub style), index directories, live-reload as you edit
Stars: ✭ 304 (-18.93%)
Mutual labels:  highlighting
Solarized
Solarized color scheme for Sublime Text 3
Stars: ✭ 314 (-16.27%)
Mutual labels:  highlighting
Typedefs
Programming language agnostic type construction language based on polynomials.
Stars: ✭ 337 (-10.13%)
Mutual labels:  serialization
Fspickler
A fast multi-format message serializer for .NET
Stars: ✭ 299 (-20.27%)
Mutual labels:  serialization
Hprose
HPROSE is short for High Performance Remote Object Service Engine. It's a serialize and RPC library, the serialize library of hprose is faster, smaller and more powerful than msgpack, the RPC library is faster, easier and more powerful than thrift.
Stars: ✭ 348 (-7.2%)
Mutual labels:  serialization
Python Syntax
Python syntax highlighting for Vim
Stars: ✭ 297 (-20.8%)
Mutual labels:  highlighting
Msgpack.php
A pure PHP implementation of the MessagePack serialization format / msgpack.org[PHP]
Stars: ✭ 327 (-12.8%)
Mutual labels:  serialization
Ceras
Universal binary serializer for a wide variety of scenarios https://discord.gg/FGaCX4c
Stars: ✭ 374 (-0.27%)
Mutual labels:  serialization
Dragselectrecyclerview
TouchListener that can be attached to any RecyclerView and handles multi selection for you
Stars: ✭ 371 (-1.07%)
Mutual labels:  selection
Windterm
A quicker and better cross-platform SSH/Sftp/Shell/Telnet/Serial client.
Stars: ✭ 345 (-8%)
Mutual labels:  highlighting

marklib

Circle CI Codacy Badge Coverage Status npm Join the chat at https://gitter.im/BowlingX/marklib

A simple and fast zero-dependencies-library to transform text-selections into serializable markings.

Demo

Demo-Gif

Install

marklib can be installed with npm or bower.

npm install --save-dev marklib

bower install marklib --save

Usage

Render by selection

// obtain a selection from document
var selection = document.getSelection();

// create a new rendering based on the current document
var renderer = new Marklib.Rendering(document, options, context)
renderer.setId('myRenderId') // if an ID is not provided, a autogenerated one will be used

// renders the given selection and returns a result (`RenderResult`).
var result = renderer.renderWithRange(selection.getRangeAt(0));

Important: After a Rendering has been used to render a selection/serialized result, it can't be used to render something again. You need to create a new Instance of Rendering.

Options

You can pass options to each rendering instance, the following shows the default options

var renderer = new Marklib.Rendering(document, {
            hoverClass: 'marklib--hover',
            treeClass: 'marklib--tree',
            // Supports arrays and/or strings
            className: ['marking']
});

Events

Marklib triggers events that can be listened to with instance.on('event-name'). Events are build with wolfy87-eventemitter (https://github.com/Olical/EventEmitter). The following Events are available:

Before you can actually receive events, you need to register the event handler with registerEvents (use import { registerEvents } from 'marklib/src/main/RenderingEvents'; on your application bootstrap code.)

Event-Name Description Arguments
click triggered when clicked on a marking. (originalEvent, instanceHierarchy)
hover-enter triggered when a pointer-device starts hovering over a marking (originalEvent, instanceHierarchy)
hover-leave triggered when a pointer-device leaves a marking (originalEvent, instanceHierarchy)

Additionally, marklib will add hover classes to the current hovered marking.

Constructor Arguments

    1. HTMLDocument document -> the document instance used
    1. Object [options], optional -> an object containing setting for marklib (see Options)
    1. HTMLElement [context], optional -> the context used to serialize / deserialize the rendering, if not given the document instance.

Render by serialized result

A Serialized results consist of 2 strings (start end end) in the following form


'body>section;0;1'`
-▲------------▲-▲ 

  • ▲ The first part defines a css-selector (queryable with document.querySelector).
  • ▲ The second part defines the text-node inside the given selector
  • ▲ The third part defines the string-offset inside this text-node

Example

 // This is the result we get from `RenderResult#serialize()`
 
 var result = {
    startContainerPath: 'body>section;0',
    endContainerPath: 'body>section;1',
    startOffset: 2,
    endOffset: 5
 }

 var rendering = new Marklib.Rendering(document);
 
 rendering.renderWithResult(result);

Use-Cases

Develop

npm run develop or npm run tdd (to start karma in watch mode)

License

The MIT License (MIT)

Copyright (c) 2015 David Heidrich

Any contribution is welcome, just issue a pull-request or bug/feature if you found something :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].