From 856240d94436754d50b91b96f1015a06298ff854 Mon Sep 17 00:00:00 2001 From: Jean Date: Thu, 26 Jun 2025 23:08:17 -0700 Subject: [PATCH] Updating exc to support exceptions for all three point-of-views, fixes #33 --- src/replace-words.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/replace-words.js b/src/replace-words.js index 8b00c28..49ae359 100644 --- a/src/replace-words.js +++ b/src/replace-words.js @@ -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); }