Skip to content

Trying to format output for Anki from Jitendex dictionary #4

@ajbjc

Description

@ajbjc

Using {py-glossary} with the code:

{{!~ bring the glossary entry in a coherent HTML-list format ~}}
{{#*inline "py-format-structured"}}
    {{~#scope~}}
        <div data-type="glossary">
        {{~#if (op ">=" length 1)~}}
            {{~#each .~}}
                <div data-type="glossary-entry">{{content}}</div>
            {{~/each~}}
        {{~else~}}
            <div data-type="glossary-entry">{{content}}</div>
        {{~/if~}}
        </div>
    {{~/scope~}}
{{/inline}}

{{!~ create html elements from the given structure ~}}
{{#*inline "py-structured-to-html"}}
    {{~#if tag~}}
        <{{tag}}>{{>py-format-html content~}}
    {{~else~}}
        {{.}}
    {{~/if~}}
    {{~#if tag~}}
        </{{tag}}>
    {{~/if~}}
{{/inline}}

{{!~ unwrap list objects ~}}
{{#*inline "py-format-html"}}
    {{~#if (op "&&"(op "==" (typeof .) "object") (op ">" length 1))~}}
        {{~#each .~}}
            {{~>py-structured-to-html .}}
        {{~/each~}}
    {{~else~}}
        {{~>py-structured-to-html .}}
    {{~/if~}}
{{/inline}}

{{!~ recursively search in the glossary for the tags and the entry marked as "glossary", containing the definitions ~}}
{{#*inline "py-unwrap-structured"}}  
    {{~#scope~}}
        {{~#set "is_glossary"~}}
            {{~#regexMatch "glossary" "g"~}}{{data.content}}{{~/regexMatch~}}   {{!~ if data.content contains the word "glossary", content contains the entries ~}}
        {{~/set~}}
        {{~#set "is_ex_sentence"~}}
            {{~#regexMatch "sentence" "g"~}}{{data.content}}{{~/regexMatch~}}
        {{~/set~}}
        {{~#set "is_note"~}}
            {{~#regexMatch "note" "g"~}}{{data.content}}{{~/regexMatch~}}
        {{~/set~}}

        {{~#if (get "is_glossary")~}}
            {{~>py-format-structured content~}}
        {{~else if (get "is_ex_sentence")~}}
            <li data-type="example-sentence">{{>py-format-html content}}</li>
        {{~else if (get "is_note")~}}
            <li data-type="notes">{{>py-format-html content}}</li>
        {{~else if data.code~}} {{!~ only tags seem to have a data.code element ~}}
            <i class="tag popup" data-type="tag" data-tag-name="{{~data.code~}}" data-tag-notes="{{~content.title~}}" data-tag-category="">{{~data.code~}}<span class="popup-text">{{~content.title~}}</span></i>
        {{~else if (op ">=" length 1)~}}
            {{~#each .~}}
                {{~>py-unwrap-structured .~}}
            {{/each}}
        {{~else if content~}}
            {{~>py-unwrap-structured content~}}
        {{~/if~}}
    {{~/scope~}}
{{/inline}}

{{#*inline "py-glossary-single"~}}
    <div data-dictionary="{{~dictionary~}}">
    {{~#each definitionTags~}}
        <i class="tag popup" data-type="tag" data-tag-name="{{~name~}}" data-tag-notes="{{~notes~}}" data-tag-category="{{~category~}}">{{~name~}}<span class="popup-text">{{~notes~}}</span></i>
    {{~/each~}}
    {{~#each glossary~}}
        {{~#if (op "==" type "structured-content")~}}
            {{~>py-unwrap-structured .~}}
        {{~else~}}
            <div data-type="glossary-entry">{{.}}</div>
        {{~/if~}}
    {{~/each~}}
    </div>
{{~/inline}}

{{!~ extract the glossary entries with their tags ~}}
{{#*inline "py-glossary"}}
    {{~#if (op "===" definition.type "term")~}}
        {{~> py-glossary-single definition~}}
    {{~else if (op "||" (op "===" definition.type "termGrouped") (op "===" definition.type "termMerged"))~}}
        {{~#each definition.definitions~}}
            {{~> py-glossary-single~}}
        {{~/each~}}
    {{~/if~}}
{{/inline}}

I get the result
Capture5

Whereas, when I use {glossary-brief} with the code:

{{#*inline "glossary-single"}}
    {{~#unless brief~}}
        {{~#scope~}}
            {{~set "any" false~}}
            {{~#each definitionTags~}}
                {{~#if (op "||" (op "!" @root.compactTags) (op "!" redundant))~}}
                    {{~#if (get "any")}}, {{else}}<i>({{/if~}}
                    {{name}}
                    {{~set "any" true~}}
                {{~/if~}}
            {{~/each~}}
            {{~#unless noDictionaryTag~}}
                {{~#if (op "||" (op "!" @root.compactTags) (op "!==" dictionary (get "previousDictionary")))~}}
                    {{~#if (get "any")}}, {{else}}<i>({{/if~}}
                    {{dictionaryAlias}}
                    {{~set "any" true~}}
                {{~/if~}}
            {{~/unless~}}
            {{~#if (get "any")}})</i> {{/if~}}
        {{~/scope~}}
        {{~#if only~}}({{#each only}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} only) {{/if~}}
    {{~/unless~}}
    {{~#if (op "<=" glossary.length 1)~}}
        {{#each glossary}}{{formatGlossary ../dictionary .}}{{/each}}
    {{~else if @root.compactGlossaries~}}
        {{#each glossary}}{{formatGlossary ../dictionary .}}{{#unless @last}} | {{/unless}}{{/each}}
    {{~else~}}
        {{#each glossary}}{{formatGlossary ../dictionary .}}{{/each}}
    {{~/if~}}
    {{~set "previousDictionary" dictionary~}}
{{/inline}}

{{~#*inline "glossary"~}}
    <div style="text-align: center;" class="yomitan-glossary">
    {{~#scope~}}
        {{~#if (op "===" definition.type "term")~}}
            {{~#unless (op "&&" selectedDictionary (op "!=" selectedDictionary definition.dictionary))~}}
                {{~> glossary-single definition brief=brief noDictionaryTag=noDictionaryTag ~}}
                {{~#if definition.glossaryScopedStyles~}}
                    <style>{{{definition.glossaryScopedStyles}}}</style>
                {{~/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))~}}
                            <div data-dictionary="{{dictionary}}">
                                {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}
                            </div>
                            {{~#if dictScopedStyles~}}
                                <style>{{{dictScopedStyles}}}</style>
                            {{~/if~}}
                        {{~/unless~}}
                    {{~/each~}}
            {{~else~}}
                {{~#each definition.definitions~}}
                    {{~#unless (op "&&" ../selectedDictionary (op "!=" ../selectedDictionary dictionary))~}}
                        {{~> glossary-single . brief=../brief noDictionaryTag=../noDictionaryTag ~}}
                        {{~#if glossaryScopedStyles~}}
                            <style>{{{glossaryScopedStyles}}}</style>
                        {{~/if~}}
                    {{~/unless~}}
                {{~/each~}}
            {{~/if~}}
        {{~else if (op "===" definition.type "kanji")~}}
            {{~#if (op ">" definition.glossary.length 1)~}}
                {{#each definition.glossary}}{{.}}{{/each}}
            {{~else~}}
                {{~#each definition.glossary~}}{{.}}{{~/each~}}
            {{~/if~}}
        {{~/if~}}
    {{~/scope~}}
    </div>
{{~/inline~}}

{{#*inline "glossary-brief"}}
    {{~> glossary brief=true ~}}
{{/inline}}

I get this:

Capture4

What I want is to remove the three different list elements above so they can all be centred.

While not the same word, an example of what I'm looking for is:

Capture6

Though in the case of 現在に至る, for example, all definitons would be included in their own groups, I can sort the rest out afterwards.

Also not sure if it's related to the dictionary I'm using or what's causing it but the compact glossary setting in yomitan doesn't carry over to Anki despite it appearing correctly in the yomitan popup so not sure what's going on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions