Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for many clozures within a single flashcard #796

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 54 additions & 23 deletions src/QuestionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,60 @@ class QuestionType_Cloze implements IQuestionTypeHandler {
let front: string, back: string;
const result: CardFrontBack[] = [];
for (const m of siblings) {
const deletionStart: number = m.index,
deletionEnd: number = deletionStart + m[0].length;
front =
questionText.substring(0, deletionStart) +
QuestionType_ClozeUtil.renderClozeFront() +
questionText.substring(deletionEnd);
front = front
.replace(/==/gm, "")
.replace(/\*\*/gm, "")
.replace(/{{/gm, "")
.replace(/}}/gm, "");
back =
questionText.substring(0, deletionStart) +
QuestionType_ClozeUtil.renderClozeBack(
questionText.substring(deletionStart, deletionEnd),
) +
questionText.substring(deletionEnd);
back = back
.replace(/==/gm, "")
.replace(/\*\*/gm, "")
.replace(/{{/gm, "")
.replace(/}}/gm, "");
result.push(new CardFrontBack(front, back));
if (settings.manyClozes) {
let characterSet = "";
if (settings.convertHighlightsToClozes) {
characterSet += "=";
}
if (settings.convertBoldTextToClozes) {
characterSet += "*";
}
if (settings.convertCurlyBracketsToClozes) {
characterSet += "{}";
}
if (characterSet.length > 0) {
const expression = new RegExp(
`([${characterSet}])\\1(.+?)([${characterSet}])\\3`,
"gm",
);
result.push(
new CardFrontBack(
questionText.replace(
expression,
QuestionType_ClozeUtil.renderClozeFront(),
),
questionText.replace(
expression,
QuestionType_ClozeUtil.renderClozeBack("$2"),
),
),
);
}
} else {
const deletionStart: number = m.index,
deletionEnd: number = deletionStart + m[0].length;
front =
questionText.substring(0, deletionStart) +
QuestionType_ClozeUtil.renderClozeFront() +
questionText.substring(deletionEnd);
front = front
.replace(/==/gm, "")
.replace(/\*\*/gm, "")
.replace(/{{/gm, "")
.replace(/}}/gm, "");
back =
questionText.substring(0, deletionStart) +
QuestionType_ClozeUtil.renderClozeBack(
questionText.substring(deletionStart, deletionEnd),
) +
questionText.substring(deletionEnd);
back = back
.replace(/==/gm, "")
.replace(/\*\*/gm, "")
.replace(/{{/gm, "")
.replace(/}}/gm, "");
result.push(new CardFrontBack(front, back));
}
}

return result;
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "نسبة عرض البطاقة",
RANDOMIZE_CARD_ORDER: "ترتيب بطاقة عشوائي أثناء المراجعة؟",
DISABLE_CLOZE_CARDS: "؟cloze تعطيل بطاقات",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==hightlights== to clozes?",
CONVERT_BOLD_TEXT_TO_CLOZES: "Convert **bolded text** to clozes?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Convert {{curly brackets}} to clozes?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/cz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "Šířka kartiček v procentech",
RANDOMIZE_CARD_ORDER: "Náhodně změnit pořadí kartiček během revize?",
DISABLE_CLOZE_CARDS: "Vypnout cloze kartičky?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Převést ==zvýraznění== na clozes?",
CONVERT_BOLD_TEXT_TO_CLOZES: "Převést **tučný text** na clozes?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Převést {{složené závorky}} na clozes?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "Breite einer Lernkarte in Prozent",
RANDOMIZE_CARD_ORDER: "Während der Wiederhoung die Reihenfolge zufällig mischen?",
DISABLE_CLOZE_CARDS: "Lückentextkarten (cloze deletions) deaktivieren?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "==Hervorgehobenen== Text in Lückentextkarten umwandeln?",
CONVERT_BOLD_TEXT_TO_CLOZES: "**Fettgedruckten** Text in Lückentextkarten umwandeln?",
CONVERT_CURLY_BRACKETS_TO_CLOZES:
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "Flashcard Width Percentage",
RANDOMIZE_CARD_ORDER: "Randomize card order during review?",
DISABLE_CLOZE_CARDS: "Disable cloze cards?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==hightlights== to clozes?",
CONVERT_BOLD_TEXT_TO_CLOZES: "Convert **bolded text** to clozes?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Convert {{curly brackets}} to clozes?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "Porcentaje del ancho de las tarjetas de memoria",
RANDOMIZE_CARD_ORDER: "¿Aleatorizar el orden de las tarjetas para revisión?",
DISABLE_CLOZE_CARDS: "¿Deshabilitar deletreo de huecos en las tarjetas?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "¿Convertir ==resaltados== a deletreo de huecos?",
CONVERT_BOLD_TEXT_TO_CLOZES: "¿Convertir **texto en negrita** a deletreo de huecos?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "¿Convertir {{llaves rizadas}} a deletreo de huecos?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "フラッシュカードの横サイズのパーセンテージ",
RANDOMIZE_CARD_ORDER: "レビュー中のカードの順番をランダムにしますか?",
DISABLE_CLOZE_CARDS: "穴埋めカードを無効化しますか?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "==ハイライト==を穴埋めとして使用しますか?",
CONVERT_BOLD_TEXT_TO_CLOZES: "**ボールド体**を穴埋めとして使用しますか?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "{{中括弧}}を穴埋めとして使用しますか?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "플래시카드 너비 비율",
RANDOMIZE_CARD_ORDER: "리뷰중인 카드의 순서를 랜덤으로 두시겠습니까?",
DISABLE_CLOZE_CARDS: "빈 칸 채우기 카드를 비활성화하시겠습니까?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "==hightlights== 를 빈 칸 채우기로 전환하시겠습니까?",
CONVERT_BOLD_TEXT_TO_CLOZES: "**bolded text** 를 빈 칸 채우기로 전환하시겠습니까?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "{{curly brackets}} 를 빈 칸 채우기로 전환하시겠습니까?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "Porcentagem de Largura do Flashcard",
RANDOMIZE_CARD_ORDER: "Aleatorizar a ordem das cartas durante a revisão?",
DISABLE_CLOZE_CARDS: "Desabilitar cartas que usam omissão de palavras?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Converter ==marca-texto== em omissões?",
CONVERT_BOLD_TEXT_TO_CLOZES: "Converter **texto em negrito** em omissões?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Converter {{chaves}} em omissões?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "Ширина карточки в процентах",
RANDOMIZE_CARD_ORDER: "Случайный порядок карточек во время повторения?",
DISABLE_CLOZE_CARDS: "Выключить карты с пропусками (пример: [...])?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Конвертировать ==выделенный текст== в пропуски (пример: [...])?",
CONVERT_BOLD_TEXT_TO_CLOZES: "Конвертировать **жирный текст** в пропуски (пример: [...])?",
CONVERT_CURLY_BRACKETS_TO_CLOZES:
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "卡片宽度百分比",
RANDOMIZE_CARD_ORDER: "复习时随机显示卡片?",
DISABLE_CLOZE_CARDS: "不进行完形填空?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "将 ==高亮== 转换为完形填空?",
CONVERT_BOLD_TEXT_TO_CLOZES: "将 **粗体** 转换为完形填空?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "将 {{大括号}} 转换为完形填空?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/locale/zh-tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
CARD_MODAL_WIDTH_PERCENT: "卡片寬度百分比",
RANDOMIZE_CARD_ORDER: "復習時隨機顯示卡片?",
DISABLE_CLOZE_CARDS: "停用填空克漏字卡片?",
MANY_CLOZE: "Combine all clozes into one card?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "將 ==高亮== 轉換為填空克漏字?",
CONVERT_BOLD_TEXT_TO_CLOZES: "將 **粗體** 轉換為填空克漏字?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "將 {{大括號}} 轉換為填空克漏字?",
Expand Down
9 changes: 9 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface SRSettings {
flashcardHeightPercentage: number;
flashcardWidthPercentage: number;
randomizeCardOrder: boolean;
manyClozes: boolean;
convertHighlightsToClozes: boolean;
convertBoldTextToClozes: boolean;
convertCurlyBracketsToClozes: boolean;
Expand Down Expand Up @@ -56,6 +57,7 @@ export const DEFAULT_SETTINGS: SRSettings = {
flashcardHeightPercentage: Platform.isMobile ? 100 : 80,
flashcardWidthPercentage: Platform.isMobile ? 100 : 40,
randomizeCardOrder: true,
manyClozes: false,
convertHighlightsToClozes: true,
convertBoldTextToClozes: false,
convertCurlyBracketsToClozes: false,
Expand Down Expand Up @@ -251,6 +253,13 @@ export class SRSettingTab extends PluginSettingTab {
}),
);

new Setting(containerEl).setName(t("MANY_CLOZE")).addToggle((toggle) =>
toggle.setValue(this.plugin.data.settings.manyClozes).onChange(async (value) => {
this.plugin.data.settings.manyClozes = value;
await this.plugin.savePluginData();
}),
);

new Setting(containerEl).setName(t("CONVERT_HIGHLIGHTS_TO_CLOZES")).addToggle((toggle) =>
toggle
.setValue(this.plugin.data.settings.convertHighlightsToClozes)
Expand Down