Giter VIP home page Giter VIP logo

deltaconvert's Introduction

deltaconvert

Node.js CI

Convert quill delta objects to and from plain text, HTML, and NPF.

Installation

npm install deltaconvert

Example

const {deltaToHtml} = require('deltaconvert');
deltaToHtml({
    ops: [
        {insert: 'Gandalf', attributes: {bold: true}},
        {insert: ' the '},
        {insert: 'Grey', attributes: {color: '#cccccc'}},
        {insert: '\n'}
    ]
});
/** 
 * Returns
 * <p><b>Gandalf</b> the <span style="color:#cccccc;">Grey</span></p>
 */

Reference

deltaToHtml

Convert a delta object to html. The resulting HTML can be inserted into an existing website, it will have no <html>, <body>, etc. tags. {insert: {divider:true}} objects will be converted to <hr> tags.

deltaToNpf

Convert a delta object to tumblr's NPF format. Headings of level >2 will be converted to bold text. Images will be inserted without any size information. Videos will be inserted as media object if we can guess the mime type from the url, otherwise as plain links. Code blocks will be converted to text objects with subtype chat, which should be rendered with a monospace font.

deltaToText

Convert a delta object to plain text. Formatting, images, etc. will be ignored.

deltaToSsml

Convert a delta object to the Speech Synthesis Markup Language. Images will be converted to elements containing the alt text. Other media and special elements will be ignored.

htmlToDelta

Convert a html document or snippet to a quill delta document. Note that only inline styles are supported. <style> tags and external stylesheets will be ignored. <hr> tags will be converted to {insert: {divider: true}} objects. <iframe>s with the ql-video class will be treated as videos.

npfToDelta

Convert a tumblr NPF to a quill delta. Blog references aren't supported yet.

textToDelta

Convert plain text to a delta object with no formatting information.

htmlToNpf

Convert a html document or snippet to tumblr's NPF format. This is a shorthand for deltaToNpf(htmlToDelta(...)).

npfToHtml

Convert a tumblr NPF to html. This is a shorthand for deltaToNpf(htmlToDelta(...)). Note that blockquotes with indent_level > 1 will be converted to plain <blockquote>s, not nested <blockquote>s. This may change in a future release.

Contributing

If you want to request a feature, report a bug, or contribute in some other way, please file an issue here. Thanks!

deltaconvert's People

Contributors

jfhr avatar

Watchers

 avatar

deltaconvert's Issues

Add video support

Videos should be supported in deltaToHtml, deltaToNpf, htmlToDelta, and npfToDelta.

Considerations:

  • HTML supports multiple <src> elements. We could always pick the first one
  • NPF supports multiple ways to specify a source: media { type, url } for videos that can be played natively, embed_html, embed_iframe, embed_url and url. url would always work but we could add extra logic for some known providers (e.g. youtube)
  • Quill by default inserts videos is <iframe>s with class ql-video. We should treat these like <video>s, using the <src> attribute as the video url

Todo:

  • Add unit tests
    • deltaToHtml
    • htmlToDelta
    • npfToDelta
    • deltaToNpf
  • Implement stuff
  • Add bugs
  • Fix bugs

Support code blocks

#6 was about inline code, this one is about code blocks

Objects of the form { insert: "\n", attributes: { "code-block": true, /*...*/ } } should be converted into <pre><code>foo</code></pre>, or the equivalent on other platforms

For tumblr npf, we can use the chat subtype for this (see #7)

Support code tags

Objects of the form { insert: "foo", attributes: { code: true, /*...*/ } } should be converted into <code>foo</code>, or the equivalent on other platforms

Add deltaToSsml

SSML is an XML format for speech synthesis. See here.

At a minimum we should support:

  • top-level <speak> element
  • bold text to <emphasis> (only full sentences)
  • paragraphs to <p> elements
  • maybe sentences to <s> elements, although most TTS engines should be able to split sentences on their own

I don't see the use case for the reverse (ssmlToDelta), so that's not part of this PR

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.