Skip to content

Commit

Permalink
set data-subtype on all NPF block elements
Browse files Browse the repository at this point in the history
attributes now go data-block then data-subtype which i like more

also adds data-subtype to paywall-type block elements
  • Loading branch information
AprilSylph committed Nov 16, 2021
1 parent 47bfc69 commit dfc7a91
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lib/npf.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ const blockRenderers = {
'unordered-list-item': 'li'
})[subtype] || 'p');

if (subtype) Object.assign(element.dataset, { subtype });

element.append(...applyFormatting({ text, formatting }));

return element;
Expand Down Expand Up @@ -196,7 +194,10 @@ const blockRenderers = {
}
};

const renderBlock = block => blockRenderers[block.type](block).tap(element => { element.dataset.block = block.type; });
const renderBlock = block => blockRenderers[block.type](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

0 comments on commit dfc7a91

Please sign in to comment.