Updating exc to support exceptions for all three point-of-views, fixes #33

This commit is contained in:
Jean Viscogliosi-Pate 2025-06-26 23:08:17 -07:00
parent 2a50830c7f
commit 856240d944
1 changed files with 19 additions and 5 deletions

View File

@ -224,7 +224,7 @@ function replaceAlso(options) {
/* Replaces exception statements by POV */
function replaceExceptions(options) {
const searchTerm = /exc\/([^\/]*)\/([^\/]*)\//i;
const searchTerm = /exc\/([^\/]*)\/([^\/]*)\/(?:([^\/]*)\/)?/i;
walk(document.body, searchTerm, options, exceptionMethod);
}
@ -348,14 +348,28 @@ function verbMethod(node, searchTerm, options) {
function exceptionMethod(node, searchTerm, options) {
const match = node.nodeValue.match(searchTerm);
if (match == null) { return; }
let replaceValue;
if (options.pov == "third") {
replaceValue = match[2];
const isFirstSecondSame = match[3] == null;
if (isFirstSecondSame) {
if (options.pov == "third") {
replaceValue = match[2];
} else {
replaceValue = match[1];
}
} else {
replaceValue = match[1];
if (options.pov == "third") {
replaceValue = match[3];
} else if (options.pov == "second") {
replaceValue = match[2];
} else {
replaceValue = match[1];
}
}
node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue);
exceptionMethod(node, searchTerm, options);
}