aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/display.js2
-rw-r--r--ext/mixed/js/util.js15
2 files changed, 11 insertions, 6 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 973b7749..64d462ae 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -108,7 +108,7 @@ class Display {
if (context) {
for (const definition of definitions) {
- definition.cloze = clozeBuild(context.sentence, definition.source);
+ definition.cloze = clozeBuild(context.sentence);
definition.url = context.url;
}
}
diff --git a/ext/mixed/js/util.js b/ext/mixed/js/util.js
index eae54f49..62838674 100644
--- a/ext/mixed/js/util.js
+++ b/ext/mixed/js/util.js
@@ -22,12 +22,17 @@
*/
function clozeBuild(sentence, source) {
- return {
- sentence: sentence.text.trim(),
- prefix: sentence.text.substring(0, sentence.offset).trim(),
- body: source.trim(),
- suffix: sentence.text.substring(sentence.offset + source.length).trim()
+ const result = {
+ sentence: sentence.text.trim()
};
+
+ if (source) {
+ result.prefix = sentence.text.substring(0, sentence.offset).trim();
+ result.body = source.trim();
+ result.suffix = sentence.text.substring(sentence.offset + source.length).trim();
+ }
+
+ return result;
}