hgiesel / closet

The Web Framework for Flashcards
https://closetengine.com
GNU General Public License v3.0
65 stars 6 forks source link

Conflict with Japanese Support add-on #27

Closed Incina76 closed 4 years ago

Incina76 commented 4 years ago

both add-ons use the [ ] bracket on cards to trigger their effects. so when i try to use you cloze deletion on my cards I get the un hidden part of the sentence with the cloze deletion code as furigana above it.

Incina76 commented 4 years ago

Illustration

hgiesel commented 4 years ago

The Japanese Support add-on has this to say:

To show furigana with your own note types:

  • You need a directive like "{{furigana:Reading}}" in your card templates.
  • The Reading field must be formatted in a special way with brackets. After every word should come the reading in brackets, followed by a space. It is not intended to be entered in manually; it is intended to be automatically generated as described in the above section.

So it seems like you need to change {{furigana:Example Sentence w/ Blanked Out Word (optional)}} into {{Example Sentence w/ Blanked Out Word (optional)}} in the card template.

Incina76 commented 4 years ago

that will allow closet to work on that line, but will prevent me from using Furigana on any line I want to use the clozet's effects with. if possible i would like to be able to use both. Is it possible for me to edit something so closet uses { } or <> to trigger?

hgiesel commented 4 years ago

Yes, they are defined in the source code in a single location: https://github.com/hgiesel/closet/blob/70b85670a825e30aeae3de0b3e034ed8ca809609/src/template/utils.ts#L1. You would need to find this location in the compiled Closet code, and change it to what you want. You should be able to find by looking for "[[". Note that at least for now, you would have to repeat this, every time I push another version of the Closet add-on, however I could make this configurable in the future: #28.

Another idea: Create a Closet filter, that creates Ruby text (furigana). In fact I use this:

function rubySupport(filterManager) {

const rubyStylizer = closet.Stylizer.make({
  separator: '',
  mapper: (v, i) => i === 0
    ? `<rb>${v}</rb>`
    : `<rt>${v}</rt>`,
  processor: (v) => `<ruby>${v}</ruby>`,
})

filterManager.install(closet.recipes.stylize({ 
    tagname: 'rb',
    separator: { sep: '::', max: 2 },
    stylizer: rubyStylizer,
}))

}

That allows you to create ruby text like so: [[rb::家::いえ]] will turn into いえ

Incina76 commented 4 years ago

Am I doing this wrong? I've open Closet.js in notepad++ and searched [[ and found t.TAG_OPEN="[[",t.TAG_CLOSE="]]" and changed it to t.TAG_OPEN="<<",t.TAG_CLOSE=">>" restarted anki and write to template again and change the line in anki to <<c0::起きます::起きる>> and its not working. am i editing the wrong file or the wrong place in the code? and thanks for the help i know this isn't exactly and issue with your add-on.

hgiesel commented 4 years ago

The problem here is that "<" and ">" are treated special in HTML. You can look at the HTML you generated by using Ctrl-Shift-X (Cmd-Shift-X on Mac).

image

The < and > are translated to &lt; (less than) and &gt; (greater than). So in your case you would want:

t.TAG_OPEN="&lt;&lt;",t.TAG_CLOSE="&gt;&gt;"
Incina76 commented 4 years ago

I'm still having no luck I've tried t.TAG_OPEN="&lt;&lt;",t.TAG_CLOSE="&gt;&gt;" t.TAG_OPEN="&lt;",t.TAG_CLOSE="&gt;" t.TAG_OPEN="{{",t.TAG_CLOSE="}}" t.TAG_OPEN="??",t.TAG_CLOSE="]]" it only seems to work if i change it back to t.TAG_OPEN="[[",t.TAG_CLOSE="]]" the ctrl+shift+X thing dosn't work either Thanks again i saw that you added a plan to make them configurable.

hgiesel commented 4 years ago

Okay, I definitely had setting the delimiters to something else in the back of my mind while developing, however I never tried it, to make sure it actually works.

It seems there are still a few places where it's unsupported. I will see that I fix that very soon.

Incina76 commented 4 years ago

Ill look forward to it.

hgiesel commented 4 years ago

I just uploaded a new version, which at least makes the delimiters settable, however you will still need to redo it, if I were to update Closet again (and you choose Write to Templates) again.

Incina76 commented 4 years ago

Just updated it and tested it seems to be working now. Thank you!

hgiesel commented 4 years ago

I just pushed a new version, which has a few radical changes, but it also has better support for setting custom delimiters via JavaScript. You can read about them in #28.

Incina76 commented 4 years ago

i'm not sure what to do to configure it to use the different delimiters. in #28 you said i had to call closet.setDelimiters('[[', '::', ']]') Im not sure how or where to do that.

hgiesel commented 4 years ago

I'm actually still working on this. I tried it out myself in order to demonstrate it to you, but that's when I figured out there was still a bug. Give me a moment, I'll try to figure as we're speaking.