Updating exc to support exceptions for all three point-of-views, fixes #33
This commit is contained in:
parent
2a50830c7f
commit
856240d944
|
@ -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,14 +348,28 @@ 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;
|
||||||
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 {
|
} 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);
|
node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue);
|
||||||
exceptionMethod(node, searchTerm, options);
|
exceptionMethod(node, searchTerm, options);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue