From b765abc6de9377761098ebf6c4295fe3795bc04e Mon Sep 17 00:00:00 2001 From: Stephen Mwangi Date: Mon, 14 Oct 2024 18:08:41 +0300 Subject: [PATCH] fix: cloze patterns settings upgrade --- docs/docs/en/flashcards/cloze-cards.md | 9 +++++++-- docs/docs/en/resources.md | 2 +- src/lang/locale/ar.ts | 2 +- src/lang/locale/en.ts | 2 +- src/lang/locale/ko.ts | 2 +- src/settings.ts | 26 +++++++++----------------- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/docs/docs/en/flashcards/cloze-cards.md b/docs/docs/en/flashcards/cloze-cards.md index 2f38627c..acd2a213 100644 --- a/docs/docs/en/flashcards/cloze-cards.md +++ b/docs/docs/en/flashcards/cloze-cards.md @@ -143,13 +143,18 @@ 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}}`

Or, with hint:
`Brazilians speak {{Portuguese::language}}` | `Brazilians speak {{1::Portuguese}}`

Or, with hint:
`Brazilians speak {{1::Portuguese::language}}` | `Brazilians speak {{a::Portuguese}}`

Or, with hint:
`Brazilians speak {{a::Portuguese::language}}` | -| Highlighted pattern with hint and sequencer in footnotes.

**Note that you can use brackets as part of your pattern, but you need to escape them.** | `==answer==[^\\[hint\\]][\\[^123\\]]` | `Brazilians speak ==Portuguese==`

Or, with hint:
`Brazilians speak ==Portuguese==^[language]` | `Brazilians speak ==Portuguese==[^1]`

Or, with hint:
`Brazilians speak ==Portuguese==^[language][^1]` | `Brazilians speak ==Portuguese==[^a]`

Or, with hint:
`Brazilians speak ==Portuguese==^[language][^a]` | +| Highlighted pattern with hint and sequencer in footnotes. | `==answer==[^\\[hint\\]][\\[^123\\]]` | `Brazilians speak ==Portuguese==`

Or, with hint:
`Brazilians speak ==Portuguese==^[language]` | `Brazilians speak ==Portuguese==[^1]`

Or, with hint:
`Brazilians speak ==Portuguese==^[language][^1]` | `Brazilians speak ==Portuguese==[^a]`

Or, with hint:
`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.
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 `\\`.
+ 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: ``` diff --git a/docs/docs/en/resources.md b/docs/docs/en/resources.md index be7d7790..469b2ccc 100644 --- a/docs/docs/en/resources.md +++ b/docs/docs/en/resources.md @@ -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). diff --git a/src/lang/locale/ar.ts b/src/lang/locale/ar.ts index efe8035a..a6357ef0 100644 --- a/src/lang/locale/ar.ts +++ b/src/lang/locale/ar.ts @@ -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", diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index d1a1076d..264f17fb 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -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", diff --git a/src/lang/locale/ko.ts b/src/lang/locale/ko.ts index b97ad5c8..2954671a 100644 --- a/src/lang/locale/ko.ts +++ b/src/lang/locale/ko.ts @@ -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: "빈 칸 채우기 패턴", diff --git a/src/settings.ts b/src/settings.ts index 52b12cc7..9d0c7a96 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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]}}"); } }