How to use the @tryghost/mobiledoc-kit/dist/commonjs/mobiledoc-kit/renderers/mobiledoc.default function in @tryghost/mobiledoc-kit

To help you get started, we’ve selected a few @tryghost/mobiledoc-kit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gazooka / GhostInAzureWebApp / node_modules / @tryghost / html-to-mobiledoc / lib / converter.js View on Github external
const DOMParser = require('@tryghost/mobiledoc-kit/dist/commonjs/mobiledoc-kit/parsers/dom').default;
const Builder = require('@tryghost/mobiledoc-kit/dist/commonjs/mobiledoc-kit/models/post-node-builder').default;
const mobiledocRenderer = require('@tryghost/mobiledoc-kit/dist/commonjs/mobiledoc-kit/renderers/mobiledoc').default;
const {createParserPlugins} = require('@tryghost/kg-parser-plugins');
const {JSDOM} = require('jsdom');

module.exports.toMobiledoc = (html, options = {}) => {
    // 1. sanitize HTML
    // @TODO: what sanitisations are needed?
    let sanitizedHTML = html;

    // 2. Do something vaguely like loadPost
    // https://github.com/ErisDS/mobiledoc-kit/blob/master/src/js/editor/editor.js#L193

    // 2.a. Parse our HTML and convert to a DOM with same API as browser
    let dom = new JSDOM(`${sanitizedHTML}`);

    // 2.b. Use Mobiledoc-kit's own DOM Parser to convert the DOM into mobiledoc's internal format
    // We use our parser plugins by default, but this is extensible