Skip to content

Commit

Permalink
fix preserve format content replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai committed Mar 29, 2024
1 parent d854635 commit 9216c99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ main a.con-button.no-event {
pointer-events: none;
opacity: 0.5;
}

.preserve-format {
white-space: pre-wrap;
}
3 changes: 2 additions & 1 deletion utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function updateImgTag(child, matchCallback, parentElement) {

function updateTextNode(child, matchCallback) {
const originalText = child.nodeValue;
const replacedText = originalText.replace(REG, matchCallback);
const replacedText = originalText.replace(REG, (_match, p1) => matchCallback(_match, p1, child));
if (replacedText !== originalText) child.nodeValue = replacedText;
}

Expand All @@ -106,6 +106,7 @@ export function autoUpdateContent(parent) {
const getContent = (_match, p1, n) => {
const content = getMetadata(p1) || '';
if (preserveFormatKeys.includes(p1)) {
console.log('yes! but', n.parentNode);
n.parentNode?.classList.add('preserve-format');
}
return content;
Expand Down

0 comments on commit 9216c99

Please sign in to comment.