diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/fg/js/util.js | 8 | ||||
-rw-r--r-- | ext/mixed/js/display.js | 4 | ||||
-rw-r--r-- | ext/mixed/js/util.js | 14 |
3 files changed, 18 insertions, 8 deletions
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js index a1bce660..59060221 100644 --- a/ext/fg/js/util.js +++ b/ext/fg/js/util.js @@ -205,14 +205,10 @@ function docClozeExtract(source, extent) { } const sentence = content.substring(startPos, endPos); - const clozePrefix = sentence.substring(0, position - startPos); - const clozeBody = source.text(); - const clozeSuffix = sentence.substring(position - startPos + clozeBody.length); + const padding = sentence.length - sentence.replace(/^\s+/, ''); return { sentence: sentence.trim(), - prefix: clozePrefix.trim(), - body: clozeBody.trim(), - suffix: clozeSuffix.trim() + offset: position - startPos - padding }; } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index f5ad4849..e77ca7da 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -74,7 +74,7 @@ class Display { if (context) { for (const definition of definitions) { - definition.cloze = context.cloze; + definition.cloze = clozeBuild(context.cloze); definition.url = context.url; } } @@ -108,7 +108,7 @@ class Display { if (context) { for (const definition of definitions) { - definition.cloze = context.cloze; + definition.cloze = clozeBuild(context.cloze); definition.url = context.url; } } diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js index c05fb679..aeeb830e 100644 --- a/ext/mixed/js/util.js +++ b/ext/mixed/js/util.js @@ -18,6 +18,20 @@ /* + * Cloze + */ + +function clozeBuild(sentence, offset, source) { + return { + sentence: sentence.trim(), + prefix: sentence.substring(0, offset).trim(), + body: source.trim(), + suffix: sentence.substring(offset + source.length).trim() + }; +} + + +/* * Audio */ |