Koenig - Grab image caption from <img><figcaption> when pasting

refs https://github.com/TryGhost/Ghost/issues/9623
- workaround to grab a `<figcaption>` for use in an image card in some cases
- will only work when an `<img>` tag is immediately followed by a `<figcaption>` tag in the parsed html
This commit is contained in:
Kevin Ansfield 2018-05-18 14:26:26 +01:00
parent 631edbe60a
commit ac870e43bd

View File

@ -27,6 +27,16 @@ export function imgToCard(node, builder, {addSection, nodeFinished}) {
}
let payload = {src: node.src};
// TODO: this is a workaround for grabbing a figure>img+figcaption until
// https://github.com/bustle/mobiledoc-kit/issues/494 is resolved
// NOTE: it will only work in a strict <figure><img><figcaption></figure> case
let nextSibling = node.nextSibling;
if (nextSibling && nextSibling.tagName === 'FIGCAPTION') {
payload.caption = nextSibling.textContent;
node.parentNode.removeChild(nextSibling);
}
let cardSection = builder.createCardSection('image', payload);
addSection(cardSection);
nodeFinished();