Skip to content

Commit

Permalink
fix: cloze patterns settings upgrade (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
st3v3nmw authored Oct 14, 2024
1 parent 4f24409 commit 6658797
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
8 changes: 8 additions & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [1.13.1](https://github.com/st3v3nmw/obsidian-spaced-repetition/compare/1.13.0...1.13.1)

- docs: update README links [`#1120`](https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/1120)
- fix: cloze patterns settings upgrade [`b765abc`](https://github.com/st3v3nmw/obsidian-spaced-repetition/commit/b765abc6de9377761098ebf6c4295fe3795bc04e)

#### [1.13.0](https://github.com/st3v3nmw/obsidian-spaced-repetition/compare/1.12.9...1.13.0)

> 13 October 2024
- chore: bump version to v1.13.0 [`#1119`](https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/1119)
- docs: document custom cloze patterns [`#1118`](https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/1118)
- refactor: parser & cloze patterns [`#1117`](https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/1117)
- fix(ui): render markdown content for questions in nested lists [`#1114`](https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/1114)
Expand Down
15 changes: 10 additions & 5 deletions docs/docs/en/flashcards/cloze-cards.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,21 @@ Brackets `[]` delineate where the sequence number and hint will be placed, along

Here are some examples of custom patterns:

| Explanation | Pattern in the Settings | Simplified Cloze Usage | Numbered Cloze Usage | Generalized Cloze Overlapping Usage |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| Anki-Like Pattern | `{{[123::]answer[::hint]}}` | `Brazilians speak {{Portuguese}}`<br><br>Or, with hint:<br>`Brazilians speak {{Portuguese::language}}` | `Brazilians speak {{1::Portuguese}}`<br><br>Or, with hint:<br>`Brazilians speak {{1::Portuguese::language}}` | `Brazilians speak {{a::Portuguese}}`<br><br>Or, with hint:<br>`Brazilians speak {{a::Portuguese::language}}` |
| Highlighted pattern with hint and sequencer in footnotes. <br/><br/> **Note that you can use brackets as part of your pattern, but you need to escape them.** | `==answer==[^\\[hint\\]][\\[^123\\]]` | `Brazilians speak ==Portuguese==`<br><br>Or, with hint:<br>`Brazilians speak ==Portuguese==^[language]` | `Brazilians speak ==Portuguese==[^1]`<br><br>Or, with hint:<br>`Brazilians speak ==Portuguese==^[language][^1]` | `Brazilians speak ==Portuguese==[^a]`<br><br>Or, with hint:<br>`Brazilians speak ==Portuguese==^[language][^a]` |
| Explanation | Pattern in the Settings | Simplified Cloze Usage | Numbered Cloze Usage | Generalized Cloze Overlapping Usage |
| --------------------------------------------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| Anki-Like Pattern | `{{[123::]answer[::hint]}}` | `Brazilians speak {{Portuguese}}`<br><br>Or, with hint:<br>`Brazilians speak {{Portuguese::language}}` | `Brazilians speak {{1::Portuguese}}`<br><br>Or, with hint:<br>`Brazilians speak {{1::Portuguese::language}}` | `Brazilians speak {{a::Portuguese}}`<br><br>Or, with hint:<br>`Brazilians speak {{a::Portuguese::language}}` |
| Highlighted pattern with hint and sequencer in footnotes. | `==answer==[^\\[hint\\]][\\[^123\\]]` | `Brazilians speak ==Portuguese==`<br><br>Or, with hint:<br>`Brazilians speak ==Portuguese==^[language]` | `Brazilians speak ==Portuguese==[^1]`<br><br>Or, with hint:<br>`Brazilians speak ==Portuguese==^[language][^1]` | `Brazilians speak ==Portuguese==[^a]`<br><br>Or, with hint:<br>`Brazilians speak ==Portuguese==^[language][^a]` |

!!! warning

Make sure that your custom cloze patterns do not conflict with other flashcard separators.
Make sure that your custom cloze patterns do not conflict with other flashcard separators.<br/>
For instance, the Anki-Like pattern `{{[123::]answer[::hint]}}` conflicts with the default single line flashcard separator `::`.

!!! warning

You can use brackets as part of your pattern, but you need to [escape](https://en.wikipedia.org/wiki/Escape_character) them with `\\`.<br/>
For instance, in the pattern `==answer==[^\\[hint\\]][\\[^123\\]]`, the brackets _inside_ the outer brackets are escaped (`^\\[hint\\]` & `\\[^123\\]`).

In your settings, you can add multiple patterns at once, separating them with a new line:

```
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/en/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

This was introduced [here](https://github.com/st3v3nmw/obsidian-spaced-repetition/issues/15) by `@aviskase`.

### Brief summary
#### Brief summary

Andy Matuschak uses [spaced repetition system for working on writing inbox](https://notes.andymatuschak.org/z7iCjRziX6V6unNWL81yc2dJicpRw2Cpp9MfQ).

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-spaced-repetition",
"name": "Spaced Repetition",
"version": "1.13.0",
"version": "1.13.1",
"minAppVersion": "1.2.8",
"description": "Fight the forgetting curve by reviewing flashcards & entire notes.",
"author": "Stephen Mwangi",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-spaced-repetition",
"version": "1.13.0",
"version": "1.13.1",
"description": "Fight the forgetting curve by reviewing flashcards & entire notes.",
"main": "main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/lang/locale/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default {
"Randomly (once all cards in previous deck reviewed)",
REVIEW_DECK_ORDER_RANDOM_DECK_AND_CARD: "Random card from random deck",
DISABLE_CLOZE_CARDS: "؟cloze تعطيل بطاقات",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==hightlights== to clozes?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==highlights== to clozes?",
CONVERT_BOLD_TEXT_TO_CLOZES: "Convert **bolded text** to clozes?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Convert {{curly brackets}} to clozes?",
CLOZE_PATTERNS: "Cloze Patterns",
Expand Down
2 changes: 1 addition & 1 deletion src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
"Randomly (once all cards in previous deck reviewed)",
REVIEW_DECK_ORDER_RANDOM_DECK_AND_CARD: "Random card from random deck",
DISABLE_CLOZE_CARDS: "Disable cloze cards?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==hightlights== to clozes?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==highlights== to clozes?",
CONVERT_BOLD_TEXT_TO_CLOZES: "Convert **bolded text** to clozes?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Convert {{curly brackets}} to clozes?",
CLOZE_PATTERNS: "Cloze Patterns",
Expand Down
2 changes: 1 addition & 1 deletion src/lang/locale/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default {
"Randomly (once all cards in previous deck reviewed)",
REVIEW_DECK_ORDER_RANDOM_DECK_AND_CARD: "Random card from random deck",
DISABLE_CLOZE_CARDS: "빈 칸 채우기 카드를 비활성화하시겠습니까?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "==hightlights== 를 빈 칸 채우기로 전환하시겠습니까?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "==highlights== 를 빈 칸 채우기로 전환하시겠습니까?",
CONVERT_BOLD_TEXT_TO_CLOZES: "**bolded text** 를 빈 칸 채우기로 전환하시겠습니까?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "{{curly brackets}} 를 빈 칸 채우기로 전환하시겠습니까?",
CLOZE_PATTERNS: "빈 칸 채우기 패턴",
Expand Down
26 changes: 9 additions & 17 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,17 @@ export function upgradeSettings(settings: SRSettings) {
settings.randomizeCardOrder = null;
}

if (
settings.convertHighlightsToClozes &&
!settings.clozePatterns.contains("==[123;;]answer[;;hint]==")
) {
settings.clozePatterns.push("==[123;;]answer[;;hint]==");
}
if (settings.clozePatterns == null) {
settings.clozePatterns = [];

if (
settings.convertBoldTextToClozes &&
!settings.clozePatterns.contains("**[123;;]answer[;;hint]**")
) {
settings.clozePatterns.push("**[123;;]answer[;;hint]**");
}
if (settings.convertHighlightsToClozes)
settings.clozePatterns.push("==[123;;]answer[;;hint]==");

if (
settings.convertCurlyBracketsToClozes &&
!settings.clozePatterns.contains("{{[123;;]answer[;;hint]}}")
) {
settings.clozePatterns.push("{{[123;;]answer[;;hint]}}");
if (settings.convertBoldTextToClozes)
settings.clozePatterns.push("**[123;;]answer[;;hint]**");

if (settings.convertCurlyBracketsToClozes)
settings.clozePatterns.push("{{[123;;]answer[;;hint]}}");
}
}

Expand Down

0 comments on commit 6658797

Please sign in to comment.