Skip to content

Commit

Permalink
✨ selectionText要对特殊符号进行处理,比如把英文双引号变为" #32
Browse files Browse the repository at this point in the history
  • Loading branch information
Achuan-2 committed Dec 13, 2024
1 parent f701aa7 commit f3f2f17
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,19 @@ export default class PluginFootnote extends Plugin {
.replace(plainSpanPattern2, '$1') // 保留span标签中的文本内容
let templates = this.settingUtils.get("templates");
templates = templates.replace(/\$\{selection\}/g, cleanSelection);
// selectionText要对特殊符号进行处理,比如把英文双引号变为"
const escapeHtml = (text: string) => {
const map: { [key: string]: string } = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;',
};
return text.replace(/[&<>"']/g, (m) => map[m]);
};
const escapedSelectionText = escapeHtml(selectionText);
templates = templates.replace(/\$\{selection:text\}/g, escapedSelectionText);
templates = templates.replace(/\$\{selection:text\}/g, selectionText);
templates = templates.replace(/\$\{content\}/g, zeroWhite);
templates = templates.replace(/\$\{refID\}/g, currentBlockId);
Expand Down

0 comments on commit f3f2f17

Please sign in to comment.