Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/na2axl/deltoid.js

A Delta converter to HTML and plain text.
https://github.com/na2axl/deltoid.js

delta html javascript parser quill quill-delta quill-editor quilljs

Last synced: 7 days ago
JSON representation

A Delta converter to HTML and plain text.

Awesome Lists containing this project

README

        

# Deltoid.js
A Delta parser to HTML and plain text.

## Installation

### Browser
Just include `deltoid.js` in your web page:
```html

```
And then you can use the class `Deltoid` where you want

### Node.js
Install Deltoid in your project with this command:
```shell
npm install deltoid --save
```
And then you can require them later:
```js
var Deltoid = require('deltoid');
```

### Require.js
Deltoid can be accessed as an asynchronous module with require.js:
```js
require(['path/to/deltoid.js'], function (Deltoid) {
// Do your stuff...
});
```

## How to use ?
Once Deltoid is installed, to use it you just have to create a new instance of Deltoid and give it required parameters:
```js
var deltaParser = new Deltoid(delta, options);
```

* The `delta` parameter is the Delta to parse. It can be an `object` or a `string` which can be parsed to object.
* The `options` parameter is optional. It define the `tokens` to use when Deltoid will parse the Delta to HTML.

Supported tokens and their format:
```js
{
line: "

{content}
",
bold: "{content}",
italic: "{content}",
strike: "{content}",
underline: "{content}",
script: {
sub: "{content}",
super: "{content}"
},
list: {
ordered: "
    {content}
",
unordered: "
    {content}
",
item: "
  • {content}
  • "
    },
    header: [
    "",
    "

    {content}

    ",
    "

    {content}

    ",
    "

    {content}

    ",
    "

    {content}

    ",
    "
    {content}
    ",
    "
    {content}
    "
    ],
    link: "{content}",
    image: "{alt}",
    formula: "{formula}",
    blockquote: "
    {content}
    ",
    "code-block": "
    {content}
    "
    }
    ```

    ## Examples
    ```js
    var delta = {
    ops: [
    {
    insert: "Hello ",
    attributes: {
    bold: true,
    underline: true
    }
    },
    {
    insert: "world!",
    attributes: {
    italic: true
    }
    }
    ]
    };

    var d1 = new Deltoid(delta);
    var d2 = new Deltoid(delta, {
    tokens: {
    bold: "{content}",
    italic: "{content}",
    }
    })

    var parsed1 = d1.parse();
    var parsed2 = d2.parse();

    parsed1.toHTML(); // =>


    Hello world!

    parsed1.toPlainText(); // => Hello world!

    parsed2.toHTML(); // =>


    Hello world!

    parsed2.toPlainText(); // => Hello world!
    ```