Commit a5cd53da authored by chris's avatar chris

create helpers file for editoria schema

parent b3ecc46e
export { default as DefaultSchema } from "./src/DefaultSchema";
export { default as EditoriaSchema } from "./src/EditoriaSchema";
export { default as EditoriaSchema } from "./src/editoria/EditoriaSchema";
export { default as XpubSchema } from "./src/XpubSchema";
import { parseFormatList, parseTracks, blockLevelToDOM } from "./helpers";
// Npdes
const pDOM = ["p", 0],
brDOM = ["br"],
......@@ -7,56 +9,6 @@ const pDOM = ["p", 0],
const emDOM = ["em", 0],
strongDOM = ["strong", 0],
codeDOM = ["code", 0];
const parseFormatList = str => {
if (!str) {
return [];
}
let formatList;
try {
formatList = JSON.parse(str);
} catch (error) {
return [];
}
if (!Array.isArray(formatList)) {
return [];
}
return formatList.filter(format => typeof format === "string"); // ensure there are only strings in list
};
const parseTracks = str => {
if (!str) {
return [];
}
let tracks;
try {
tracks = JSON.parse(str);
} catch (error) {
return [];
}
if (!Array.isArray(tracks)) {
return [];
}
return tracks.filter(
(
track // ensure required fields are present
) =>
track.hasOwnProperty("user") &&
track.hasOwnProperty("username") &&
track.hasOwnProperty("date")
);
};
const blockLevelToDOM = node => {
const attrs = node.attrs.track.length
? {
class: node.attrs.class,
"data-track": JSON.stringify(node.attrs.track)
}
: { class: node.attrs.class };
return attrs;
};
const EditoriaSchema = {
nodes: {
doc: {
......
const parseFormatList = str => {
if (!str) {
return [];
}
let formatList;
try {
formatList = JSON.parse(str);
} catch (error) {
return [];
}
if (!Array.isArray(formatList)) {
return [];
}
return formatList.filter(format => typeof format === "string"); // ensure there are only strings in list
};
const parseTracks = str => {
if (!str) {
return [];
}
let tracks;
try {
tracks = JSON.parse(str);
} catch (error) {
return [];
}
if (!Array.isArray(tracks)) {
return [];
}
return tracks.filter(
(
track // ensure required fields are present
) =>
track.hasOwnProperty("user") &&
track.hasOwnProperty("username") &&
track.hasOwnProperty("date")
);
};
const blockLevelToDOM = node => {
const attrs = node.attrs.track.length
? {
class: node.attrs.class,
"data-track": JSON.stringify(node.attrs.track)
}
: { class: node.attrs.class };
return attrs;
};
export { parseFormatList, parseTracks, blockLevelToDOM };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment