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