fix: handle literal \r\n escape sequences in hwpod-node insert-after/replace anchor matching
This commit is contained in:
@@ -701,7 +701,8 @@ function lineEndingFromArgs(args: any, fallback: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function normalizeContentLineEndings(content: string, lineEnding: string, finalNewline: boolean) {
|
function normalizeContentLineEndings(content: string, lineEnding: string, finalNewline: boolean) {
|
||||||
const normalized = String(content).replace(/\r\n?/gu, "\n");
|
const unescaped = String(content).replace(/\\r\\n/gu, "\r\n").replace(/\\n/gu, "\n").replace(/\\r(?!\n)/gu, "\r");
|
||||||
|
const normalized = unescaped.replace(/\r\n?/gu, "\n");
|
||||||
const withFinal = finalNewline && !normalized.endsWith("\n") ? `${normalized}\n` : normalized;
|
const withFinal = finalNewline && !normalized.endsWith("\n") ? `${normalized}\n` : normalized;
|
||||||
return lineEnding === "\r\n" ? withFinal.replace(/\n/gu, "\r\n") : withFinal;
|
return lineEnding === "\r\n" ? withFinal.replace(/\n/gu, "\r\n") : withFinal;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user