Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

editorjs-html-examples

node v8.17.0
version: 2.0.0
endpointsharetweet
This is a playground to test JavaScript. It runs a completely standard copy of Node.js on a virtual server created just for you. Every one of npm’s 300,000+ packages are pre-installed, so try it out:
// Import editorjs-html library const edjsHTML = require('editorjs-html'); // Initialise a parser object const edjsParser = edjsHTML(); // fetch editorjs cleandata, I will add some sample clean data for this tutorial const cleanData = { blocks: [{ type: 'header', data: { text: 'This is a sample Header', level: 2 } }] } // parse cleanData to HTML const html = edjsParser.parse(cleanData); // display generated HTML, or use it as you'd like. console.log(html); // Press Shift+Enter to view the result.
// Parse a single block const blockHTML = edjsParser.parseBlock(cleanData.blocks[0]); console.log(blockHTML);
// Defining a custom Block Function function customParser({data}){ return `<custom> ${data.text} </custom>` } // You need to re-initialize edjsParser Instance, or pass it to earlier instance. // The `edjsParser` defined above will throw an error since parser for `custom` block type is not defined. const edjsParser2 = edjsHTML({custom: customParser}); const cleanDataWithCustomBlock = { blocks: [{ type: 'custom', data: { text: 'This is a sample Header', level: 2 } }] } console.log(edjsParser2.parse(cleanDataWithCustomBlock));
Loading…

no comments

    sign in to comment