diff options
author | StefanVukovic99 <stefanvukovic44@gmail.com> | 2024-06-20 19:27:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-20 17:27:02 +0000 |
commit | d2c930a94d6e445053bcb5e5bb629851165425fc (patch) | |
tree | 94ff7034e7d3ab36ed663f353aeb5486bd294d1c /ext/js/dictionary | |
parent | 1a866b3997310a04fc146b91eb47a59a3f049589 (diff) |
support css file in dictionaries (#1080)
* get styles in db
* get styles in settings
* use styles
* fix test
* scope
* fix comma separated
* escape dict name in css selector
* g regex
* get styles in anki
* fix tests
* more specificity
* whitespace
* test importing
* test handlebars
* add styles to glossary-first
Diffstat (limited to 'ext/js/dictionary')
-rw-r--r-- | ext/js/dictionary/dictionary-importer.js | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/ext/js/dictionary/dictionary-importer.js b/ext/js/dictionary/dictionary-importer.js index 62453a13..d558636e 100644 --- a/ext/js/dictionary/dictionary-importer.js +++ b/ext/js/dictionary/dictionary-importer.js @@ -189,7 +189,25 @@ export class DictionaryImporter { tagMeta: {total: tagList.length}, media: {total: media.length}, }; - const summary = this._createSummary(dictionaryTitle, version, index, {prefixWildcardsSupported, counts}); + + const stylesFileName = 'styles.css'; + const stylesFile = fileMap.get(stylesFileName); + let styles = ''; + if (typeof stylesFile !== 'undefined') { + styles = await this._getData(stylesFile, new TextWriter()); + const cssErrors = this._validateCss(styles); + if (cssErrors.length > 0) { + return { + errors: cssErrors, + result: null, + }; + } + } + + /** @type {import('dictionary-importer').SummaryDetails} */ + const summaryDetails = {prefixWildcardsSupported, counts, styles}; + + const summary = this._createSummary(dictionaryTitle, version, index, summaryDetails); await dictionaryDatabase.bulkAdd('dictionaries', [summary], 0, 1); // Add data @@ -267,13 +285,12 @@ export class DictionaryImporter { * @param {string} dictionaryTitle * @param {number} version * @param {import('dictionary-data').Index} index - * @param {{prefixWildcardsSupported: boolean, counts: import('dictionary-importer').SummaryCounts}} details + * @param {import('dictionary-importer').SummaryDetails} details * @returns {import('dictionary-importer').Summary} */ _createSummary(dictionaryTitle, version, index, details) { const indexSequenced = index.sequenced; - const {prefixWildcardsSupported, counts} = details; - + const {prefixWildcardsSupported, counts, styles} = details; /** @type {import('dictionary-importer').Summary} */ const summary = { title: dictionaryTitle, @@ -283,6 +300,7 @@ export class DictionaryImporter { importDate: Date.now(), prefixWildcardsSupported, counts, + styles, }; const {author, url, description, attribution, frequencyMode, sourceLanguage, targetLanguage} = index; @@ -332,6 +350,14 @@ export class DictionaryImporter { } /** + * @param {string} css + * @returns {Error[]} + */ + _validateCss(css) { + return css ? [] : [new Error('No styles found')]; + } + + /** * @param {import('dictionary-data').TermGlossaryText|import('dictionary-data').TermGlossaryImage|import('dictionary-data').TermGlossaryStructuredContent} data * @param {import('dictionary-database').DatabaseTermEntry} entry * @param {import('dictionary-importer').ImportRequirement[]} requirements |