@tryghost/kg-parser-plugins
Advanced tools
Comparing version 2.12.7 to 2.12.8
@@ -9,7 +9,5 @@ import cleanBasicHtml from '@tryghost/kg-clean-basic-html'; | ||
} = _ref; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-audio-card')) { | ||
return; | ||
} | ||
const titleNode = node.querySelector('.kg-audio-title'); | ||
@@ -23,7 +21,5 @@ const audioNode = node.querySelector('.kg-audio-player-container audio'); | ||
const durationText = durationNode && durationNode.innerHTML.trim(); | ||
if (!audioSrc) { | ||
return; | ||
} | ||
const payload = { | ||
@@ -33,7 +29,5 @@ src: audioSrc, | ||
}; | ||
if (thumbnailSrc) { | ||
payload.thumbnailSrc = thumbnailSrc; | ||
} | ||
if (durationText) { | ||
@@ -44,9 +38,8 @@ const { | ||
} = durationText.split(':'); | ||
try { | ||
payload.duration = parseInt(minutes) * 60 + parseInt(seconds); | ||
} catch (e) {// ignore duration | ||
} catch (e) { | ||
// ignore duration | ||
} | ||
} | ||
const cardSection = builder.createCardSection('audio', payload); | ||
@@ -64,3 +57,2 @@ addSection(cardSection); | ||
let figcaptions = Array.from(node.querySelectorAll(selector)); | ||
if (figcaptions.length) { | ||
@@ -74,9 +66,8 @@ figcaptions.forEach(caption => { | ||
} | ||
function readImageAttributesFromNode(node) { | ||
const attrs = {}; | ||
if (node.src) { | ||
attrs.src = node.src; | ||
} | ||
if (node.width) { | ||
@@ -87,3 +78,2 @@ attrs.width = node.width; | ||
} | ||
if (node.height) { | ||
@@ -94,3 +84,2 @@ attrs.height = node.height; | ||
} | ||
if (!node.width && !node.height && node.getAttribute('data-image-dimensions')) { | ||
@@ -101,14 +90,10 @@ const [, width, height] = /^(\d*)x(\d*)$/gi.exec(node.getAttribute('data-image-dimensions')); | ||
} | ||
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) { | ||
@@ -118,3 +103,2 @@ attrs.href = href; | ||
} | ||
return attrs; | ||
@@ -129,7 +113,5 @@ } | ||
} = _ref; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-before-after-card')) { | ||
return; | ||
} | ||
const cardWidth = node.classList.contains('kg-width-full') ? 'full' : 'wide'; | ||
@@ -139,7 +121,5 @@ const images = node.querySelectorAll('img'); | ||
const afterImage = images[0]; | ||
if (!beforeImage || !afterImage) { | ||
return; | ||
} | ||
const payload = { | ||
@@ -170,7 +150,5 @@ cardWidth, | ||
} = _ref2; | ||
if (node.nodeType !== 1 || !node.classList.contains('wp-block-jetpack-image-compare')) { | ||
return; | ||
} | ||
const cardWidth = 'wide'; | ||
@@ -180,7 +158,5 @@ const images = node.querySelectorAll('img'); | ||
const afterImage = images[1]; | ||
if (!beforeImage || !afterImage) { | ||
return; | ||
} | ||
const payload = { | ||
@@ -208,10 +184,7 @@ cardWidth, | ||
let buttonText = node.textContent; | ||
if (buttonText) { | ||
buttonText = buttonText.replace(/\n/g, ' ').replace(/\s+/g, ' ').trim(); | ||
} | ||
return buttonText; | ||
} | ||
function fromKoenigCard$6() { | ||
@@ -223,7 +196,5 @@ return function kgButtonCardToCard(node, builder, _ref) { | ||
} = _ref; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-button-card')) { | ||
return; | ||
} | ||
const alignment = node.classList.contains('kg-align-center') ? 'center' : 'left'; | ||
@@ -233,7 +204,5 @@ const anchor = node.querySelector('a'); | ||
const buttonText = getButtonText$1(anchor); | ||
if (!buttonUrl || !buttonText) { | ||
return; | ||
} | ||
const payload = { | ||
@@ -255,20 +224,14 @@ alignment, | ||
} = _ref2; | ||
if (node.nodeType !== 1 || !node.classList.contains('wp-block-button__link')) { | ||
return; | ||
} | ||
const buttonUrl = node.href; | ||
const buttonText = getButtonText$1(node); | ||
if (!buttonUrl || !buttonText) { | ||
return; | ||
} | ||
let alignment = 'left'; | ||
if (node.closest('.is-content-justification-center, .is-content-justification-right')) { | ||
alignment = 'center'; | ||
} | ||
const payload = { | ||
@@ -290,22 +253,18 @@ alignment, | ||
} = _ref3; | ||
if (node.nodeType !== 1 || !node.classList.contains('button')) { | ||
return; | ||
} // substack has .button-wrapper elems with a data-attrs JSON object with `url` and `text` | ||
} | ||
// substack has .button-wrapper elems with a data-attrs JSON object with `url` and `text` | ||
// we're not using that in favour of grabbing the anchor element directly for simplicity | ||
const anchor = node.tagName === 'A' ? node : node.querySelector('a'); | ||
if (!anchor) { | ||
return; | ||
} | ||
const buttonUrl = anchor.href; | ||
const buttonText = getButtonText$1(anchor); | ||
if (!buttonUrl || !buttonText) { | ||
return; | ||
} | ||
const payload = { | ||
@@ -323,2 +282,4 @@ alignment: 'center', | ||
// Helpers | ||
function _createPayloadForIframe(iframe) { | ||
@@ -329,9 +290,8 @@ // If we don't have a src Or it's not an absolute URL, we can't handle this | ||
return; | ||
} // if it's a schemaless URL, convert to https | ||
} | ||
// if it's a schemaless URL, convert to https | ||
if (iframe.src.match(/^\/\//)) { | ||
iframe.src = `https:${iframe.src}`; | ||
} | ||
let payload = { | ||
@@ -342,4 +302,5 @@ url: iframe.src | ||
return payload; | ||
} // Plugins | ||
} | ||
// Plugins | ||
@@ -352,31 +313,29 @@ function fromMixtape(options) { | ||
} = _ref; | ||
if (node.nodeType !== 1 || node.tagName !== 'DIV' || !node.className.match(/graf--mixtapeEmbed/)) { | ||
return; | ||
} // Grab the relevant elements - Anchor wraps most of the data | ||
} | ||
// Grab the relevant elements - Anchor wraps most of the data | ||
let anchorElement = node.querySelector('.markup--mixtapeEmbed-anchor'); | ||
let titleElement = anchorElement.querySelector('.markup--mixtapeEmbed-strong'); | ||
let descElement = anchorElement.querySelector('.markup--mixtapeEmbed-em'); // Image is a top level field inside it's own a tag | ||
let descElement = anchorElement.querySelector('.markup--mixtapeEmbed-em'); | ||
// Image is a top level field inside it's own a tag | ||
let imgElement = node.querySelector('.mixtapeImage'); | ||
let imgElement = node.querySelector('.mixtapeImage'); // Grab individual values from the elements | ||
// Grab individual values from the elements | ||
let url = anchorElement.href; | ||
let title = ''; | ||
let description = ''; | ||
if (titleElement && titleElement.innerHTML) { | ||
title = options.cleanBasicHtml(titleElement.innerHTML); // Cleanup anchor so we can see what's left now that we've processed title | ||
title = options.cleanBasicHtml(titleElement.innerHTML); | ||
// Cleanup anchor so we can see what's left now that we've processed title | ||
anchorElement.removeChild(titleElement); | ||
} | ||
if (descElement && descElement.innerHTML) { | ||
description = options.cleanBasicHtml(descElement.innerHTML); // Cleanup anchor so we can see what's left now that we've processed description | ||
description = options.cleanBasicHtml(descElement.innerHTML); | ||
// Cleanup anchor so we can see what's left now that we've processed description | ||
anchorElement.removeChild(descElement); | ||
} // // Format our preferred structure. | ||
} | ||
// // Format our preferred structure. | ||
let metadata = { | ||
@@ -386,16 +345,15 @@ url, | ||
description | ||
}; // Publisher is the remaining text in the anchor, once title & desc are removed | ||
}; | ||
// Publisher is the remaining text in the anchor, once title & desc are removed | ||
let publisher = options.cleanBasicHtml(anchorElement.innerHTML); | ||
if (publisher) { | ||
metadata.publisher = publisher; | ||
} // Image is optional, | ||
} | ||
// Image is optional, | ||
// The element usually still exists with an additional has.mixtapeImage--empty class and has no background image | ||
if (imgElement && imgElement.style['background-image']) { | ||
metadata.thumbnail = imgElement.style['background-image'].match(/url\(([^)]*?)\)/)[1]; | ||
} | ||
let payload = { | ||
@@ -416,19 +374,13 @@ url, | ||
} = _ref2; | ||
if (node.nodeType !== 1 || node.tagName !== 'FIGURE') { | ||
return; | ||
} | ||
let iframe = node.querySelector('iframe'); | ||
if (!iframe) { | ||
return; | ||
} | ||
let payload = _createPayloadForIframe(iframe); | ||
if (!payload) { | ||
return; | ||
} | ||
addFigCaptionToPayload(node, payload, { | ||
@@ -448,13 +400,9 @@ options | ||
} = _ref3; | ||
if (node.nodeType !== 1 || node.tagName !== 'IFRAME') { | ||
return; | ||
} | ||
let payload = _createPayloadForIframe(node); | ||
if (!payload) { | ||
return; | ||
} | ||
let cardSection = builder.createCardSection('embed', payload); | ||
@@ -471,20 +419,16 @@ addSection(cardSection); | ||
} = _ref4; | ||
if (node.nodeType !== 1 || node.tagName !== 'FIGURE') { | ||
return; | ||
} | ||
let blockquote = node.querySelector('blockquote'); | ||
let link = node.querySelector('a'); | ||
if (!blockquote || !link) { | ||
return; | ||
} | ||
let url = link.href; | ||
let url = link.href; // If we don't have a url, or it's not an absolute URL, we can't handle this | ||
// If we don't have a url, or it's not an absolute URL, we can't handle this | ||
if (!url || !url.match(/^https?:\/\//i)) { | ||
return; | ||
} | ||
let payload = { | ||
@@ -508,8 +452,7 @@ url: url | ||
} = _ref5; | ||
if (node.nodeType !== 1 || node.tagName !== 'FIGURE' && node.tagName !== 'NFT-CARD' && node.tagName !== 'DIV') { | ||
return; | ||
} // Attempt to parse Ghost NFT Card | ||
} | ||
// Attempt to parse Ghost NFT Card | ||
if (node.tagName === 'FIGURE') { | ||
@@ -519,11 +462,7 @@ if (!node.classList.contains('kg-nft-card')) { | ||
} | ||
let nftCard = node.querySelector('a'); | ||
if (!nftCard) { | ||
return; | ||
} | ||
let payload; | ||
try { | ||
@@ -534,9 +473,8 @@ payload = JSON.parse(decodeURIComponent(nftCard.dataset.payload)); | ||
} | ||
let cardSection = builder.createCardSection('embed', payload); | ||
addSection(cardSection); | ||
return nodeFinished(); | ||
} // Attempt to parse Substack NFT Card | ||
} | ||
// Attempt to parse Substack NFT Card | ||
if (node.tagName === 'DIV') { | ||
@@ -546,10 +484,7 @@ if (!node.classList.contains('opensea')) { | ||
} | ||
let url = node.querySelector('a'); | ||
let [match, contractAddress, tokenId] = url.href.match(/\/assets\/(0x[0-9a-f]+)\/(\d+)/); | ||
if (!match) { | ||
return; | ||
} | ||
let payload = { | ||
@@ -563,3 +498,2 @@ url: url.href, | ||
} | ||
if (node.tagName === 'NFT-CARD') { | ||
@@ -569,7 +503,5 @@ let attr = node.attributes; | ||
let tokenId = (attr.tokenId || attr.tokenid).value; | ||
if (!contractAddress || !tokenId) { | ||
return; | ||
} | ||
let payload = { | ||
@@ -588,13 +520,9 @@ url: `https://opensea.io/assets/${contractAddress}/${tokenId}/`, | ||
let sizeStr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
if (!sizeStr) { | ||
return 0; | ||
} | ||
const [sizeVal, sizeType] = sizeStr.split(' '); | ||
if (!sizeVal || !sizeType) { | ||
return 0; | ||
} | ||
if (sizeType === 'Bytes') { | ||
@@ -608,3 +536,2 @@ return Number(sizeVal); | ||
} | ||
function fromKoenigCard$5() { | ||
@@ -616,7 +543,5 @@ return function kgFileCardToCard(node, builder, _ref) { | ||
} = _ref; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-file-card')) { | ||
return; | ||
} | ||
const titleNode = node.querySelector('.kg-file-card-title'); | ||
@@ -632,7 +557,5 @@ const captionNode = node.querySelector('.kg-file-card-caption'); | ||
const fileSrc = fileCardLinkNode && fileCardLinkNode.href; | ||
if (!fileSrc) { | ||
return; | ||
} | ||
const payload = { | ||
@@ -657,7 +580,5 @@ src: fileSrc, | ||
} = _ref; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-header-card')) { | ||
return; | ||
} | ||
const headerNode = node.querySelector('.kg-header-card-header'); | ||
@@ -670,11 +591,8 @@ const subheaderNode = node.querySelector('.kg-header-card-subheader'); | ||
let buttonUrl = ''; | ||
if (headerNode) { | ||
header = headerNode.innerHTML.trim(); | ||
} | ||
if (subheaderNode) { | ||
subheader = subheaderNode.innerHTML.trim(); | ||
} | ||
if (buttonNode) { | ||
@@ -684,14 +602,10 @@ buttonText = buttonNode.textContent.trim(); | ||
} | ||
if (!header && !subheader && (!buttonNode || !buttonText || !buttonUrl)) { | ||
return; | ||
} | ||
const classes = [...node.classList]; | ||
let backgroundImageSrc = ''; | ||
if (node.getAttribute('data-kg-background-image')) { | ||
backgroundImageSrc = node.getAttribute('data-kg-background-image').trim(); | ||
} | ||
const payload = { | ||
@@ -709,11 +623,8 @@ header, | ||
const styleClass = classes.find(c => /^kg-style-(dark|light|accent|image)$/.test(c)); | ||
if (sizeClass) { | ||
payload.size = sizeClass.replace('kg-size-', ''); | ||
} | ||
if (styleClass) { | ||
payload.style = styleClass.replace('kg-style-', ''); | ||
} | ||
const cardSection = builder.createCardSection('header', payload); | ||
@@ -734,23 +645,17 @@ addSection(cardSection); | ||
} = _ref; | ||
if (node.nodeType !== 8 || node.nodeValue !== 'kg-card-begin: html') { | ||
return; | ||
} | ||
let html = []; | ||
function isHtmlEndComment(n) { | ||
return n && n.nodeType === 8 && n.nodeValue === 'kg-card-end: html'; | ||
} | ||
let nextNode = node.nextSibling; | ||
while (nextNode && !isHtmlEndComment(nextNode)) { | ||
let currentNode = nextNode; | ||
html.push(currentNode.outerHTML); | ||
nextNode = currentNode.nextSibling; // remove nodes as we go so that they don't go through the parser | ||
nextNode = currentNode.nextSibling; | ||
// remove nodes as we go so that they don't go through the parser | ||
currentNode.remove(); | ||
} | ||
let payload = { | ||
@@ -771,7 +676,5 @@ html: html.join('\n').trim() | ||
} = _ref; | ||
if (node.nodeType !== 1 || node.tagName !== 'IMG') { | ||
return; | ||
} | ||
const payload = readImageAttributesFromNode(node); | ||
@@ -789,17 +692,12 @@ const cardSection = builder.createCardSection('image', payload); | ||
} = _ref2; | ||
if (node.nodeType !== 1 || node.tagName !== 'FIGURE') { | ||
return; | ||
} | ||
const img = node.querySelector('img'); | ||
const kgClass = node.className.match(/kg-width-(wide|full)/); | ||
const grafClass = node.className.match(/graf--layout(FillWidth|OutsetCenter)/); | ||
if (!img) { | ||
return; | ||
} | ||
const payload = readImageAttributesFromNode(img); | ||
if (kgClass) { | ||
@@ -810,3 +708,2 @@ payload.cardWidth = kgClass[1]; | ||
} | ||
addFigCaptionToPayload(node, payload, { | ||
@@ -823,10 +720,7 @@ options | ||
let buttonText = node.textContent; | ||
if (buttonText) { | ||
buttonText = buttonText.replace(/\n/g, ' ').replace(/\s+/g, ' ').trim(); | ||
} | ||
return buttonText; | ||
} | ||
function fromKoenigCard$2() { | ||
@@ -838,7 +732,5 @@ return function kgButtonCardToCard(node, builder, _ref) { | ||
} = _ref; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-product-card')) { | ||
return; | ||
} | ||
const titleNode = node.querySelector('.kg-product-card-title'); | ||
@@ -848,7 +740,5 @@ const descriptionNode = node.querySelector('.kg-product-card-description'); | ||
const description = descriptionNode && descriptionNode.innerHTML.trim(); | ||
if (!title && !description) { | ||
return; | ||
} | ||
const payload = { | ||
@@ -861,9 +751,6 @@ productButtonEnabled: false, | ||
const img = node.querySelector('.kg-product-card-image'); | ||
if (img && img.getAttribute('src')) { | ||
payload.productImageSrc = img.getAttribute('src'); | ||
} | ||
const stars = [...node.querySelectorAll('.kg-product-card-rating-active')].length; | ||
if (stars) { | ||
@@ -873,9 +760,6 @@ payload.productRatingEnabled = true; | ||
} | ||
const button = node.querySelector('a'); | ||
if (button) { | ||
const buttonUrl = button.href; | ||
const buttonText = getButtonText(button); | ||
if (buttonUrl && buttonText) { | ||
@@ -887,3 +771,2 @@ payload.productButtonEnabled = true; | ||
} | ||
const cardSection = builder.createCardSection('product', payload); | ||
@@ -902,7 +785,5 @@ addSection(cardSection); | ||
} = _ref; | ||
if (node.nodeType !== 1 || node.tagName !== 'BR') { | ||
return; | ||
} | ||
let softReturn = builder.createAtom('soft-return'); | ||
@@ -920,7 +801,5 @@ addMarkerable(softReturn); | ||
} = _ref; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-video-card')) { | ||
return; | ||
} | ||
const videoNode = node.querySelector('.kg-video-player-container video'); | ||
@@ -930,7 +809,5 @@ const durationNode = node.querySelector('.kg-video-duration'); | ||
const durationText = durationNode && durationNode.innerHTML.trim(); | ||
if (!videoSrc) { | ||
return; | ||
} | ||
const payload = { | ||
@@ -940,3 +817,2 @@ src: videoSrc, | ||
}; | ||
if (durationText) { | ||
@@ -947,9 +823,8 @@ const { | ||
} = durationText.split(':'); | ||
try { | ||
payload.duration = parseInt(minutes) * 60 + parseInt(seconds); | ||
} catch (e) {// ignore duration | ||
} catch (e) { | ||
// ignore duration | ||
} | ||
} | ||
const cardSection = builder.createCardSection('video', payload); | ||
@@ -967,3 +842,2 @@ addSection(cardSection); | ||
} | ||
function fromKoenigCard(options) { | ||
@@ -975,14 +849,12 @@ return function kgGalleryCardToCard(node, builder, _ref) { | ||
} = _ref; | ||
if (node.nodeType !== 1 || node.tagName !== 'FIGURE') { | ||
return; | ||
} | ||
if (!node.className.match(/kg-gallery-card/)) { | ||
return; | ||
} | ||
let payload = {}; | ||
let imgs = Array.from(node.querySelectorAll('img')); // Process nodes into the payload | ||
let imgs = Array.from(node.querySelectorAll('img')); | ||
// Process nodes into the payload | ||
payload.images = imgs.map(readGalleryImageAttributesFromNode); | ||
@@ -1003,20 +875,18 @@ addFigCaptionToPayload(node, payload, { | ||
} = _ref2; | ||
function isGrafGallery(n) { | ||
return n.nodeType === 1 && n.tagName === 'DIV' && n.dataset && n.dataset.paragraphCount && n.querySelectorAll('img').length > 0; | ||
} | ||
if (!isGrafGallery(node)) { | ||
return; | ||
} | ||
let payload = {}; | ||
let payload = {}; // These galleries exist in multiple divs. Read the images and caption from the first one... | ||
// These galleries exist in multiple divs. Read the images and caption from the first one... | ||
let imgs = Array.from(node.querySelectorAll('img')); | ||
addFigCaptionToPayload(node, payload, { | ||
options | ||
}); // ...and then iterate over any remaining divs until we run out of matches | ||
}); | ||
// ...and then iterate over any remaining divs until we run out of matches | ||
let nextNode = node.nextSibling; | ||
while (nextNode && isGrafGallery(nextNode)) { | ||
@@ -1028,8 +898,8 @@ let currentNode = nextNode; | ||
}); | ||
nextNode = currentNode.nextSibling; // remove nodes as we go so that they don't go through the parser | ||
nextNode = currentNode.nextSibling; | ||
// remove nodes as we go so that they don't go through the parser | ||
currentNode.remove(); | ||
} // Process nodes into the payload | ||
} | ||
// Process nodes into the payload | ||
payload.images = imgs.map(readGalleryImageAttributesFromNode); | ||
@@ -1047,11 +917,10 @@ let cardSection = builder.createCardSection('gallery', payload); | ||
} = _ref3; | ||
if (node.nodeType !== 1 || node.tagName !== 'DIV' || !node.className.match(/sqs-gallery-container/) || node.className.match(/summary-/)) { | ||
return; | ||
} | ||
let payload = {}; | ||
let payload = {}; // Each image exists twice... | ||
// Each image exists twice... | ||
// The first image is wrapped in `<noscript>` | ||
// The second image contains image dimensions but the src property needs to be taken from `data-src`. | ||
let imgs = Array.from(node.querySelectorAll('img.thumb-image')); | ||
@@ -1068,3 +937,2 @@ imgs = imgs.map(img => { | ||
} | ||
return img; | ||
@@ -1075,4 +943,5 @@ }); | ||
selector: '.meta-title' | ||
}); // Process nodes into the payload | ||
}); | ||
// Process nodes into the payload | ||
payload.images = imgs.map(readGalleryImageAttributesFromNode); | ||
@@ -1088,13 +957,9 @@ let cardSection = builder.createCardSection('gallery', payload); | ||
let _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const defaults = {}; | ||
const options = Object.assign({}, defaults, _options); | ||
if (!options.createDocument) { | ||
const Parser = typeof DOMParser !== 'undefined' && DOMParser || typeof window !== 'undefined' && window.DOMParser; | ||
if (!Parser) { | ||
throw new Error('createParserPlugins() must be passed a `createDocument` function as an option when used in a non-browser environment'); | ||
} | ||
options.createDocument = function (html) { | ||
@@ -1105,7 +970,7 @@ const parser = new Parser(); | ||
} | ||
options.cleanBasicHtml = function (html) { | ||
return cleanBasicHtml(html, options); | ||
}; // HELPERS ----------------------------------------------------------------- | ||
}; | ||
// HELPERS ----------------------------------------------------------------- | ||
@@ -1115,3 +980,2 @@ function _readFigCaptionFromNode(node, payload) { | ||
let figcaptions = Array.from(node.querySelectorAll(selector)); | ||
if (figcaptions.length) { | ||
@@ -1124,4 +988,5 @@ figcaptions.forEach(caption => { | ||
} | ||
} // PLUGINS ----------------------------------------------------------------- | ||
} | ||
// PLUGINS ----------------------------------------------------------------- | ||
@@ -1133,7 +998,5 @@ function kgCalloutCardToCard(node, builder, _ref) { | ||
} = _ref; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-callout-card')) { | ||
return; | ||
} | ||
const emojiNode = node.querySelector('.kg-callout-emoji'); | ||
@@ -1143,6 +1006,4 @@ const htmlNode = node.querySelector('.kg-callout-text'); | ||
let calloutEmoji = ''; | ||
if (emojiNode) { | ||
calloutEmoji = emojiNode.textContent; | ||
if (calloutEmoji) { | ||
@@ -1152,3 +1013,2 @@ calloutEmoji = calloutEmoji.trim(); | ||
} | ||
let calloutText = htmlNode.innerHTML; | ||
@@ -1164,3 +1024,2 @@ const payload = { | ||
} | ||
function kgToggleCardToCard(node, builder, _ref2) { | ||
@@ -1171,7 +1030,5 @@ let { | ||
} = _ref2; | ||
if (node.nodeType !== 1 || !node.classList.contains('kg-toggle-card')) { | ||
return; | ||
} | ||
const headingNode = node.querySelector('.kg-toggle-heading-text'); | ||
@@ -1188,7 +1045,7 @@ const contentNode = node.querySelector('.kg-toggle-content'); | ||
nodeFinished(); | ||
} // leading newlines in text nodes will add a space to the beginning of the text | ||
} | ||
// leading newlines in text nodes will add a space to the beginning of the text | ||
// which doesn't render correctly if we're replacing <br> with SoftReturn atoms | ||
// after parsing text as markdown to html | ||
function removeLeadingNewline(node) { | ||
@@ -1198,6 +1055,4 @@ if (node.nodeType !== 3 || node.nodeName !== '#text') { | ||
} | ||
node.nodeValue = node.nodeValue.replace(/^\n/, ''); | ||
} | ||
function hrToCard(node, builder, _ref3) { | ||
@@ -1208,7 +1063,5 @@ let { | ||
} = _ref3; | ||
if (node.nodeType !== 1 || node.tagName !== 'HR') { | ||
return; | ||
} | ||
let cardSection = builder.createCardSection('hr'); | ||
@@ -1218,3 +1071,2 @@ addSection(cardSection); | ||
} | ||
function figureToCodeCard(node, builder, _ref4) { | ||
@@ -1225,26 +1077,22 @@ let { | ||
} = _ref4; | ||
if (node.nodeType !== 1 || node.tagName !== 'FIGURE') { | ||
return; | ||
} | ||
let pre = node.querySelector('pre'); | ||
let pre = node.querySelector('pre'); // If this figure doesn't have a pre tag in it | ||
// If this figure doesn't have a pre tag in it | ||
if (!pre) { | ||
return; | ||
} | ||
let code = pre.querySelector('code'); | ||
let figcaption = node.querySelector('figcaption'); // if there's no caption the preCodeToCard plugin will pick it up instead | ||
let figcaption = node.querySelector('figcaption'); | ||
// if there's no caption the preCodeToCard plugin will pick it up instead | ||
if (!code || !figcaption) { | ||
return; | ||
} | ||
let payload = { | ||
code: code.textContent | ||
}; | ||
_readFigCaptionFromNode(node, payload); | ||
let preClass = pre.getAttribute('class') || ''; | ||
@@ -1254,7 +1102,5 @@ let codeClass = code.getAttribute('class') || ''; | ||
let languageMatches = preClass.match(langRegex) || codeClass.match(langRegex); | ||
if (languageMatches) { | ||
payload.language = languageMatches[1].toLowerCase(); | ||
} | ||
let cardSection = builder.createCardSection('code', payload); | ||
@@ -1264,3 +1110,2 @@ addSection(cardSection); | ||
} | ||
function preCodeToCard(node, builder, _ref5) { | ||
@@ -1271,9 +1116,6 @@ let { | ||
} = _ref5; | ||
if (node.nodeType !== 1 || node.tagName !== 'PRE') { | ||
return; | ||
} | ||
let [codeElement] = node.children; | ||
if (codeElement && codeElement.tagName === 'CODE') { | ||
@@ -1287,7 +1129,5 @@ let payload = { | ||
let languageMatches = preClass.match(langRegex) || codeClass.match(langRegex); | ||
if (languageMatches) { | ||
payload.language = languageMatches[1].toLowerCase(); | ||
} | ||
let cardSection = builder.createCardSection('code', payload); | ||
@@ -1298,3 +1138,2 @@ addSection(cardSection); | ||
} | ||
function figureScriptToHtmlCard(node, builder, _ref6) { | ||
@@ -1305,13 +1144,9 @@ let { | ||
} = _ref6; | ||
if (node.nodeType !== 1 || node.tagName !== 'FIGURE') { | ||
return; | ||
} | ||
let script = node.querySelector('script'); | ||
if (!script || !script.src.match(/^https:\/\/gist\.github\.com/)) { | ||
return; | ||
} | ||
let payload = { | ||
@@ -1323,7 +1158,7 @@ html: script.outerHTML | ||
nodeFinished(); | ||
} // Nested paragraphs in blockquote are currently treated as separate blockquotes, | ||
} | ||
// Nested paragraphs in blockquote are currently treated as separate blockquotes, | ||
// see [here](https://github.com/bustle/mobiledoc-kit/issues/715). When running migrations, | ||
// this is not the desired behaviour and will cause the content to lose the previous semantic. | ||
function blockquoteWithChildren(node) { | ||
@@ -1333,3 +1168,2 @@ if (node.nodeType !== 1 || node.tagName !== 'BLOCKQUOTE' || node.children.length < 1) { | ||
} | ||
const html = []; | ||
@@ -1339,6 +1173,7 @@ const children = Array.from(node.children); | ||
let nextSibling = child.nextSibling; | ||
let previousSibling = child.previousSibling; // Only add a soft-break for two sequential paragraphs. | ||
let previousSibling = child.previousSibling; | ||
// Only add a soft-break for two sequential paragraphs. | ||
// Use the innerHTML only in that case, so Mobiledoc's default behaviour | ||
// of creating separate blockquotes doesn't apply. | ||
if (child.tagName === 'P' && nextSibling && nextSibling.tagName === 'P') { | ||
@@ -1354,6 +1189,6 @@ html.push(`${child.innerHTML}<br><br>`); | ||
return; | ||
} // we store alt-style blockquotes as `aside` sections as a workaround | ||
} | ||
// we store alt-style blockquotes as `aside` sections as a workaround | ||
// for mobiledoc not allowing arbitrary attributes on markup sections | ||
function altBlockquoteToAside(node) { | ||
@@ -1363,9 +1198,9 @@ if (node.nodeType !== 1 || node.tagName !== 'BLOCKQUOTE') { | ||
} | ||
if (!node.classList.contains('kg-blockquote-alt')) { | ||
return; | ||
} | ||
const replacementDoc = options.createDocument(`<aside>${node.innerHTML}</aside>`); | ||
const aside = replacementDoc.querySelector('aside'); | ||
const replacementDoc = options.createDocument(`<aside>${node.innerHTML}</aside>`); | ||
const aside = replacementDoc.querySelector('aside'); // bit of an ugly hack because | ||
// bit of an ugly hack because | ||
// 1. node.tagName is readonly so we can't directly change it's type | ||
@@ -1377,9 +1212,8 @@ // 2. the node list of the current tree branch is not re-evaluated so removing | ||
// inner-most understandable section element when creating sections | ||
node.textContent = ''; | ||
node.appendChild(aside); // let the default parser handle the nested aside node, keeping any formatting | ||
node.appendChild(aside); | ||
// let the default parser handle the nested aside node, keeping any formatting | ||
return; | ||
} | ||
function tableToHtmlCard(node, builder, _ref7) { | ||
@@ -1390,11 +1224,8 @@ let { | ||
} = _ref7; | ||
if (node.nodeType !== 1 || node.tagName !== 'TABLE') { | ||
return; | ||
} | ||
if (node.parentNode.tagName === 'TABLE') { | ||
return; | ||
} | ||
let payload = { | ||
@@ -1407,5 +1238,6 @@ html: node.outerHTML | ||
} | ||
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), // I think these can contain images | ||
fromGrafGallery(options), fromSqsGallery(options), fromFigure(options), fromImg(), hrToCard, figureToCodeCard, preCodeToCard, fromFigureIframe(options), fromIframe(), // Process iFrames without figures after ones with | ||
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), | ||
// I think these can contain images | ||
fromGrafGallery(options), fromSqsGallery(options), fromFigure(options), fromImg(), hrToCard, figureToCodeCard, preCodeToCard, fromFigureIframe(options), fromIframe(), | ||
// Process iFrames without figures after ones with | ||
figureScriptToHtmlCard, altBlockquoteToAside, tableToHtmlCard]; | ||
@@ -1412,0 +1244,0 @@ } |
{ | ||
"name": "@tryghost/kg-parser-plugins", | ||
"version": "2.12.7", | ||
"version": "2.12.8", | ||
"repository": "https://github.com/TryGhost/Koenig/tree/master/packages/kg-parser-plugins", | ||
@@ -33,3 +33,3 @@ "author": "Ghost Foundation", | ||
"devDependencies": { | ||
"@babel/core": "7.19.3", | ||
"@babel/core": "7.19.6", | ||
"@babel/preset-env": "7.19.4", | ||
@@ -46,5 +46,5 @@ "@tryghost/mobiledoc-kit": "0.11.2-ghost.4", | ||
"dependencies": { | ||
"@tryghost/kg-clean-basic-html": "^2.2.22" | ||
"@tryghost/kg-clean-basic-html": "^2.2.23" | ||
}, | ||
"gitHead": "8b0f327a21dd7748b5eb4f1de538931ca152b407" | ||
"gitHead": "912528b033dc263f3de87377e18464e4ba4fc42c" | ||
} |
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
3086
204649