From d2c930a94d6e445053bcb5e5bb629851165425fc Mon Sep 17 00:00:00 2001 From: StefanVukovic99 Date: Thu, 20 Jun 2024 19:27:02 +0200 Subject: 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 --- .../anki-field-templates-upgrade-v41.handlebars | 129 +++++++++++++++++++++ .../default-anki-field-templates.handlebars | 32 ++++- 2 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 ext/data/templates/anki-field-templates-upgrade-v41.handlebars (limited to 'ext/data/templates') diff --git a/ext/data/templates/anki-field-templates-upgrade-v41.handlebars b/ext/data/templates/anki-field-templates-upgrade-v41.handlebars new file mode 100644 index 00000000..4da7d1bb --- /dev/null +++ b/ext/data/templates/anki-field-templates-upgrade-v41.handlebars @@ -0,0 +1,129 @@ +{{<<<<<<<}} +{{~#*inline "glossary"~}} +
+ {{~#scope~}} + {{~#if (op "===" definition.type "term")~}} + {{~#unless (op "&&" selectedDictionary (op "!=" selectedDictionary definition.dictionary))~}} + {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}} + {{~/unless~}} + {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}} + {{~#if (op ">" definition.definitions.length 1)~}} +
    + {{~#each definition.definitions~}} + {{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}} +
  1. + {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}} +
  2. + {{~/unless~}} + {{~/each~}} +
+ {{~else~}} + {{~#each definition.definitions~}} + {{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}} + {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}} + {{~/unless~}} + {{~/each~}} + {{~/if~}} + {{~else if (op "===" definition.type "kanji")~}} + {{~#if (op ">" definition.glossary.length 1)~}} +
    {{#each definition.glossary}}
  1. {{.}}
  2. {{/each}}
+ {{~else~}} + {{~#each definition.glossary~}}{{.}}{{~/each~}} + {{~/if~}} + {{~/if~}} + {{~/scope~}} +
+{{~/inline~}} +{{=======}} +{{~#*inline "glossary"~}} +
+ {{~#scope~}} + {{~#if (op "===" definition.type "term")~}} + {{~#unless (op "&&" selectedDictionary (op "!=" selectedDictionary definition.dictionary))~}} + {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}} + {{~#if definition.glossaryScopedStyles~}} + + {{~/if~}} + {{~/unless~}} + {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}} + {{~#if (op ">" definition.definitions.length 1)~}} +
    + {{~#each definition.definitions~}} + {{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}} +
  1. + {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}} +
  2. + {{~#if dictScopedStyles~}} + + {{~/if~}} + {{~/unless~}} + {{~/each~}} +
+ {{~else~}} + {{~#each definition.definitions~}} + {{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}} + {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}} + {{~#if glossaryScopedStyles~}} + + {{~/if~}} + {{~/unless~}} + {{~/each~}} + {{~/if~}} + {{~else if (op "===" definition.type "kanji")~}} + {{~#if (op ">" definition.glossary.length 1)~}} +
    {{#each definition.glossary}}
  1. {{.}}
  2. {{/each}}
+ {{~else~}} + {{~#each definition.glossary~}}{{.}}{{~/each~}} + {{~/if~}} + {{~/if~}} + {{~/scope~}} +
+{{~/inline~}} +{{>>>>>>>}} + +{{<<<<<<<}} +{{~#*inline "glossary-first"~}} +
+ {{~#scope~}} + {{~#if (op "===" definition.type "term")~}} + {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}} + {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}} + {{~#if (op ">" definition.definitions.length 1)~}} + {{~#with definition.definitions.[0]~}}{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}{{~/with~}} + {{~else~}} + {{~#with definition.definitions.[0]~}}{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}{{~/with~}} + {{~/if~}} + {{~/if~}} + {{~/scope~}} +
+{{~/inline~}} +{{=======}} +{{~#*inline "glossary-first"~}} +
+ {{~#scope~}} + {{~#if (op "===" definition.type "term")~}} + {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}} + {{~#if definition.glossaryScopedStyles~}} + + {{~/if~}} + {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}} + {{~#if (op ">" definition.definitions.length 1)~}} + {{~#with definition.definitions.[0]~}} + {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}} + {{~#if glossaryScopedStyles~}} + + {{~/if~}} + {{~/with~}} + {{~else~}} + {{~#with definition.definitions.[0]~}} + {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}} + {{~#if glossaryScopedStyles~}} + + {{~/if~}} + {{~/with~}} + {{~/if~}} + {{~/if~}} + {{~/scope~}} +
+{{~/inline~}} +{{>>>>>>>}} \ No newline at end of file diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars index 44741866..2ac12934 100644 --- a/ext/data/templates/default-anki-field-templates.handlebars +++ b/ext/data/templates/default-anki-field-templates.handlebars @@ -98,20 +98,26 @@ {{/inline}} {{~#*inline "glossary"~}} -
+
{{~#scope~}} {{~#if (op "===" definition.type "term")~}} {{~#unless (op "&&" selectedDictionary (op "!=" selectedDictionary definition.dictionary))~}} {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}} + {{~#if definition.glossaryScopedStyles~}} + + {{~/if~}} {{~/unless~}} {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}} {{~#if (op ">" definition.definitions.length 1)~}}
    {{~#each definition.definitions~}} {{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}} -
  1. +
  2. {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}
  3. + {{~#if dictScopedStyles~}} + + {{~/if~}} {{~/unless~}} {{~/each~}}
@@ -119,6 +125,9 @@ {{~#each definition.definitions~}} {{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}} {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}} + {{~#if glossaryScopedStyles~}} + + {{~/if~}} {{~/unless~}} {{~/each~}} {{~/if~}} @@ -142,15 +151,28 @@ {{/inline}} {{~#*inline "glossary-first"~}} -
+
{{~#scope~}} {{~#if (op "===" definition.type "term")~}} {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}} + {{~#if definition.glossaryScopedStyles~}} + + {{~/if~}} {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}} {{~#if (op ">" definition.definitions.length 1)~}} - {{~#with definition.definitions.[0]~}}{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}{{~/with~}} + {{~#with definition.definitions.[0]~}} + {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}} + {{~#if glossaryScopedStyles~}} + + {{~/if~}} + {{~/with~}} {{~else~}} - {{~#with definition.definitions.[0]~}}{{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}{{~/with~}} + {{~#with definition.definitions.[0]~}} + {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}} + {{~#if glossaryScopedStyles~}} + + {{~/if~}} + {{~/with~}} {{~/if~}} {{~/if~}} {{~/scope~}} -- cgit v1.2.3