summaryrefslogtreecommitdiff
path: root/ext/bg/js/api.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-10-31 23:56:44 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2019-11-23 17:45:44 +0200
commit3881457e4ed3f9c7833ac21a5e7fc44c2ba00b0f (patch)
tree7daa263a7c7c7008bb0518a06ff4e94faded20e9 /ext/bg/js/api.js
parente6a1b781648b8ab965a4508ea29ab85f0e070b35 (diff)
use handlebars templates for query parser
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r--ext/bg/js/api.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index dbbe7368..7c9a72a7 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -85,6 +85,7 @@ async function apiTextParse(text, optionsContext) {
const results = [];
while (text) {
+ const term = [];
let [definitions, sourceLength] = await translator.findTerms(text, {}, options);
if (definitions.length > 0) {
definitions = dictTermsSort(definitions);
@@ -98,22 +99,23 @@ async function apiTextParse(text, optionsContext) {
}
const offset = source.length - stemLength;
- for (const result of jpDistributeFurigana(
+ for (const {text, furigana} of jpDistributeFurigana(
source.slice(0, offset === 0 ? source.length : source.length - offset),
- reading.slice(0, offset === 0 ? reading.length : source.length + (reading.length - expression.length) - offset)
+ reading.slice(0, offset === 0 ? reading.length : reading.length - expression.length + stemLength)
)) {
- results.push(result);
+ term.push({text, reading: furigana || ''});
}
if (stemLength !== source.length) {
- results.push({text: source.slice(stemLength)});
+ term.push({text: source.slice(stemLength)});
}
text = text.slice(source.length);
} else {
- results.push({text: text[0]});
+ term.push({text: text[0]});
text = text.slice(1);
}
+ results.push(term);
}
return results;
}