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

Added new option allowing for multiline cards with empty lines #1012

Merged
merged 29 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e2f6750
Updated to upstream. Included all changes.
alberti42 Aug 15, 2024
41f90c1
Forgot to include peggy in the dependencies
alberti42 Aug 15, 2024
0e35b5b
Automatically generate parser
alberti42 Aug 15, 2024
f33cfeb
Trying to improve the structure.
alberti42 Aug 16, 2024
7e5529b
Trying to improve the structure.
alberti42 Aug 16, 2024
b9098ee
Trying to understand the structure of tests
alberti42 Aug 16, 2024
1940e7b
Updated rules
alberti42 Aug 16, 2024
7b77d23
Fixing testing units
alberti42 Aug 16, 2024
84523bc
Testing a different approach
alberti42 Aug 16, 2024
f9e3303
Finished with the dynamic parser
alberti42 Aug 16, 2024
460d71b
All tests now pass
alberti42 Aug 16, 2024
1465e9d
Remove json
alberti42 Aug 16, 2024
6297fe5
Parser error case test
4Source Aug 16, 2024
8a63ed2
Add PaserDebugSetting + test case for messages
4Source Aug 16, 2024
6976005
- Minor changes to the language translations
alberti42 Aug 17, 2024
2be3444
- Added a few test cases for testing `multilineCardEndMarker`
alberti42 Aug 17, 2024
ca0f980
- Added more comments to the code
alberti42 Aug 17, 2024
9514c97
- Added tests for multiline clozes with `multilineCardEndMarker`
alberti42 Aug 17, 2024
b2d6d18
Minor cleanup of the parser grammar
alberti42 Aug 17, 2024
d3c0c2e
Squashed commit of the following:
ronzulu Aug 20, 2024
3ed07ee
Added some comments, minor stylistic changes to the parser grammar, u…
ronzulu Aug 20, 2024
7030325
Tiny change.
alberti42 Aug 20, 2024
1320993
Added some comments, minor stylistic changes to the parser grammar, u…
ronzulu Aug 22, 2024
a73601c
Trying to fix but not there yet
alberti42 Aug 24, 2024
d71d3ba
Seems to work again
alberti42 Aug 24, 2024
f700346
One more fix and added one more test case. All tests pass.
alberti42 Aug 24, 2024
04c2ca5
Partial update of the user documentation
ronzulu Aug 25, 2024
3b95700
Merge remote-tracking branch 'alberti42/master' into rz-alberti42-v2
ronzulu Aug 25, 2024
38d15df
Completed changes to user documentation
ronzulu Aug 25, 2024
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
60 changes: 60 additions & 0 deletions docs/docs/en/flashcards/cards-with-blank-lines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Including Blank Lines in Flashcards

