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