Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions build/Parser.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ var edjsParser = function () {
codepen: "<div class=\"embed\"><iframe <%data.length%> scrolling=\"no\" src=\"<%data.embed%>\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"></iframe></div>",
defaultMarkup: "<div class=\"embed\"><iframe src=\"<%data.embed%>\" <%data.length%> class=\"embed-unknown\" allowfullscreen=\"true\" frameborder=\"0\" ></iframe></div>"
};

var processNestedLists = function testNest(style, data) {
var result = data.reduce(function (acc, res) {
if (res.items.length > 0) return acc + "<li>".concat(res.content, "</li>") + testNest(style, res.items);else return acc + "<li>".concat(res.content, "</li>");
}, "");
return "<".concat(style, ">").concat(result, "</").concat(style, ">");
};

var defaultParsers = {
paragraph: function paragraph(data, config) {
return "<p class=\"".concat(config.paragraph.pClass, "\"> ").concat(data.text, " </p>");
Expand All @@ -53,11 +61,13 @@ var edjsParser = function () {
return "<h".concat(data.level, ">").concat(data.text, "</h").concat(data.level, ">");
},
list: function list(data) {
var type = data.style === "ordered" ? "ol" : "ul";
var items = data.items.reduce(function (acc, item) {
return acc + "<li>".concat(item, "</li>");
var style = data.style === "ordered" ? "ol" : "ul";
var items = data.items.reduce(function (acc, res) {
if (res.items.length > 0) {
return acc + "<li>".concat(res.content, "</li>") + processNestedLists(style, res.items);
} else return acc + "<li>".concat(res.content, "</li>");
}, "");
return "<".concat(type, ">").concat(items, "</").concat(type, ">");
return "<".concat(style, ">").concat(items, "</").concat(style, ">");
},
quote: function quote(data, config) {
var alignment = "";
Expand Down Expand Up @@ -179,6 +189,8 @@ var edjsParser = function () {
var html = EditorJsObject.blocks.map(function (block) {
var markup = _this.parseBlock(block);

console.log(markup);

if (markup instanceof Error) {
return ""; // parser for this kind of block doesn't exist
}
Expand Down
22 changes: 17 additions & 5 deletions build/Parser.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ var embedMarkups = {
codepen: "<div class=\"embed\"><iframe <%data.length%> scrolling=\"no\" src=\"<%data.embed%>\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"></iframe></div>",
defaultMarkup: "<div class=\"embed\"><iframe src=\"<%data.embed%>\" <%data.length%> class=\"embed-unknown\" allowfullscreen=\"true\" frameborder=\"0\" ></iframe></div>"
};

var processNestedLists = function testNest(style, data) {
var result = data.reduce(function (acc, res) {
if (res.items.length > 0) return acc + "<li>".concat(res.content, "</li>") + testNest(style, res.items);else return acc + "<li>".concat(res.content, "</li>");
}, "");
return "<".concat(style, ">").concat(result, "</").concat(style, ">");
};

var defaultParsers = {
paragraph: function paragraph(data, config) {
return "<p class=\"".concat(config.paragraph.pClass, "\"> ").concat(data.text, " </p>");
Expand All @@ -50,11 +58,13 @@ var defaultParsers = {
return "<h".concat(data.level, ">").concat(data.text, "</h").concat(data.level, ">");
},
list: function list(data) {
var type = data.style === "ordered" ? "ol" : "ul";
var items = data.items.reduce(function (acc, item) {
return acc + "<li>".concat(item, "</li>");
var style = data.style === "ordered" ? "ol" : "ul";
var items = data.items.reduce(function (acc, res) {
if (res.items.length > 0) {
return acc + "<li>".concat(res.content, "</li>") + processNestedLists(style, res.items);
} else return acc + "<li>".concat(res.content, "</li>");
}, "");
return "<".concat(type, ">").concat(items, "</").concat(type, ">");
return "<".concat(style, ">").concat(items, "</").concat(style, ">");
},
quote: function quote(data, config) {
var alignment = "";
Expand Down Expand Up @@ -176,6 +186,8 @@ var edjsParser = /*#__PURE__*/function () {
var html = EditorJsObject.blocks.map(function (block) {
var markup = _this.parseBlock(block);

console.log(markup);

if (markup instanceof Error) {
return ""; // parser for this kind of block doesn't exist
}
Expand All @@ -202,4 +214,4 @@ var edjsParser = /*#__PURE__*/function () {
return edjsParser;
}();

export default edjsParser;
export { edjsParser as default };
26 changes: 19 additions & 7 deletions build/Parser.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ const embedMarkups = {
defaultMarkup: `<div class="embed"><iframe src="<%data.embed%>" <%data.length%> class="embed-unknown" allowfullscreen="true" frameborder="0" ></iframe></div>`,
};

const processNestedLists = function testNest(style , data) {
let result = data.reduce((acc, res) => {
if (res.items.length > 0)
return acc + `<li>${res.content}</li>` + testNest(style, res.items)
else
return acc + `<li>${res.content}</li>`
}, "");
return `<${style}>${result}</${style}>`
};

var defaultParsers = {
paragraph: function(data, config) {
return `<p class="${config.paragraph.pClass}"> ${data.text} </p>`;
Expand All @@ -53,14 +63,15 @@ var defaultParsers = {
},

list: function(data) {
const type = data.style === "ordered" ? "ol" : "ul";
const items = data.items.reduce(
(acc, item) => acc + `<li>${item}</li>`,
""
);
return `<${type}>${items}</${type}>`;
const style = data.style === "ordered" ? "ol" : "ul";
let items = data.items.reduce((acc, res) => {
if (res.items.length > 0) {
return acc + `<li>${res.content}</li>` + processNestedLists(style, res.items);
}else
return acc + `<li>${res.content}</li>`
}, "");
return `<${style}>${items}</${style}>`
},

quote: function(data, config) {
let alignment = "";
if (config.quote.applyAlignment) {
Expand Down Expand Up @@ -175,6 +186,7 @@ class edjsParser {
parse(EditorJsObject) {
const html = EditorJsObject.blocks.map((block) => {
const markup = this.parseBlock(block);
console.log(markup);
if (markup instanceof Error) {
return ""; // parser for this kind of block doesn't exist
}
Expand Down
Loading