How to use the @tryghost/mobiledoc-kit/dist/commonjs/mobiledoc-kit/parsers/dom.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
// 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
    if (!options.plugins) {
        options.plugins = createParserPlugins({
            createDocument(html) {
                return (new JSDOM(html)).window.document;
            }
        });
    }
    let parser = new DOMParser(new Builder(), options);
    let post = parser.parse(dom.window.document.body);

    // 3. Do something vaguely like serializePost, to render the mobiledoc internal format as mobiledoc
    // https://github.com/ErisDS/mobiledoc-kit/blob/master/src/js/editor/editor.js#L567
    let mobiledoc = mobiledocRenderer.render(post, '0.3.1');

    return mobiledoc;
};