@tryghost/kg-parser-plugins
Advanced tools
Comparing version 3.0.8 to 3.0.9
@@ -7,3 +7,3 @@ 'use strict'; | ||
function fromKoenigCard$8() { | ||
function fromKoenigCard$7() { | ||
return function kgAudioCardToCard(node, builder, {addSection, nodeFinished}) { | ||
@@ -50,132 +50,2 @@ if (node.nodeType !== 1 || !node.classList.contains('kg-audio-card')) { | ||
function addFigCaptionToPayload(node, payload, {selector = 'figcaption', options}) { | ||
let figcaptions = Array.from(node.querySelectorAll(selector)); | ||
if (figcaptions.length) { | ||
figcaptions.forEach((caption) => { | ||
let cleanHtml = options.cleanBasicHtml(caption.innerHTML); | ||
payload.caption = payload.caption ? `${payload.caption} / ${cleanHtml}` : cleanHtml; | ||
caption.remove(); // cleanup this processed element | ||
}); | ||
} | ||
} | ||
function readImageAttributesFromNode(node) { | ||
const attrs = {}; | ||
if (node.src) { | ||
attrs.src = node.src; | ||
} | ||
if (node.width) { | ||
attrs.width = node.width; | ||
} else if (node.dataset && node.dataset.width) { | ||
attrs.width = parseInt(node.dataset.width, 10); | ||
} | ||
if (node.height) { | ||
attrs.height = node.height; | ||
} else if (node.dataset && node.dataset.height) { | ||
attrs.height = parseInt(node.dataset.height, 10); | ||
} | ||
if ((!node.width && !node.height) && node.getAttribute('data-image-dimensions')) { | ||
const [, width, height] = (/^(\d*)x(\d*)$/gi).exec(node.getAttribute('data-image-dimensions')); | ||
attrs.width = parseInt(width, 10); | ||
attrs.height = parseInt(height, 10); | ||
} | ||
if (node.alt) { | ||
attrs.alt = node.alt; | ||
} | ||
if (node.title) { | ||
attrs.title = node.title; | ||
} | ||
if (node.parentNode.tagName === 'A') { | ||
const href = node.parentNode.href; | ||
if (href !== attrs.src) { | ||
attrs.href = href; | ||
} | ||
} | ||
return attrs; | ||
} | ||
function fromKoenigCard$7(options) { | ||
return function kgBeforeAfterCardToCard(node, builder, {addSection, nodeFinished}) { | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-before-after-card')) { | ||
return; | ||
} | ||
const cardWidth = node.classList.contains('kg-width-full') ? 'full' : 'wide'; | ||
const images = node.querySelectorAll('img'); | ||
const beforeImage = images[1]; | ||
const afterImage = images[0]; | ||
if (!beforeImage || !afterImage) { | ||
return; | ||
} | ||
const payload = { | ||
cardWidth, | ||
beforeImage: { | ||
width: beforeImage.width, | ||
src: beforeImage.src | ||
}, | ||
afterImage: { | ||
width: afterImage.width, | ||
src: afterImage.src | ||
} | ||
}; | ||
addFigCaptionToPayload(node, payload, {options}); | ||
const cardSection = builder.createCardSection('before-after', payload); | ||
addSection(cardSection); | ||
nodeFinished(); | ||
}; | ||
} | ||
function fromJetpackCard(options) { | ||
return function jetpackJuxtaposeToCard(node, builder, {addSection, nodeFinished}) { | ||
if (node.nodeType !== 1 || !node.classList.contains('wp-block-jetpack-image-compare')) { | ||
return; | ||
} | ||
const cardWidth = 'wide'; | ||
const images = node.querySelectorAll('img'); | ||
const beforeImage = images[0]; | ||
const afterImage = images[1]; | ||
if (!beforeImage || !afterImage) { | ||
return; | ||
} | ||
const payload = { | ||
cardWidth, | ||
beforeImage: { | ||
width: 1000, | ||
src: beforeImage.src | ||
}, | ||
afterImage: { | ||
width: 1000, | ||
src: afterImage.src | ||
} | ||
}; | ||
addFigCaptionToPayload(node, payload, {options}); | ||
const cardSection = builder.createCardSection('before-after', payload); | ||
addSection(cardSection); | ||
nodeFinished(); | ||
}; | ||
} | ||
function getButtonText$1(node) { | ||
@@ -283,2 +153,58 @@ let buttonText = node.textContent; | ||
function addFigCaptionToPayload(node, payload, {selector = 'figcaption', options}) { | ||
let figcaptions = Array.from(node.querySelectorAll(selector)); | ||
if (figcaptions.length) { | ||
figcaptions.forEach((caption) => { | ||
let cleanHtml = options.cleanBasicHtml(caption.innerHTML); | ||
payload.caption = payload.caption ? `${payload.caption} / ${cleanHtml}` : cleanHtml; | ||
caption.remove(); // cleanup this processed element | ||
}); | ||
} | ||
} | ||
function readImageAttributesFromNode(node) { | ||
const attrs = {}; | ||
if (node.src) { | ||
attrs.src = node.src; | ||
} | ||
if (node.width) { | ||
attrs.width = node.width; | ||
} else if (node.dataset && node.dataset.width) { | ||
attrs.width = parseInt(node.dataset.width, 10); | ||
} | ||
if (node.height) { | ||
attrs.height = node.height; | ||
} else if (node.dataset && node.dataset.height) { | ||
attrs.height = parseInt(node.dataset.height, 10); | ||
} | ||
if ((!node.width && !node.height) && node.getAttribute('data-image-dimensions')) { | ||
const [, width, height] = (/^(\d*)x(\d*)$/gi).exec(node.getAttribute('data-image-dimensions')); | ||
attrs.width = parseInt(width, 10); | ||
attrs.height = parseInt(height, 10); | ||
} | ||
if (node.alt) { | ||
attrs.alt = node.alt; | ||
} | ||
if (node.title) { | ||
attrs.title = node.title; | ||
} | ||
if (node.parentNode.tagName === 'A') { | ||
const href = node.parentNode.href; | ||
if (href !== attrs.src) { | ||
attrs.href = href; | ||
} | ||
} | ||
return attrs; | ||
} | ||
// Helpers | ||
@@ -1187,4 +1113,2 @@ | ||
return [ | ||
fromKoenigCard$7(options), | ||
fromJetpackCard(options), | ||
fromNFTEmbed(), | ||
@@ -1199,3 +1123,3 @@ fromMixtape(options), | ||
fromKoenigCard$2(), | ||
fromKoenigCard$8(), | ||
fromKoenigCard$7(), | ||
fromKoenigCard$1(), | ||
@@ -1202,0 +1126,0 @@ fromKoenigCard$5(), |
import cleanBasicHtml from '@tryghost/kg-clean-basic-html'; | ||
function fromKoenigCard$8() { | ||
function fromKoenigCard$7() { | ||
return function kgAudioCardToCard(node, builder, _ref) { | ||
@@ -47,123 +47,2 @@ let { | ||
function addFigCaptionToPayload(node, payload, _ref) { | ||
let { | ||
selector = 'figcaption', | ||
options | ||
} = _ref; | ||
let figcaptions = Array.from(node.querySelectorAll(selector)); | ||
if (figcaptions.length) { | ||
figcaptions.forEach(caption => { | ||
let cleanHtml = options.cleanBasicHtml(caption.innerHTML); | ||
payload.caption = payload.caption ? `${payload.caption} / ${cleanHtml}` : cleanHtml; | ||
caption.remove(); // cleanup this processed element | ||
}); | ||
} | ||
} | ||
function readImageAttributesFromNode(node) { | ||
const attrs = {}; | ||
if (node.src) { | ||
attrs.src = node.src; | ||
} | ||
if (node.width) { | ||
attrs.width = node.width; | ||
} else if (node.dataset && node.dataset.width) { | ||
attrs.width = parseInt(node.dataset.width, 10); | ||
} | ||
if (node.height) { | ||
attrs.height = node.height; | ||
} else if (node.dataset && node.dataset.height) { | ||
attrs.height = parseInt(node.dataset.height, 10); | ||
} | ||
if (!node.width && !node.height && node.getAttribute('data-image-dimensions')) { | ||
const [, width, height] = /^(\d*)x(\d*)$/gi.exec(node.getAttribute('data-image-dimensions')); | ||
attrs.width = parseInt(width, 10); | ||
attrs.height = parseInt(height, 10); | ||
} | ||
if (node.alt) { | ||
attrs.alt = node.alt; | ||
} | ||
if (node.title) { | ||
attrs.title = node.title; | ||
} | ||
if (node.parentNode.tagName === 'A') { | ||
const href = node.parentNode.href; | ||
if (href !== attrs.src) { | ||
attrs.href = href; | ||
} | ||
} | ||
return attrs; | ||
} | ||
function fromKoenigCard$7(options) { | ||
return function kgBeforeAfterCardToCard(node, builder, _ref) { | ||
let { | ||
addSection, | ||
nodeFinished | ||
} = _ref; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-before-after-card')) { | ||
return; | ||
} | ||
const cardWidth = node.classList.contains('kg-width-full') ? 'full' : 'wide'; | ||
const images = node.querySelectorAll('img'); | ||
const beforeImage = images[1]; | ||
const afterImage = images[0]; | ||
if (!beforeImage || !afterImage) { | ||
return; | ||
} | ||
const payload = { | ||
cardWidth, | ||
beforeImage: { | ||
width: beforeImage.width, | ||
src: beforeImage.src | ||
}, | ||
afterImage: { | ||
width: afterImage.width, | ||
src: afterImage.src | ||
} | ||
}; | ||
addFigCaptionToPayload(node, payload, { | ||
options | ||
}); | ||
const cardSection = builder.createCardSection('before-after', payload); | ||
addSection(cardSection); | ||
nodeFinished(); | ||
}; | ||
} | ||
function fromJetpackCard(options) { | ||
return function jetpackJuxtaposeToCard(node, builder, _ref2) { | ||
let { | ||
addSection, | ||
nodeFinished | ||
} = _ref2; | ||
if (node.nodeType !== 1 || !node.classList.contains('wp-block-jetpack-image-compare')) { | ||
return; | ||
} | ||
const cardWidth = 'wide'; | ||
const images = node.querySelectorAll('img'); | ||
const beforeImage = images[0]; | ||
const afterImage = images[1]; | ||
if (!beforeImage || !afterImage) { | ||
return; | ||
} | ||
const payload = { | ||
cardWidth, | ||
beforeImage: { | ||
width: 1000, | ||
src: beforeImage.src | ||
}, | ||
afterImage: { | ||
width: 1000, | ||
src: afterImage.src | ||
} | ||
}; | ||
addFigCaptionToPayload(node, payload, { | ||
options | ||
}); | ||
const cardSection = builder.createCardSection('before-after', payload); | ||
addSection(cardSection); | ||
nodeFinished(); | ||
}; | ||
} | ||
function getButtonText$1(node) { | ||
@@ -264,2 +143,52 @@ let buttonText = node.textContent; | ||
function addFigCaptionToPayload(node, payload, _ref) { | ||
let { | ||
selector = 'figcaption', | ||
options | ||
} = _ref; | ||
let figcaptions = Array.from(node.querySelectorAll(selector)); | ||
if (figcaptions.length) { | ||
figcaptions.forEach(caption => { | ||
let cleanHtml = options.cleanBasicHtml(caption.innerHTML); | ||
payload.caption = payload.caption ? `${payload.caption} / ${cleanHtml}` : cleanHtml; | ||
caption.remove(); // cleanup this processed element | ||
}); | ||
} | ||
} | ||
function readImageAttributesFromNode(node) { | ||
const attrs = {}; | ||
if (node.src) { | ||
attrs.src = node.src; | ||
} | ||
if (node.width) { | ||
attrs.width = node.width; | ||
} else if (node.dataset && node.dataset.width) { | ||
attrs.width = parseInt(node.dataset.width, 10); | ||
} | ||
if (node.height) { | ||
attrs.height = node.height; | ||
} else if (node.dataset && node.dataset.height) { | ||
attrs.height = parseInt(node.dataset.height, 10); | ||
} | ||
if (!node.width && !node.height && node.getAttribute('data-image-dimensions')) { | ||
const [, width, height] = /^(\d*)x(\d*)$/gi.exec(node.getAttribute('data-image-dimensions')); | ||
attrs.width = parseInt(width, 10); | ||
attrs.height = parseInt(height, 10); | ||
} | ||
if (node.alt) { | ||
attrs.alt = node.alt; | ||
} | ||
if (node.title) { | ||
attrs.title = node.title; | ||
} | ||
if (node.parentNode.tagName === 'A') { | ||
const href = node.parentNode.href; | ||
if (href !== attrs.src) { | ||
attrs.href = href; | ||
} | ||
} | ||
return attrs; | ||
} | ||
// Helpers | ||
@@ -1150,3 +1079,3 @@ | ||
} | ||
return [fromKoenigCard$7(options), fromJetpackCard(options), fromNFTEmbed(), fromMixtape(options), fromKoenigCard$3(), fromKoenigCard$6(), fromWordpressButton(), fromSubstackButton(), kgCalloutCardToCard, kgToggleCardToCard, fromKoenigCard$2(), fromKoenigCard$8(), fromKoenigCard$1(), fromKoenigCard$5(), fromKoenigCard$4(), blockquoteWithChildren, fromBr(), removeLeadingNewline, fromKoenigCard(options), fromFigureBlockquote(options), | ||
return [fromNFTEmbed(), fromMixtape(options), fromKoenigCard$3(), fromKoenigCard$6(), fromWordpressButton(), fromSubstackButton(), kgCalloutCardToCard, kgToggleCardToCard, fromKoenigCard$2(), fromKoenigCard$7(), fromKoenigCard$1(), fromKoenigCard$5(), fromKoenigCard$4(), blockquoteWithChildren, fromBr(), removeLeadingNewline, fromKoenigCard(options), fromFigureBlockquote(options), | ||
// I think these can contain images | ||
@@ -1153,0 +1082,0 @@ fromGrafGallery(options), fromSqsGallery(options), fromFigure(options), fromImg(), hrToCard, figureToCodeCard, preCodeToCard, fromFigureIframe(options), fromIframe(), |
@@ -15,3 +15,2 @@ /* global DOMParser, window */ | ||
import * as audioCard from './cards/audio'; | ||
import * as beforeAfterCard from './cards/before-after'; | ||
import * as buttonCard from './cards/button'; | ||
@@ -294,4 +293,2 @@ import * as embedCard from './cards/embed'; | ||
return [ | ||
beforeAfterCard.fromKoenigCard(options), | ||
beforeAfterCard.fromJetpackCard(options), | ||
embedCard.fromNFTEmbed(), | ||
@@ -298,0 +295,0 @@ embedCard.fromMixtape(options), |
{ | ||
"name": "@tryghost/kg-parser-plugins", | ||
"version": "3.0.8", | ||
"version": "3.0.9", | ||
"repository": "https://github.com/TryGhost/Koenig/tree/master/packages/kg-parser-plugins", | ||
@@ -47,3 +47,3 @@ "author": "Ghost Foundation", | ||
}, | ||
"gitHead": "371c47945186e2608cc11ff00d1a089778a2733f" | ||
"gitHead": "05916bba28b3c18ea73afbe4f22d49b446b5c145" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
194229
19
2894