Adding two-term exceptions, fixes #25

This commit is contained in:
Jean Viscogliosi-Pate 2025-02-21 21:20:27 -08:00
parent abbfef5093
commit 445f38b4ee
1 changed files with 28 additions and 1 deletions

View File

@ -14,6 +14,7 @@ function replaceAll() {
const isPronounsSet = !(options.preset === undefined || options.preset == "");
const isPovSet = !(options.pov === undefined || options.pov == "");
const isPovLegal = isPovSet && (options.pov != "third" || (isNameSet && isPronounsSet));
const isAllSet = isNameSet && isPronounsSet && isPovLegal;
if (isPovLegal) {
replaceVerbs(options);
@ -34,7 +35,10 @@ function replaceAll() {
replaceAlso(options);
}
replaceCuts();
if (isAllSet) {
replaceExceptions(options);
replaceCuts();
}
});
}
@ -231,6 +235,13 @@ function replaceAlso(options) {
});
}
/* Replaces exception statements by POV */
function replaceExceptions(options) {
const searchTerm = /[Ee]xc\/([^\/]*)\/([^\/]*)\//;
walk(document.body, searchTerm, options, exceptionMethod);
}
/* Replaces cut statements with cuts */
function replaceCuts() {
const searchTerm = /[Cc]ut\/([^\/]+)\/(-?[\d]+)\//;
@ -425,6 +436,22 @@ function cutMethod(node, searchTerm, unused) {
cutMethod(node, searchTerm, unused);
}
/* Allows for custom words to be cut off */
function exceptionMethod(node, searchTerm, options) {
let match = node.nodeValue.match(searchTerm);
if (match == null) { return; }
let replaceValue;
if (options.pov == "third") {
replaceValue = match[2];
} else {
replaceValue = match[1];
}
node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue);
cutMethod(node, searchTerm, options);
}
/* Returns the input word, capitalized */
function capitalize(word) {
return word.charAt(0).toUpperCase() + word.slice(1);