Skip to content

Commit

Permalink
add fallback renderers for blocks and attribution
Browse files Browse the repository at this point in the history
fixes #71
  • Loading branch information
AprilSylph committed Jun 28, 2023
1 parent 2916734 commit e2ec942
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/lib/npf.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,19 @@ const blockRenderers = {
Object.assign(document.createElement('summary'), { textContent: title }),
Object.assign(document.createElement('p'), { textContent: text })
));
},

default ({ type }) {
console.warn(`Unknown block type: "${type}"`);
return document.createElement('div');
}
};

const renderBlock = block => blockRenderers[block.type](block).tap(element => {
element.dataset.block = block.type;
if (block.subtype) element.dataset.subtype = block.subtype;
});
const renderBlock = block =>
(blockRenderers[block.type] || blockRenderers.default)(block).tap(element => {
element.dataset.block = block.type;
if (block.subtype) element.dataset.subtype = block.subtype;
});

const applyFormatting = ({ text, formatting = [] }) => {
if (!formatting.length) {
Expand Down Expand Up @@ -326,12 +332,18 @@ const attributionRenderers = {
}

return a;
},

default ({ type }) {
console.warn(`Unknown attribution type: "${type}"`);
return document.createElement('span');
}
};

const renderAttribution = attribution => attributionRenderers[attribution.type](attribution).tap(element => {
element.dataset.attribution = attribution.type;
});
const renderAttribution = attribution =>
(attributionRenderers[attribution.type] || attributionRenderers.default)(attribution).tap(element => {
element.dataset.attribution = attribution.type;
});

const ascendBy = (...funcs) => (negativeFirstItem, postiveFirstItem) => {
for (const func of funcs) {
Expand Down

0 comments on commit e2ec942

Please sign in to comment.