EditorJS Parser is a small tool used to format blocks created from Editor.js
Use the package manager npm
npm install @mattnick/editorjsparser
const EditorJsParser = require('@mattnick/editorjsparser');
const parser = new EditorJsParser();
var blocks = [{
type: "paragraph",
data: {
"text": "hello world"
}
}];
blocks.forEach((row)=>{
var formatted_block = parser.parse(row,"my-custom-class");
console.log(formatted_block);
})
// formatted_block
/*
{
is_empty: false,
text: "hello world",
html: '<p class="my-custom-class">hello world</p>'
}
*/
- paragraph
- header
- list
- image
- embed
- quote
- delimiter
- poll
If a block does not match one of these types then it will pass straight through untouched.