2020-03-07 20:14:05 +00:00
|
|
|
/*
|
2022-02-03 01:43:10 +00:00
|
|
|
* Copyright (C) 2020-2022 Yomichan Authors
|
2020-03-07 20:14:05 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-08-01 20:23:33 +00:00
|
|
|
/* global
|
2021-02-25 02:54:58 +00:00
|
|
|
* AnkiUtil
|
2021-01-11 00:28:50 +00:00
|
|
|
* TemplateRendererProxy
|
2020-08-01 20:23:33 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-07 20:14:05 +00:00
|
|
|
class AnkiNoteBuilder {
|
2021-07-09 21:48:27 +00:00
|
|
|
constructor({japaneseUtil}) {
|
|
|
|
this._japaneseUtil = japaneseUtil;
|
2021-02-25 02:54:58 +00:00
|
|
|
this._markerPattern = AnkiUtil.cloneFieldMarkerPattern(true);
|
|
|
|
this._templateRenderer = new TemplateRendererProxy();
|
2021-04-02 23:09:21 +00:00
|
|
|
this._batchedRequests = [];
|
|
|
|
this._batchedRequestsQueued = false;
|
2020-03-07 20:14:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 15:54:40 +00:00
|
|
|
async createNote({
|
2021-04-04 20:22:35 +00:00
|
|
|
dictionaryEntry,
|
2020-09-09 15:54:40 +00:00
|
|
|
mode,
|
|
|
|
context,
|
2021-04-02 16:42:06 +00:00
|
|
|
template,
|
2021-01-04 00:40:12 +00:00
|
|
|
deckName,
|
|
|
|
modelName,
|
|
|
|
fields,
|
2020-09-09 15:54:40 +00:00
|
|
|
tags=[],
|
2021-07-06 23:43:53 +00:00
|
|
|
requirements=[],
|
2020-11-08 21:25:07 +00:00
|
|
|
checkForDuplicates=true,
|
2020-09-09 15:54:40 +00:00
|
|
|
duplicateScope='collection',
|
2021-07-14 00:29:53 +00:00
|
|
|
duplicateScopeCheckAllModels=false,
|
2020-09-09 15:54:40 +00:00
|
|
|
resultOutputMode='split',
|
2020-11-26 04:22:05 +00:00
|
|
|
glossaryLayoutMode='default',
|
2021-07-06 23:43:53 +00:00
|
|
|
compactTags=false,
|
|
|
|
mediaOptions=null
|
2020-09-09 15:54:40 +00:00
|
|
|
}) {
|
2020-10-31 23:03:45 +00:00
|
|
|
let duplicateScopeDeckName = null;
|
|
|
|
let duplicateScopeCheckChildren = false;
|
|
|
|
if (duplicateScope === 'deck-root') {
|
|
|
|
duplicateScope = 'deck';
|
2021-02-25 02:54:58 +00:00
|
|
|
duplicateScopeDeckName = AnkiUtil.getRootDeckName(deckName);
|
2020-10-31 23:03:45 +00:00
|
|
|
duplicateScopeCheckChildren = true;
|
|
|
|
}
|
|
|
|
|
2021-07-06 23:43:53 +00:00
|
|
|
const allErrors = [];
|
|
|
|
let media;
|
|
|
|
if (requirements.length > 0 && mediaOptions !== null) {
|
|
|
|
let errors;
|
|
|
|
({media, errors} = await this._injectMedia(dictionaryEntry, requirements, mediaOptions));
|
|
|
|
for (const error of errors) {
|
|
|
|
allErrors.push(deserializeError(error));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
media = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const commonData = this._createData(dictionaryEntry, mode, context, resultOutputMode, glossaryLayoutMode, compactTags, media);
|
2020-06-21 19:54:34 +00:00
|
|
|
const formattedFieldValuePromises = [];
|
2021-01-04 00:40:12 +00:00
|
|
|
for (const [, fieldValue] of fields) {
|
2021-07-05 19:08:11 +00:00
|
|
|
const formattedFieldValuePromise = this._formatField(fieldValue, commonData, template);
|
2020-06-21 19:54:34 +00:00
|
|
|
formattedFieldValuePromises.push(formattedFieldValuePromise);
|
|
|
|
}
|
|
|
|
|
|
|
|
const formattedFieldValues = await Promise.all(formattedFieldValuePromises);
|
2021-07-05 19:08:11 +00:00
|
|
|
const uniqueRequirements = new Map();
|
2021-01-11 00:28:50 +00:00
|
|
|
const noteFields = {};
|
2021-01-04 00:40:12 +00:00
|
|
|
for (let i = 0, ii = fields.length; i < ii; ++i) {
|
|
|
|
const fieldName = fields[i][0];
|
2021-07-06 23:43:53 +00:00
|
|
|
const {value, errors: fieldErrors, requirements: fieldRequirements} = formattedFieldValues[i];
|
2021-07-05 19:08:11 +00:00
|
|
|
noteFields[fieldName] = value;
|
2021-07-06 23:43:53 +00:00
|
|
|
allErrors.push(...fieldErrors);
|
|
|
|
for (const requirement of fieldRequirements) {
|
2021-07-05 19:08:11 +00:00
|
|
|
const key = JSON.stringify(requirement);
|
|
|
|
if (uniqueRequirements.has(key)) { continue; }
|
|
|
|
uniqueRequirements.set(key, requirement);
|
|
|
|
}
|
2020-03-07 20:14:05 +00:00
|
|
|
}
|
|
|
|
|
2021-07-03 15:30:48 +00:00
|
|
|
const note = {
|
2021-01-11 00:28:50 +00:00
|
|
|
fields: noteFields,
|
|
|
|
tags,
|
|
|
|
deckName,
|
|
|
|
modelName,
|
|
|
|
options: {
|
|
|
|
allowDuplicate: !checkForDuplicates,
|
|
|
|
duplicateScope,
|
|
|
|
duplicateScopeOptions: {
|
|
|
|
deckName: duplicateScopeDeckName,
|
2021-07-14 00:29:53 +00:00
|
|
|
checkChildren: duplicateScopeCheckChildren,
|
|
|
|
checkAllModels: duplicateScopeCheckAllModels
|
2021-01-11 00:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2021-07-06 23:43:53 +00:00
|
|
|
return {note, errors: allErrors, requirements: [...uniqueRequirements.values()]};
|
2020-03-07 20:14:05 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 00:07:11 +00:00
|
|
|
async getRenderingData({
|
2021-04-04 20:22:35 +00:00
|
|
|
dictionaryEntry,
|
2021-04-01 00:07:11 +00:00
|
|
|
mode,
|
|
|
|
context,
|
|
|
|
resultOutputMode='split',
|
|
|
|
glossaryLayoutMode='default',
|
|
|
|
compactTags=false,
|
|
|
|
marker=null
|
|
|
|
}) {
|
2021-07-06 23:43:53 +00:00
|
|
|
const commonData = this._createData(dictionaryEntry, mode, context, resultOutputMode, glossaryLayoutMode, compactTags, {});
|
2021-04-03 19:18:52 +00:00
|
|
|
return await this._templateRenderer.getModifiedData({marker, commonData}, 'ankiNote');
|
2021-04-01 00:07:11 +00:00
|
|
|
}
|
|
|
|
|
2021-07-06 23:43:53 +00:00
|
|
|
getDictionaryEntryDetailsForNote(dictionaryEntry) {
|
|
|
|
const {type} = dictionaryEntry;
|
|
|
|
if (type === 'kanji') {
|
|
|
|
const {character} = dictionaryEntry;
|
|
|
|
return {type, character};
|
|
|
|
}
|
|
|
|
|
|
|
|
const {headwords} = dictionaryEntry;
|
|
|
|
let bestIndex = -1;
|
|
|
|
for (let i = 0, ii = headwords.length; i < ii; ++i) {
|
|
|
|
const {term, reading, sources} = headwords[i];
|
|
|
|
for (const {deinflectedText} of sources) {
|
|
|
|
if (term === deinflectedText) {
|
|
|
|
bestIndex = i;
|
|
|
|
i = ii;
|
|
|
|
break;
|
|
|
|
} else if (reading === deinflectedText && bestIndex < 0) {
|
|
|
|
bestIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const {term, reading} = headwords[Math.max(0, bestIndex)];
|
|
|
|
return {type, term, reading};
|
|
|
|
}
|
|
|
|
|
2020-09-09 20:57:35 +00:00
|
|
|
// Private
|
|
|
|
|
2021-07-06 23:43:53 +00:00
|
|
|
_createData(dictionaryEntry, mode, context, resultOutputMode, glossaryLayoutMode, compactTags, media) {
|
2021-04-01 00:07:11 +00:00
|
|
|
return {
|
2021-04-04 20:22:35 +00:00
|
|
|
dictionaryEntry,
|
2021-04-01 00:07:11 +00:00
|
|
|
mode,
|
|
|
|
context,
|
|
|
|
resultOutputMode,
|
|
|
|
glossaryLayoutMode,
|
|
|
|
compactTags,
|
2021-07-06 23:43:53 +00:00
|
|
|
media
|
2021-04-01 00:07:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-05 19:08:11 +00:00
|
|
|
async _formatField(field, commonData, template) {
|
|
|
|
const errors = [];
|
|
|
|
const requirements = [];
|
|
|
|
const value = await this._stringReplaceAsync(field, this._markerPattern, async (g0, marker) => {
|
2020-03-07 20:14:05 +00:00
|
|
|
try {
|
2021-07-05 19:08:11 +00:00
|
|
|
const {result, requirements: fieldRequirements} = await this._renderTemplateBatched(template, commonData, marker);
|
|
|
|
requirements.push(...fieldRequirements);
|
2021-06-26 21:05:55 +00:00
|
|
|
return result;
|
2020-03-07 20:14:05 +00:00
|
|
|
} catch (e) {
|
2021-07-03 15:30:48 +00:00
|
|
|
const error = new Error(`Template render error for {${marker}}`);
|
|
|
|
error.data = {error: e};
|
|
|
|
errors.push(error);
|
2020-03-07 20:14:05 +00:00
|
|
|
return `{${marker}-render-error}`;
|
|
|
|
}
|
|
|
|
});
|
2021-07-05 19:08:11 +00:00
|
|
|
return {value, errors, requirements};
|
2020-03-07 20:14:05 +00:00
|
|
|
}
|
2020-03-07 20:23:32 +00:00
|
|
|
|
2021-01-11 00:28:50 +00:00
|
|
|
async _stringReplaceAsync(str, regex, replacer) {
|
2020-03-07 20:23:32 +00:00
|
|
|
let match;
|
|
|
|
let index = 0;
|
|
|
|
const parts = [];
|
|
|
|
while ((match = regex.exec(str)) !== null) {
|
|
|
|
parts.push(str.substring(index, match.index), replacer(...match, match.index, str));
|
|
|
|
index = regex.lastIndex;
|
|
|
|
}
|
|
|
|
if (parts.length === 0) {
|
2021-01-11 00:28:50 +00:00
|
|
|
return str;
|
2020-03-07 20:23:32 +00:00
|
|
|
}
|
|
|
|
parts.push(str.substring(index));
|
2021-01-11 00:28:50 +00:00
|
|
|
return (await Promise.all(parts)).join('');
|
|
|
|
}
|
|
|
|
|
2021-04-02 23:09:21 +00:00
|
|
|
_getBatchedTemplateGroup(template) {
|
|
|
|
for (const item of this._batchedRequests) {
|
|
|
|
if (item.template === template) {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = {template, commonDataRequestsMap: new Map()};
|
|
|
|
this._batchedRequests.push(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderTemplateBatched(template, commonData, marker) {
|
|
|
|
const {promise, resolve, reject} = deferPromise();
|
|
|
|
const {commonDataRequestsMap} = this._getBatchedTemplateGroup(template);
|
|
|
|
let requests = commonDataRequestsMap.get(commonData);
|
|
|
|
if (typeof requests === 'undefined') {
|
|
|
|
requests = [];
|
|
|
|
commonDataRequestsMap.set(commonData, requests);
|
|
|
|
}
|
|
|
|
requests.push({resolve, reject, marker});
|
|
|
|
this._runBatchedRequestsDelayed();
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
_runBatchedRequestsDelayed() {
|
|
|
|
if (this._batchedRequestsQueued) { return; }
|
|
|
|
this._batchedRequestsQueued = true;
|
|
|
|
Promise.resolve().then(() => {
|
|
|
|
this._batchedRequestsQueued = false;
|
|
|
|
this._runBatchedRequests();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_runBatchedRequests() {
|
|
|
|
if (this._batchedRequests.length === 0) { return; }
|
|
|
|
|
|
|
|
const allRequests = [];
|
|
|
|
const items = [];
|
|
|
|
for (const {template, commonDataRequestsMap} of this._batchedRequests) {
|
|
|
|
const templateItems = [];
|
|
|
|
for (const [commonData, requests] of commonDataRequestsMap.entries()) {
|
|
|
|
const datas = [];
|
|
|
|
for (const {marker} of requests) {
|
|
|
|
datas.push(marker);
|
|
|
|
}
|
|
|
|
allRequests.push(...requests);
|
|
|
|
templateItems.push({type: 'ankiNote', commonData, datas});
|
|
|
|
}
|
|
|
|
items.push({template, templateItems});
|
|
|
|
}
|
|
|
|
|
|
|
|
this._batchedRequests.length = 0;
|
|
|
|
|
|
|
|
this._resolveBatchedRequests(items, allRequests);
|
|
|
|
}
|
|
|
|
|
|
|
|
async _resolveBatchedRequests(items, requests) {
|
|
|
|
let responses;
|
|
|
|
try {
|
|
|
|
responses = await this._templateRenderer.renderMulti(items);
|
|
|
|
} catch (e) {
|
|
|
|
for (const {reject} of requests) {
|
|
|
|
reject(e);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0, ii = requests.length; i < ii; ++i) {
|
|
|
|
const request = requests[i];
|
|
|
|
try {
|
|
|
|
const response = responses[i];
|
|
|
|
const {error} = response;
|
|
|
|
if (typeof error !== 'undefined') {
|
|
|
|
throw deserializeError(error);
|
|
|
|
} else {
|
|
|
|
request.resolve(response.result);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
request.reject(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-06 23:43:53 +00:00
|
|
|
|
|
|
|
async _injectMedia(dictionaryEntry, requirements, mediaOptions) {
|
|
|
|
const timestamp = Date.now();
|
|
|
|
|
|
|
|
// Parse requirements
|
|
|
|
let injectAudio = false;
|
|
|
|
let injectScreenshot = false;
|
|
|
|
let injectClipboardImage = false;
|
|
|
|
let injectClipboardText = false;
|
2021-07-08 00:00:30 +00:00
|
|
|
let injectSelectionText = false;
|
2021-07-09 21:48:27 +00:00
|
|
|
const textFuriganaDetails = [];
|
2021-07-07 02:00:18 +00:00
|
|
|
const dictionaryMediaDetails = [];
|
2021-07-06 23:43:53 +00:00
|
|
|
for (const requirement of requirements) {
|
|
|
|
const {type} = requirement;
|
|
|
|
switch (type) {
|
|
|
|
case 'audio': injectAudio = true; break;
|
|
|
|
case 'screenshot': injectScreenshot = true; break;
|
|
|
|
case 'clipboardImage': injectClipboardImage = true; break;
|
|
|
|
case 'clipboardText': injectClipboardText = true; break;
|
2021-07-08 00:00:30 +00:00
|
|
|
case 'selectionText': injectSelectionText = true; break;
|
2021-07-09 21:48:27 +00:00
|
|
|
case 'textFurigana':
|
|
|
|
{
|
|
|
|
const {text, readingMode} = requirement;
|
|
|
|
textFuriganaDetails.push({text, readingMode});
|
|
|
|
}
|
|
|
|
break;
|
2021-07-07 02:00:18 +00:00
|
|
|
case 'dictionaryMedia':
|
|
|
|
{
|
|
|
|
const {dictionary, path} = requirement;
|
|
|
|
dictionaryMediaDetails.push({dictionary, path});
|
|
|
|
}
|
|
|
|
break;
|
2021-07-06 23:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate request data
|
|
|
|
const dictionaryEntryDetails = this.getDictionaryEntryDetailsForNote(dictionaryEntry);
|
|
|
|
let audioDetails = null;
|
|
|
|
let screenshotDetails = null;
|
|
|
|
const clipboardDetails = {image: injectClipboardImage, text: injectClipboardText};
|
|
|
|
if (injectAudio && dictionaryEntryDetails.type !== 'kanji') {
|
|
|
|
const audioOptions = mediaOptions.audio;
|
|
|
|
if (typeof audioOptions === 'object' && audioOptions !== null) {
|
2022-08-20 15:17:24 +00:00
|
|
|
const {sources, preferredAudioIndex, idleTimeout} = audioOptions;
|
|
|
|
audioDetails = {sources, preferredAudioIndex, idleTimeout};
|
2021-07-06 23:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (injectScreenshot) {
|
|
|
|
const screenshotOptions = mediaOptions.screenshot;
|
|
|
|
if (typeof screenshotOptions === 'object' && screenshotOptions !== null) {
|
|
|
|
const {format, quality, contentOrigin: {tabId, frameId}} = screenshotOptions;
|
|
|
|
if (typeof tabId === 'number' && typeof frameId === 'number') {
|
|
|
|
screenshotDetails = {tabId, frameId, format, quality};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-09 21:48:27 +00:00
|
|
|
let textFuriganaPromise = null;
|
|
|
|
if (textFuriganaDetails.length > 0) {
|
|
|
|
const textParsingOptions = mediaOptions.textParsing;
|
|
|
|
if (typeof textParsingOptions === 'object' && textParsingOptions !== null) {
|
|
|
|
const {optionsContext, scanLength} = textParsingOptions;
|
|
|
|
textFuriganaPromise = this._getTextFurigana(textFuriganaDetails, optionsContext, scanLength);
|
|
|
|
}
|
|
|
|
}
|
2021-07-06 23:43:53 +00:00
|
|
|
|
|
|
|
// Inject media
|
2021-07-08 00:00:30 +00:00
|
|
|
const selectionText = injectSelectionText ? this._getSelectionText() : null;
|
|
|
|
const injectedMedia = await yomichan.api.injectAnkiNoteMedia(
|
2021-07-06 23:43:53 +00:00
|
|
|
timestamp,
|
|
|
|
dictionaryEntryDetails,
|
|
|
|
audioDetails,
|
|
|
|
screenshotDetails,
|
2021-07-07 02:00:18 +00:00
|
|
|
clipboardDetails,
|
|
|
|
dictionaryMediaDetails
|
2021-07-06 23:43:53 +00:00
|
|
|
);
|
2021-07-08 00:00:30 +00:00
|
|
|
const {audioFileName, screenshotFileName, clipboardImageFileName, clipboardText, dictionaryMedia: dictionaryMediaArray, errors} = injectedMedia;
|
2021-07-09 21:48:27 +00:00
|
|
|
const textFurigana = textFuriganaPromise !== null ? await textFuriganaPromise : [];
|
2021-07-06 23:43:53 +00:00
|
|
|
|
|
|
|
// Format results
|
2021-07-07 02:00:18 +00:00
|
|
|
const dictionaryMedia = {};
|
|
|
|
for (const {dictionary, path, fileName} of dictionaryMediaArray) {
|
|
|
|
if (fileName === null) { continue; }
|
|
|
|
const dictionaryMedia2 = (
|
|
|
|
Object.prototype.hasOwnProperty.call(dictionaryMedia, dictionary) ?
|
|
|
|
(dictionaryMedia[dictionary]) :
|
|
|
|
(dictionaryMedia[dictionary] = {})
|
|
|
|
);
|
2021-07-10 00:14:05 +00:00
|
|
|
dictionaryMedia2[path] = {value: fileName};
|
2021-07-07 02:00:18 +00:00
|
|
|
}
|
2021-07-06 23:43:53 +00:00
|
|
|
const media = {
|
2021-07-10 00:14:05 +00:00
|
|
|
audio: (typeof audioFileName === 'string' ? {value: audioFileName} : null),
|
|
|
|
screenshot: (typeof screenshotFileName === 'string' ? {value: screenshotFileName} : null),
|
|
|
|
clipboardImage: (typeof clipboardImageFileName === 'string' ? {value: clipboardImageFileName} : null),
|
|
|
|
clipboardText: (typeof clipboardText === 'string' ? {value: clipboardText} : null),
|
|
|
|
selectionText: (typeof selectionText === 'string' ? {value: selectionText} : null),
|
2021-07-09 21:48:27 +00:00
|
|
|
textFurigana,
|
2021-07-06 23:43:53 +00:00
|
|
|
dictionaryMedia
|
|
|
|
};
|
|
|
|
return {media, errors};
|
|
|
|
}
|
2021-07-08 00:00:30 +00:00
|
|
|
|
|
|
|
_getSelectionText() {
|
|
|
|
return document.getSelection().toString();
|
|
|
|
}
|
2021-07-09 21:48:27 +00:00
|
|
|
|
|
|
|
async _getTextFurigana(entries, optionsContext, scanLength) {
|
|
|
|
const results = [];
|
|
|
|
for (const {text, readingMode} of entries) {
|
|
|
|
const parseResults = await yomichan.api.parseText(text, optionsContext, scanLength, true, false);
|
|
|
|
let data = null;
|
|
|
|
for (const {source, content} of parseResults) {
|
|
|
|
if (source !== 'scanning-parser') { continue; }
|
|
|
|
data = content;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (data !== null) {
|
2021-07-10 00:14:05 +00:00
|
|
|
const value = this._createFuriganaHtml(data, readingMode);
|
|
|
|
results.push({text, readingMode, details: {value}});
|
2021-07-09 21:48:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
_createFuriganaHtml(data, readingMode) {
|
|
|
|
let result = '';
|
|
|
|
for (const term of data) {
|
|
|
|
result += '<span class="term">';
|
|
|
|
for (const {text, reading} of term) {
|
|
|
|
if (reading.length > 0) {
|
|
|
|
const reading2 = this._convertReading(reading, readingMode);
|
|
|
|
result += `<ruby>${text}<rt>${reading2}</rt></ruby>`;
|
|
|
|
} else {
|
|
|
|
result += text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result += '</span>';
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
_convertReading(reading, readingMode) {
|
|
|
|
switch (readingMode) {
|
|
|
|
case 'hiragana':
|
|
|
|
return this._japaneseUtil.convertKatakanaToHiragana(reading);
|
|
|
|
case 'katakana':
|
|
|
|
return this._japaneseUtil.convertHiraganaToKatakana(reading);
|
|
|
|
default:
|
|
|
|
return reading;
|
|
|
|
}
|
|
|
|
}
|
2020-03-07 20:14:05 +00:00
|
|
|
}
|