Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
fix: Improve types for paragraphs handling
Browse files Browse the repository at this point in the history
BREAKING CHANGE: is-paragraph becomes is-text
  • Loading branch information
kptdobe committed Mar 7, 2019
1 parent 406a68c commit f4cb9fb
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/html/get-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@ function sectiontype(section) {
if (type === 'paragraph' && pChildren && pChildren.length > 0) {
// if child is a paragraph, check its children, it might contain an image or a list
// which are always wrapped by default.
pChildren.forEach(({ type: subType }) => {
// exclude text nodes which are default paragraph content
if (subType !== 'text') {
const mycount = mycounter[subType] || 0;
mycounter[subType] = mycount + 1;
node.data.types.push(`is-${subType}`);
pChildren.forEach((p) => {
let prefix = 'has';
if (p.type === 'text') {
// do not count "empty" paragraphs
if (p.value === '\n' || p.value === '') return;

// paragraph with type text "is" a text
prefix = 'is';
}
if (!node.data.types.includes(`${prefix}-${p.type}`)) {
node.data.types.push(`${prefix}-${p.type}`);
}
const mycount = mycounter[p.type] || 0;
mycounter[p.type] = mycount + 1;
});
}

Expand Down

0 comments on commit f4cb9fb

Please sign in to comment.