By default, [Multi-line Basic](qanda-cards.md#multi-line-basic), [Multi-line Bidirectional](qanda-cards.md#multi-line-bidirectional)
and [Cloze](basic-cloze-cards.md) type flashcards recognize a blank line as the end of the flashcard text.
This means that blank lines can not be included within the text.

If blank lines need to be included (e.g. on a card containing a markdown table), the
`Characters denoting the end of clozes and multiline flashcards` [setting](../user-options.md#flashcard-separators)
needs to be changed.

For example, it could be changed to `+++`.

!!! warning "Global Edit Required"
Note that after changing this you have to manually edit any flashcards you already have.

## Including a Table in the Flashcard Answer

!!! note "Obsidian requires a blank line before a table for it to be displayed correctly."
Without it, Obsidian displays it just as text and not correctly formatted.

![table-with-no-preceding-blank-line](https://github.com/user-attachments/assets/daed1309-3b38-4d14-bb42-b302efda96df)

And with a blank line after the `?` and before the table, it is displays correctly.
![table-with-preceding-blank-line](https://github.com/user-attachments/assets/beef90b7-324e-4876-b10b-055a4d23d41f)

However, by default a blank line signifies the end of the multiline card.

To include the blank line, the
`Characters denoting the end of clozes and multiline flashcards` [setting](../user-options.md#flashcard-separators)
needs to be changed. Then that character sequence added as a line after the end of the flashcard text. For example:

![table-with-preceding-blank-line+++](https://github.com/user-attachments/assets/954fd7fc-6d5f-4315-b40e-2192664c3962)

Now the card is displayed correctly during a review.

![table-with-preceding-blank-line-review](https://github.com/user-attachments/assets/3bff8d25-f91f-4bc0-b922-7471d6b60869)

## Including Blank Lines in a Cloze Flashcard

With `Convert ==highlights== to clozes` enabled in [settings](../user-options.md#flashcard-separators)
and the `Characters denoting the end of clozes and multiline flashcards` set to `+++`,
we can have blank lines in a cloze flashcard. E.g.

![cloze-with-blank-lines](https://github.com/user-attachments/assets/f9d6f123-3378-41cb-9c93-2b061856c81d)

As there are 3 clozes defined, three separate cards will be generated for review.
One card, for example is:

![cloze-with-blank-lines-front1](https://github.com/user-attachments/assets/6b939d46-b93a-4a67-96d4-6985ccafb76e)

And after `Show Answer` is clicked, the following is displayed:

![cloze-with-blank-lines-answer](https://github.com/user-attachments/assets/225abd90-20a4-4e29-abb3-36beb61388d7)

## Limitation

### Blank Lines in Answer Side Only

Blank lines are only supported in the answer side of a multiline flashcard, and not in the question side.

7 changes: 7 additions & 0 deletions docs/docs/en/flashcards/flashcards-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ If there are multiple cards defined by a single flashcard, those cards are known
A special scheduling option is available for the review of sibling cards. If the [Bury sibling cards until the next day]( ../user-options.md#flashcard-review) setting is turned on,
only one sibling card is available for review on a single day.

### Including Blank Lines within Multiline and Cloze Flashcards

By default, the end of a multiline flashcard is denoted by a blank line at the end of the flashcard text.
This means that blank lines can not be included within the text.

See [Cards with Blank Lines](cards-with-blank-lines.md) if blank lines need to be included.

---


Expand Down
8 changes: 4 additions & 4 deletions docs/docs/en/flashcards/qanda-cards.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ the answer
</div>


These can also span over multiple lines as long as both sides "touch" the `?`:
These can also span over multiple lines as long as both sides "touch" the `?`.

See [Cards with Blank Lines](cards-with-blank-lines.md) if blank lines need to be included.



Expand All @@ -128,6 +130,7 @@ info 2B
```

These can also span over multiple lines as long as both sides "touch" the `??`:
To include blank lines, see the section below.

!!! note "Card 1"
<div class="grid" markdown>
Expand Down Expand Up @@ -162,6 +165,3 @@ These can also span over multiple lines as long as both sides "touch" the `??`:

These two cards are considered sibling cards. See [sibling cards](flashcards-overview.md#sibling-cards) regarding the
[Bury sibling cards until the next day]( ../user-options.md#flashcard-review) scheduling option.



2 changes: 1 addition & 1 deletion docs/docs/en/user-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

### Flashcard Separators

![flashcard-settings-separators](https://github.com/user-attachments/assets/bc5706de-80d7-445d-9e9c-5c9fe6d9522a)
![flashcard-settings-separators](https://github.com/user-attachments/assets/744aea85-fdb3-4508-b532-7a551253f97d)

### Storage of Scheduling Data

Expand Down
Binary file added docs/media/en/cloze-with-blank-lines-answer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/media/en/cloze-with-blank-lines-front1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/media/en/cloze-with-blank-lines.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/media/en/flashcard-settings-separators.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/media/en/image-annotation.docx
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/media/en/table-with-preceding-blank-line.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/user-doco-vault/en/User Guide/Cloze with blank lines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#flashcards

Lorem ipsum dolor sit amet, consectetur adipiscing elit. ==Nam efficitur et nulla vel porttitor. Nam a neque in massa egestas rutrum.== Maecenas in nulla ipsum. Donec a lobortis justo. Donec tincidunt lorem dui. Praesent nulla nisi, facilisis vitae tincidunt nec, mollis id eros.

Duis eget volutpat magna. Nam sit amet est ac diam venenatis sollicitudin. Aliquam finibus ante quis bibendum dignissim. ==Maecenas quis semper risus==. Nam condimentum a tellus et vestibulum. Nullam porta arcu in orci efficitur, sed suscipit urna imperdiet.

Phasellus sodales dictum erat sit amet posuere. ==Vestibulum volutpat, turpis at bibendum mollis, turpis leo elementum lacus, ac finibus mi orci ac enim.== Quisque porta eleifend diam, sit amet sagittis odio pulvinar sed. Aenean tristique enim eu dui pulvinar, eget ornare ante scelerisque.

+++
13 changes: 13 additions & 0 deletions docs/user-doco-vault/en/User Guide/Cloze with table using+++.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#flashcards


| Name | Description |
| ------------------------ | ------------------------------------------------------------------------------------ |
| ==[[Amazon Inspector]]== | ==Automated and continual vulnerability management at scale (within EC2 instances)== |
| [[AWS GuardDuty]] | Protect your AWS accounts with intelligent threat detection |
| [[AWS Security Hub]] | ==Automate AWS security checks and centralize security alerts== |
| [[AWS Shield]] | Maximize application availability and responsiveness with managed DDoS protection |
<!--SR:!2024-08-28,4,270!2000-01-01,1,250!2024-08-25,1,232-->
+++

1 change: 1 addition & 0 deletions docs/user-doco-vault/en/User Guide/Context.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Africa

Kenya::Nairobi
<!--SR:!2024-08-25,1,230-->

### North America

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#flashcards

# Table with no preceding blank line

List 4 AWS security related services
?
| Name | Description |
| -------------------- | --------------------------------------------------------------------------------- |
| [[Amazon Inspector]] | Automated and continual vulnerability management at scale (within EC2 instances) |
| [[AWS GuardDuty]] | Protect your AWS accounts with intelligent threat detection |
| [[AWS Security Hub]] | Automate AWS security checks and centralize security alerts |
| [[AWS Shield]] | Maximize application availability and responsiveness with managed DDoS protection |

# Table with preceding blank line

List 4 AWS security related services
?

| Name | Description |
| -------------------- | --------------------------------------------------------------------------------- |
| [[Amazon Inspector]] | Automated and continual vulnerability management at scale (within EC2 instances) |
| [[AWS GuardDuty]] | Protect your AWS accounts with intelligent threat detection |
| [[AWS Security Hub]] | Automate AWS security checks and centralize security alerts |
| [[AWS Shield]] | Maximize application availability and responsiveness with managed DDoS protection |




Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#flashcards

List 4 AWS security related services
?

| Name | Description |
| -------------------- | --------------------------------------------------------------------------------- |
| [[Amazon Inspector]] | Automated and continual vulnerability management at scale (within EC2 instances) |
| [[AWS GuardDuty]] | Protect your AWS accounts with intelligent threat detection |
| [[AWS Security Hub]] | Automate AWS security checks and centralize security alerts |
| [[AWS Shield]] | Maximize application availability and responsiveness with managed DDoS protection |
<!--SR:!2024-08-26,1,230-->
+++

1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ nav:
- Flashcards Overview: flashcards/flashcards-overview.md
- Question & Answer Cards: flashcards/qanda-cards.md
- Cloze Cards: flashcards/basic-cloze-cards.md
- Cards with Blank Lines: flashcards/cards-with-blank-lines.md
- Organizing into Decks: flashcards/decks.md
- Reviewing & Cramming: flashcards/reviewing.md
- Statistics: flashcards/statistics.md
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
},
"dependencies": {
"chart.js": "^4.4.2",
"pagerank.js": "^1.0.2"
"pagerank.js": "^1.0.2",
"peggy": "^4.0.3"
},
"packageManager": "^pnpm@8.15.4"
}
33 changes: 30 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions src/NoteQuestionParser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TagCache } from "obsidian";
import { Card } from "./Card";
import { CardScheduleInfo, NoteCardScheduleParser } from "./CardSchedule";
import { parseEx, ParsedQuestionInfo } from "./parser";
import { parseEx, ParsedQuestionInfo, ParserOptions } from "./parser";
import { Question, QuestionText } from "./Question";
import { CardFrontBack, CardFrontBackUtil } from "./QuestionType";
import { SRSettings, SettingsUtil } from "./settings";
Expand Down Expand Up @@ -136,17 +136,18 @@ export class NoteQuestionParser {

private parseQuestions(): ParsedQuestionInfo[] {
// We pass contentText which has the frontmatter blanked out; see extractFrontmatter for reasoning
const settings: SRSettings = this.settings;
const result: ParsedQuestionInfo[] = parseEx(
this.contentText,
settings.singleLineCardSeparator,
settings.singleLineReversedCardSeparator,
settings.multilineCardSeparator,
settings.multilineReversedCardSeparator,
settings.convertHighlightsToClozes,
settings.convertBoldTextToClozes,
settings.convertCurlyBracketsToClozes,
);
const parserOptions: ParserOptions = {
singleLineCardSeparator:this.settings.singleLineCardSeparator,
singleLineReversedCardSeparator: this.settings.singleLineReversedCardSeparator,
multilineCardSeparator: this.settings.multilineCardSeparator,
multilineReversedCardSeparator: this.settings.multilineReversedCardSeparator,
multilineCardEndMarker: this.settings.multilineCardEndMarker,
convertHighlightsToClozes: this.settings.convertHighlightsToClozes,
convertBoldTextToClozes: this.settings.convertBoldTextToClozes,
convertCurlyBracketsToClozes: this.settings.convertCurlyBracketsToClozes,
};

const result: ParsedQuestionInfo[] = parseEx(this.contentText, parserOptions);
return result;
}

Expand Down
Loading
Loading