Update tagProcessor.js

This commit is contained in:
2025-07-12 17:47:23 +08:00
committed by GitHub
parent 377ac63fea
commit 3e3621ba44

View File

@@ -4,6 +4,12 @@ function extractContentByTag(xmlString, tagName) {
return match ? match[1] : null; return match ? match[1] : null;
} }
function extractFullTagBlock(xmlString, tagName) {
const regex = new RegExp(`(<${tagName}[^>]*>[\\s\\S]*?<\\/${tagName}>)`);
const match = xmlString.match(regex);
return match ? match[0] : null;
}
function replaceContentByTag(xmlString, tagName, newContent) { function replaceContentByTag(xmlString, tagName, newContent) {
const regex = new RegExp(`(<${tagName}[^>]*>)[\\s\\S]*?(<\\/${tagName}>)`); const regex = new RegExp(`(<${tagName}[^>]*>)[\\s\\S]*?(<\\/${tagName}>)`);
if (regex.test(xmlString)) { if (regex.test(xmlString)) {
@@ -11,4 +17,5 @@ function replaceContentByTag(xmlString, tagName, newContent) {
} }
return xmlString; return xmlString;
} }
export { extractContentByTag, replaceContentByTag };
export { extractContentByTag, replaceContentByTag, extractFullTagBlock };