aboutsummaryrefslogtreecommitdiff
path: root/vnext
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2024-01-31 15:06:43 +0300
committerGravatar Vitaly Takmazov2024-01-31 15:06:43 +0300
commit7c998caae3f6a027118c5c627a625a624b036582 (patch)
treebcac10bbcd26afb14f71fa9a0acbec9e47cfedb7 /vnext
parente636df69a3a6e5b313c432f6e64bb3aa07ba5eaa (diff)
embed.js: process all links, stop on first embed
Diffstat (limited to 'vnext')
-rw-r--r--vnext/src/utils/embed.js14
1 files changed, 8 insertions, 6 deletions
diff --git a/vnext/src/utils/embed.js b/vnext/src/utils/embed.js
index 11434938..79674e28 100644
--- a/vnext/src/utils/embed.js
+++ b/vnext/src/utils/embed.js
@@ -1,8 +1,8 @@
function htmlEscape(html) {
return html.replace(/&/g, '&')
- .replace(/"/g, '"')
- .replace(/</g, '&lt;')
- .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
}
function insertAfter(newNode, referenceNode) {
@@ -352,15 +352,17 @@ function embedLink(aNode, linkTypes, container, afterNode = false) {
function embedLinks(aNodes, container) {
let anyEmbed = false
let embeddableLinkTypes = getEmbeddableLinkTypes()
- Array.from(aNodes).forEach(aNode => {
+ Array.from(aNodes).every(aNode => {
let isEmbedded = embedLink(aNode, embeddableLinkTypes, container)
+ // stop on first embedded link
anyEmbed = anyEmbed || isEmbedded
+ return !(anyEmbed)
})
return anyEmbed
}
/**
- * Embed all the links inside element "x" that match to "allLinksSelector".
+ * Embed first link from supplied links inside element "x" that match to "allLinksSelector".
* All the embedded media is placed inside "div.embedContainer".
* "div.embedContainer" is inserted before an element matched by "beforeNodeSelector"
* if not present. Existing container is used otherwise.
@@ -369,7 +371,7 @@ function embedLinks(aNodes, container) {
* @param {string} allLinksSelector
*/
export function embedLinksToX(x, beforeNodeSelector, allLinksSelector) {
- let allLinks = [x.querySelector(allLinksSelector)]
+ let allLinks = x.querySelectorAll(allLinksSelector)
let existingContainer = x.querySelector('div.embedContainer')
if (existingContainer) {