Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/components/Composer/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@
:insert-modal-label="insertModalLabel"
:prepared-content-label="insertContentLabel"
:search-label="insertSearchLabel"
@change="(name, prop, value) => emitChange({body: value})"
@change="
(name, prop, value) =>
emitChange({
body: value,
bodyTokenized: toToken(value),
})
"
>
<template #footer>
<div
Expand Down Expand Up @@ -729,6 +735,36 @@ export default {
}
},
methods: {
toToken(html) {
const temp = document.createElement('div');
temp.innerHTML = html ?? '';

temp.querySelectorAll('span.pkpTag[data-symbolic]').forEach((el) => {
const key = el.getAttribute('data-symbolic');
el.replaceWith(document.createTextNode(`{$${key}}`));
});

// 2) Replace pkpTag spans that exist INSIDE attribute strings (e.g., href, title, data-*)
const spanInAttrRe =
/<span[^>]*\bpkpTag\b[^>]*\bdata-symbolic=(?:"|')([^"']+)(?:"|')[^>]*>.*?<\/span>/gi;

const replaceInAttrs = (node) => {
if (node.nodeType !== 1) return;
// iterate a static copy of attributes
Array.from(node.attributes).forEach((attr) => {
const orig = attr.value;
const replaced = orig.replace(spanInAttrRe, (_m, key) => `{$${key}}`);
if (replaced !== orig) {
node.setAttribute(attr.name, replaced);
}
});

Array.from(node.children).forEach(replaceInAttrs);
};
replaceInAttrs(temp);

return temp.innerHTML; // tokenized string including attrs
},
/**
* Add file attachments to the email
*
Expand Down