Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kleinerpirat
Copy link
Contributor

@kleinerpirat kleinerpirat commented Jul 17, 2022

Exposes clozed text as a data-attribute on the front side.
Use case: https://forums.ankiweb.net/t/an-improved-implementation-of-cloze-to-enable-sequential-uncovering/21489/6

Example

Input:

{{c1::hidden text}}

Output with current implementation:

<span class=cloze>[...]</span>

After this PR:

<span class="cloze" data-cloze="hidden text">[...]</span>

@kleinerpirat kleinerpirat force-pushed the expose-cloze branch 2 times, most recently from c4358dc to bcb60bb Compare July 17, 2022 13:33
to match Python's html.escape and pass tests.
@kleinerpirat
Copy link
Contributor Author

Perhaps it could be useful to expose the hint as data-hint as well and show it as a CSS pseudo-element. People could then make the hints show on hover/click or create tooltips:

{{c1::hidden text::hint}}
<span class="cloze" data-cloze="hidden text" data-hint="hint"></span>

A disadvantage of this approach is that pseudo-elements are not selectable since they're not part of the DOM.

@dae
Copy link
Member

dae commented Jul 18, 2022

No objections to adding hint as well, though let's avoid pseudo elements for now.

@kleinerpirat
Copy link
Contributor Author

Considering the hint is available as the innerHTML of a cloze anyway, I think I'll hold back on adding it as an attribute until a proper cloze overhaul is in the works. If the attribute isn't used by Anki itself (i.e. as pseudo-element content), it is redundant.

@dae
Copy link
Member

dae commented Jul 18, 2022

Sounds good. Thanks Matthias!

@dae dae merged commit d1ba48b into ankitects:main Jul 18, 2022
@kleinerpirat kleinerpirat deleted the expose-cloze branch July 24, 2022 20:29
@gomarcus
Copy link

Thanks @kleinerpirat for the implementation! Can hardly wait for the update to reach me. Added another idea to my suggestion in our last chat to expand the 'Cloze', which certainly has many practical applications. Would be very happy if these could be incorporated as well. Although this rather requires a revision of the backend.

https://forums.ankiweb.net/t/an-improved-implementation-of-cloze-to-enable-sequential-uncovering/21489/9

Proposal: A text cloze should be able to be assigned to several groups.

current: {{group::value::hint}}
proposal: {{group1,group2,group3::value::hint}}

Template:

The {{c1,c2::quick}} brown {{c2,c3::fox}} jumps over the lazy dog

Cards:

The [...] brown fox jumps over the lazy dog
The [...] brown [...] jumps over the lazy dog
The quick brown [...] jumps over the lazy dog

@triaeiou
Copy link
Contributor

To follow up with an additional suggestion that should be easy to implement with few maintenance issues: increase the meta data to allow easier addon creation:

  • Hint (as @kleinerpirat suggested)
  • Cloze ordinal
  • Wrap inactive clozes (i.e. the "other" clozes) in a <span> as well with the same meta data and a specific class, eg inactive.

So something like this
The {{c1::quick::speed}} brown {{c2::fox}} jumped over the lazy {{c2::dog}}

The <span class="cloze" data-cloze="quick" data-hint="speed" data-ordinal="1">quick</span> brown <span class="cloze inactive" data-cloze="fox" data-hint="" data-ordinal="2">fox</span> jumped over the lazy <span class="cloze inactive" data-cloze="dog" data-hint="" data-ordinal="2">dog</span>

It would be easy enough to make such a PR if there is an indication of it being welcome?

@dae
Copy link
Member

dae commented Oct 17, 2022

I'd be fine with accepting such a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants