From 7b5fd815fc76cbaa88e55ce1cdb8b5c03e928d82 Mon Sep 17 00:00:00 2001 From: Alan Morgan Date: Fri, 23 Oct 2020 19:56:49 -0600 Subject: [PATCH 1/5] [GH-71] Documented cloze & restructured README. I went through most of the readme file and editted/rewrote it. The only section I didn't really touch was the predict and outcome file sections. I tried to go in depth into cloze syntax, reversible cards, and multiple sides, while also providing a variety of flashcard examples. I might make another commit for this case, depending on how my final review on github looks like. --- README.md | 309 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 246 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index b4aa405..ff8285f 100644 --- a/README.md +++ b/README.md @@ -6,97 +6,261 @@ [![Coverage Status](https://coveralls.io/repos/github/alanxoc3/concards/badge.svg?branch=master)](https://coveralls.io/github/alanxoc3/concards?branch=master) Turning notes into flashcards, or should I say concards! Concards is my ongoing -attempt to make flashcards simple and easily embeddable into text document -based notes. Concards is much lighter than other flashcard applications such as -such as [Anki](https://apps.ankiweb.net/) or -[Memrise](https://www.memrise.com/), but it is also very powerful striving to -do one thing and do it well. +attempt to make flashcards more simple and convenient. Concards provides much +of the functionality of other mainstream flashcard applications, but with a +unique focus on parsing cards embedded in text based files. ## Features -- Implements a repetition algorithm similar to [SM2](https://www.supermemo.com/english/ol/sm2.htm). -- Reading from multiple files & directories. -- Conveniently edit cards while reviewing them! -- Helpful syntax for adding reversible cards. -- Built with Unicode in mind! -- Undoing/Redoing support. +- Configure with your favorite editor! +- Spaced repetition similar to [SM2](https://www.supermemo.com/english/ol/sm2.htm)! +- Read from directories or files! +- Reversible cards! +- [Cloze](https://en.wikipedia.org/wiki/Cloze_test) cards! +- Undo & Redo support. +- [UTF-8](https://en.wikipedia.org/wiki/UTF-8) is a first-class citizen. ## Install -Download the latest binary executable from the [release +Download the latest release from the [release page](https://github.com/alanxoc3/concards/releases). At the moment, only Linux and Mac are supported. -### Building From Source -It should be super simple: -``` bash -go install github.com/alanxoc3/concards +You can also build a snapshot from source with the `go` command. +```sh +$ go install github.com/alanxoc3/concards ``` -### Dependencies -This project currently depends on: -- [stretchr/testify](https://github.com/stretchr/testify) for unit tests. -- [alanxoc3/argparse](https://github.com/alanxoc3/argparse) forked from - [akamensky/argparse](https://github.com/akamensky/argparse) for CLI options. -- [nsf/termbox-go](https://github.com/nsf/termbox-go) for the terminal gui. -- [mattn/go-runewidth](https://github.com/mattn/go-runewidth) to help with - Asian characters. +Once installed, you may try running concards on this readme! +```sh +$ concards README.md +``` + +You may also review the help command's output. +```sh +$ concards --help +``` + +## Running Concards -Concards wouldn't be where it is today without those open source projects & -their contributors, so please check them out too! +## Basic Syntax +You can learn the full flashcard embedding syntax in just a few minutes! Let's +get started. -## Usage -The complete syntax of embedding your flashcards into text documents consists -of these symbols: +### Creating a flashcard +To make a flashcard, you must put the flashcard text within a concards block. +The concards block starts with a pound sign followed by a colon, and ends with +a colon followed by a pound sign. Ex: ``` -'#:' = Starts a concards block and also starts a question. -'|' = Separates sides. -':' = Separates sides, and adds a reversed card. -':#' = Ends the concards block. -'\' = Escapes the special tokens above. +#: This is a one sided flashcard. +:# ``` -Here are a few example concards: +If you run concards on a file that has the text above, you'll see a one sided +flashcard! Flashcards are normally 2 sided, so let's create a new flashcard +that separates a question and answer with the pipe symbol: +``` +#: What is a great way to decrease the effects of the forgetting curve? + | Spending time every day to review previously learned information. +:# ``` -#: Concards - : A lightweight embeddable note-taking flashcard program. -#: What does "concards" stand for? - | Console Cards +Concards actually supports flashcards with any number of sides. Creating a 3 +sided flashcard is a piece of cake: +``` +#: What are Newton's 3 laws of motion? + | 1. An object at rest stays at rest unless acted upon. + | 2. Force is equal to mass times acceleration. + | 3. For every action, there is an equal and opposite reaction. +:# +``` -#: What does the ":" do in concards? - | It will add an extra card where the "colon" side is the question and the - question is the answer. - | This syntax is especially useful for vocabulary when learning a language and - can save typing. +For embedding multiple flashcards, you can either create new concards blocks +for each one, or you can reuse the same block. This example will create 2 +flashcards: +``` +#: Who published the first flashcards? + | Favell Lee Mortimer -#: Can a concard have more than 2 sides? - | Yes +#: When were the first flashcards published? + | 1834 +:# +``` -#: What does a concard look like? - | \#: It could look like this \| What does a concard look like? \:\# - | \#: It could also look like this \| with multiple \| answers! \:\# +### Reversible Cards +When learning a language, you might find yourself writing a flashcard that +transitions a phrase from English to Esperanto and writing another flashcard +that transitions the same phrase from Esperanto to English: +``` +#: saluton al la mundo | hello world +#: hello world | saluton al la mundo +:# +``` -#: How do you escape a concard keyword? - | Put a backslash before it. Your text file would show "\#:", but the app shows "#:". +Concards can do the same thing with less typing if you use the double colon +operator: +``` +#: saluton al la mundo :: hello world +:# +``` -#: How do you show a backslash then a keyword in the concards ui? - | To see \\#: in the ui, your text document must have 2 backslashes: \\\#: +If you are learning two languages, you can expand this with an extra double +colon: +``` +#: spagetoj :: spaghetti :: 意面 :# -#: 你好世界 - : Hello World - : Greetings World +Generates these cards: +#: spagetoj | spaghetti | 意面 +#: spaghetti | spagetoj | 意面 +#: 意面 | spagetoj | spaghetti +:# +``` -#: The human who created concards. - : Alan Morgan +Translating a word from one language to another often results in multiple +definitions. Concards as able to concisely represents these scenarios when you +combine the pipe and double colon operators. +``` +#: apricot | almond :: 杏仁 + +Generates these cards: +#: apricot | 杏仁 +#: almond | 杏仁 +#: 杏仁 | apricot | almond :# ``` -The easiest way to understand that syntax is by trying it out! Just run -concards on this `README.md` file and see what happens! -``` bash -$ concards README.md +Note that the double colon operator always takes precedence before the pipe +operator. + +### Cloze Cards +Cloze cards are handy when working with phrases or related facts. In concards, +a cloze is created by putting text within a curly brace. Concards will generate +cards from this cloze by replacing it with an empty set of curly braces. + +``` +#: {Hermann Ebbinghaus} published his findings on the forgetting curve in {1885}. +:# + +Generates these cards: +#: {} published his findings on the forgetting curve in 1885. | Hermann Ebbinghaus +#: Hermann Ebbinghaus published his findings on the forgetting curve in {}. | 1885 +:# ``` -## Advanced Usage +Nesting clozes is supported: +``` +#: {Education is the {kindling of a flame}}, {not the {filling of a vessel}}. +:# + +Generates these cards: +#: {}, not the filling of a vessel. | Education is the kindling of a flame +#: Education is the {}, not the filling of a vessel. | kindling of a flame +#: Education is the kindling of a flame, {}. | not the filling of a vessel +#: Education is the kindling of a flame, not the {}. | filling of a vessel +:# +``` + +You can replace consecutive curly braces with the colon operator. This +especially makes separation within a single word look nicer. +``` +#: {Pneumono:ultra:microscopic:silico:volcano:coniosis} :# + +Is the same as: + +#: {Pneumono}{ultra}{microscopic}{silico}{volcano}{coniosis} :# + +And generates these cards: +#: {}ultramicroscopicsilicovolcanoconiosis | Pneumono +#: Pneumono{}microscopicsilicovolcanoconiosis | ultra +#: Pneumonoultra{}silicovolcanoconiosis | microscopic +#: Pneumonoultramicroscopic{}volcanoconiosis | silico +#: Pneumonoultramicroscopicsilico{}coniosis | volcano +#: Pneumonoultramicroscopicsilicovolcano{} | coniosis +:# +``` + +To group multiple clozes together, use the hash symbol before a set of curly +braces. +``` +#: #{Sebastian Leitner} published about the Leitner System in #{1972}. :# + +Generates this card: +#: {} published about the Leitner System in {}. | Sebastian Leitner | 1972 :# +``` + +Cloze groups are different based on the number of hash symbols before the curly +brace. Here is an example with 3 cloze groups: +``` +#: ###{Spaced repetition} is an #{evidence-based} learning technique which + ##{incorporates} increasing time intervals between each ##{review} of a + flashcard in order to exploit the ###{psychological} #{spacing effect}. +:# + +Generates these cards: +#: Spaced repetition is an {} learning technique which incorporates increasing + time intervals between each review of a flashcard in order to exploit the + psychological {}. + | evidence-based + | spacing effect + +#: Spaced repetition is an evidence-based learning technique which {} + increasing time intervals between each {} of a flashcard in order to exploit + the psychological spacing effect. + | incorporates + | review + +#: {} is an evidence-based learning technique which incorporates increasing + time intervals between each review of a flashcard in order to exploit the {} + spacing effect. + | Spaced repetition + | psychological +:# +``` + +Finally, you can combine the cloze syntax with `::` and `|`: +``` +#: {新型:冠状:病毒} :: Coronavirus | COVID-19 :# + +Generates these cards: +#: {}冠状病毒 | 新型 +#: 新型{}病毒 | 冠状 +#: 新型冠状{} | 病毒 +#: 新型冠状病毒 | Coronavirus | COVID-19 +#: Coronavirus | 新型冠状病毒 +#: COVID-19 | 新型冠状病毒 +:# +``` + +### Whitespace & Escaping +Concards ignores consecutive whitespace. The following flashcards are +equivalent: +``` +#: {Piotr A. Woźniak} created the SM-2 spaced repetition algorithm in {1987}. +#: { Piotr A. Woźniak } created the SM-2 spaced repetition algorithm in { 1987}. +#:{Piotr A. Woźniak }created the SM-2 spaced repetition algorithm in{ 1987}. +:# + +Would generate these cards: +#: {} created the SM-2 spaced repetition algorithm in 1987. | Piotr A. Woźniak +#: Piotr A. Woźniak created the SM-2 spaced repetition algorithm in {}. | 1987 +:# +``` + +Backslash any reserved character or whitespace to include it in the card text: +``` +#: Which characters are special in concards? + | \# \: \| \{ \} + +#: Leave my door open just a crack\ + Cause I feel like such an insomniac\ + Why do I tire of counting sheep?\ + When I'm far too tired to fall asleep + | Fireflies, by Owl City +:# +``` + +## File Structure +Concards has a very simple file structure. This section explains the content of +the meta data files concards writes to after a review session. + ### The Predict File The predict file contains information needed to make a prediction when you should review a card next. @@ -138,3 +302,22 @@ You can notice that there are two main differences from the predict file: This file is read from `$CONCARDS_OUTCOME`, or `$HOME/.config/concards/outcome` if that environment variable doesn't exist. + +## Dependencies +Concards currently depends on these libraries: +- [stretchr/testify](https://github.com/stretchr/testify) for unit tests. +- [alanxoc3/argparse](https://github.com/alanxoc3/argparse) forked from + [akamensky/argparse](https://github.com/akamensky/argparse) for CLI options. +- [nsf/termbox-go](https://github.com/nsf/termbox-go) for the terminal gui. +- [mattn/go-runewidth](https://github.com/mattn/go-runewidth) to help with + Asian characters. + +Concards wouldn't be where it is today without those repositories & their +contributors, so please check them out too! + +## Future Work +The next big things to focus on: +- Improved CLI UI. +- Local Web Server UI. +- Support Unix Piping. +- Customizable Algorithm Plugin System. From 8e093543d4cb0debe12ad0d9462f802b1f157e2d Mon Sep 17 00:00:00 2001 From: Alan Morgan Date: Fri, 23 Oct 2020 20:11:20 -0600 Subject: [PATCH 2/5] [GH-71] Minor wording & format edit to readme. --- README.md | 112 ++++++++++++++++++++---------------------------------- 1 file changed, 42 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index ff8285f..1377f23 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # [![Build Status](https://travis-ci.org/alanxoc3/concards.svg?branch=master)](https://travis-ci.org/alanxoc3/concards) @@ -16,8 +15,8 @@ unique focus on parsing cards embedded in text based files. - Read from directories or files! - Reversible cards! - [Cloze](https://en.wikipedia.org/wiki/Cloze_test) cards! -- Undo & Redo support. -- [UTF-8](https://en.wikipedia.org/wiki/UTF-8) is a first-class citizen. +- Undo & Redo support! +- [UTF-8](https://en.wikipedia.org/wiki/UTF-8) is a first-class citizen! ## Install Download the latest release from the [release @@ -25,81 +24,67 @@ page](https://github.com/alanxoc3/concards/releases). At the moment, only Linux and Mac are supported. You can also build a snapshot from source with the `go` command. -```sh +```bash $ go install github.com/alanxoc3/concards ``` -Once installed, you may try running concards on this readme! -```sh +Once installed, you may want to try running concards on this readme! +```bash $ concards README.md ``` -You may also review the help command's output. -```sh +You may also want to review the help command's output. +```bash $ concards --help ``` -## Running Concards - ## Basic Syntax You can learn the full flashcard embedding syntax in just a few minutes! Let's get started. ### Creating a flashcard -To make a flashcard, you must put the flashcard text within a concards block. -The concards block starts with a pound sign followed by a colon, and ends with -a colon followed by a pound sign. Ex: +To make a flashcard, you must put the flashcard text within a concards block. A +concards block looks like this `#: :#`, where text would be placed between the +two colons. Ex: ``` -#: This is a one sided flashcard. -:# +#: This is a one sided flashcard. :# ``` -If you run concards on a file that has the text above, you'll see a one sided -flashcard! Flashcards are normally 2 sided, so let's create a new flashcard -that separates a question and answer with the pipe symbol: +The text above will produce a one sided flashcard! But flashcards are normally +2 sided, so let's create a new flashcard that separates a question and answer +with the pipe symbol: ``` #: What is a great way to decrease the effects of the forgetting curve? - | Spending time every day to review previously learned information. -:# + | Spending time every day to review previously learned information. :# ``` -Concards actually supports flashcards with any number of sides. Creating a 3 -sided flashcard is a piece of cake: +Any number of sides are supported, so creating a 3 sided flashcard is a piece +of cake: ``` #: What are Newton's 3 laws of motion? | 1. An object at rest stays at rest unless acted upon. | 2. Force is equal to mass times acceleration. - | 3. For every action, there is an equal and opposite reaction. -:# + | 3. For every action, there is an equal and opposite reaction. :# ``` -For embedding multiple flashcards, you can either create new concards blocks -for each one, or you can reuse the same block. This example will create 2 -flashcards: +You can either create new blocks for each card, or you can keep them in the +same block. This creates 2 cards: ``` -#: Who published the first flashcards? - | Favell Lee Mortimer - -#: When were the first flashcards published? - | 1834 -:# +#: Who published the first flashcards? | Favell Lee Mortimer +#: When were the first flashcards published? | 1834 :# ``` ### Reversible Cards When learning a language, you might find yourself writing a flashcard that -transitions a phrase from English to Esperanto and writing another flashcard -that transitions the same phrase from Esperanto to English: -``` -#: saluton al la mundo | hello world -#: hello world | saluton al la mundo -:# +transitions a phrase from language #1 to language #2 and writing another +flashcard that transitions the same phrase from language #2 to language #1. +Concards makes this easier with the reversible card operator `::`. ``` +#: saluton al la mundo :: hello world :# -Concards can do the same thing with less typing if you use the double colon -operator: -``` -#: saluton al la mundo :: hello world -:# +Generates these cards: +#: saluton al la mundo | hello world +#: hello world | saluton al la mundo :# ``` If you are learning two languages, you can expand this with an extra double @@ -110,8 +95,7 @@ colon: Generates these cards: #: spagetoj | spaghetti | 意面 #: spaghetti | spagetoj | 意面 -#: 意面 | spagetoj | spaghetti -:# +#: 意面 | spagetoj | spaghetti :# ``` Translating a word from one language to another often results in multiple @@ -123,8 +107,7 @@ combine the pipe and double colon operators. Generates these cards: #: apricot | 杏仁 #: almond | 杏仁 -#: 杏仁 | apricot | almond -:# +#: 杏仁 | apricot | almond :# ``` Note that the double colon operator always takes precedence before the pipe @@ -136,26 +119,22 @@ a cloze is created by putting text within a curly brace. Concards will generate cards from this cloze by replacing it with an empty set of curly braces. ``` -#: {Hermann Ebbinghaus} published his findings on the forgetting curve in {1885}. -:# +#: {Hermann Ebbinghaus} published his findings on the forgetting curve in {1885}. :# Generates these cards: #: {} published his findings on the forgetting curve in 1885. | Hermann Ebbinghaus -#: Hermann Ebbinghaus published his findings on the forgetting curve in {}. | 1885 -:# +#: Hermann Ebbinghaus published his findings on the forgetting curve in {}. | 1885 :# ``` Nesting clozes is supported: ``` -#: {Education is the {kindling of a flame}}, {not the {filling of a vessel}}. -:# +#: {Education is the {kindling of a flame}}, {not the {filling of a vessel}}. :# Generates these cards: #: {}, not the filling of a vessel. | Education is the kindling of a flame #: Education is the {}, not the filling of a vessel. | kindling of a flame #: Education is the kindling of a flame, {}. | not the filling of a vessel -#: Education is the kindling of a flame, not the {}. | filling of a vessel -:# +#: Education is the kindling of a flame, not the {}. | filling of a vessel :# ``` You can replace consecutive curly braces with the colon operator. This @@ -173,8 +152,7 @@ And generates these cards: #: Pneumonoultra{}silicovolcanoconiosis | microscopic #: Pneumonoultramicroscopic{}volcanoconiosis | silico #: Pneumonoultramicroscopicsilico{}coniosis | volcano -#: Pneumonoultramicroscopicsilicovolcano{} | coniosis -:# +#: Pneumonoultramicroscopicsilicovolcano{} | coniosis :# ``` To group multiple clozes together, use the hash symbol before a set of curly @@ -191,8 +169,7 @@ brace. Here is an example with 3 cloze groups: ``` #: ###{Spaced repetition} is an #{evidence-based} learning technique which ##{incorporates} increasing time intervals between each ##{review} of a - flashcard in order to exploit the ###{psychological} #{spacing effect}. -:# + flashcard in order to exploit the ###{psychological} #{spacing effect}. :# Generates these cards: #: Spaced repetition is an {} learning technique which incorporates increasing @@ -211,8 +188,7 @@ Generates these cards: time intervals between each review of a flashcard in order to exploit the {} spacing effect. | Spaced repetition - | psychological -:# + | psychological :# ``` Finally, you can combine the cloze syntax with `::` and `|`: @@ -225,8 +201,7 @@ Generates these cards: #: 新型冠状{} | 病毒 #: 新型冠状病毒 | Coronavirus | COVID-19 #: Coronavirus | 新型冠状病毒 -#: COVID-19 | 新型冠状病毒 -:# +#: COVID-19 | 新型冠状病毒 :# ``` ### Whitespace & Escaping @@ -235,13 +210,11 @@ equivalent: ``` #: {Piotr A. Woźniak} created the SM-2 spaced repetition algorithm in {1987}. #: { Piotr A. Woźniak } created the SM-2 spaced repetition algorithm in { 1987}. -#:{Piotr A. Woźniak }created the SM-2 spaced repetition algorithm in{ 1987}. -:# +#:{Piotr A. Woźniak }created the SM-2 spaced repetition algorithm in{ 1987}. :# Would generate these cards: #: {} created the SM-2 spaced repetition algorithm in 1987. | Piotr A. Woźniak -#: Piotr A. Woźniak created the SM-2 spaced repetition algorithm in {}. | 1987 -:# +#: Piotr A. Woźniak created the SM-2 spaced repetition algorithm in {}. | 1987 :# ``` Backslash any reserved character or whitespace to include it in the card text: @@ -253,8 +226,7 @@ Backslash any reserved character or whitespace to include it in the card text: Cause I feel like such an insomniac\ Why do I tire of counting sheep?\ When I'm far too tired to fall asleep - | Fireflies, by Owl City -:# + | Fireflies, by Owl City :# ``` ## File Structure From f094059c1c891c3ba476dca8e33cea0a91e9373f Mon Sep 17 00:00:00 2001 From: Alan Morgan Date: Fri, 23 Oct 2020 20:21:10 -0600 Subject: [PATCH 3/5] [GH-71] Further minor editting. --- README.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1377f23..10195fe 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ same block. This creates 2 cards: When learning a language, you might find yourself writing a flashcard that transitions a phrase from language #1 to language #2 and writing another flashcard that transitions the same phrase from language #2 to language #1. -Concards makes this easier with the reversible card operator `::`. +Concards makes this easier with the `::` operator ``` #: saluton al la mundo :: hello world :# @@ -87,8 +87,7 @@ Generates these cards: #: hello world | saluton al la mundo :# ``` -If you are learning two languages, you can expand this with an extra double -colon: +If you are learning two languages, you can expand this with an extra `::`: ``` #: spagetoj :: spaghetti :: 意面 :# @@ -99,8 +98,8 @@ Generates these cards: ``` Translating a word from one language to another often results in multiple -definitions. Concards as able to concisely represents these scenarios when you -combine the pipe and double colon operators. +definitions. Concards can represent these scenarios more efficiently when +combining the `|` and `::`. ``` #: apricot | almond :: 杏仁 @@ -110,14 +109,13 @@ Generates these cards: #: 杏仁 | apricot | almond :# ``` -Note that the double colon operator always takes precedence before the pipe -operator. +The double colon operator always takes precedence before the pipe operator. ### Cloze Cards Cloze cards are handy when working with phrases or related facts. In concards, -a cloze is created by putting text within a curly brace. Concards will generate -cards from this cloze by replacing it with an empty set of curly braces. - +a cloze is created by putting text within a set of curly braces. Concards will +generate cards from the text in the curly braces and replace the text with an +empty set of curly braces. ``` #: {Hermann Ebbinghaus} published his findings on the forgetting curve in {1885}. :# @@ -126,7 +124,7 @@ Generates these cards: #: Hermann Ebbinghaus published his findings on the forgetting curve in {}. | 1885 :# ``` -Nesting clozes is supported: +Cloze nesting is supported: ``` #: {Education is the {kindling of a flame}}, {not the {filling of a vessel}}. :# From 637e440c1a78fe06fc6a70bea92d0d5160b10df1 Mon Sep 17 00:00:00 2001 From: Alan Morgan Date: Fri, 23 Oct 2020 21:54:25 -0600 Subject: [PATCH 4/5] [GH-71] Fixed cloze problems. While writing the README, I wrote some examples that were actually broken in concards. I added those cases as tests and fixed the problems. Now that cloze cards are working. That readme was kind of like writing a big test. Now that cloze is working, more time could be spent refactoring it. --- README.md | 12 ++++++------ internal/card/card.go | 25 +++++++++++++++++-------- internal/card/card_test.go | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 10195fe..87ee430 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,19 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/alanxoc3/concards)](https://goreportcard.com/report/github.com/alanxoc3/concards) [![Coverage Status](https://coveralls.io/repos/github/alanxoc3/concards/badge.svg?branch=master)](https://coveralls.io/github/alanxoc3/concards?branch=master) -Turning notes into flashcards, or should I say concards! Concards is my ongoing +Turning notes into flashcards, or should I say concards! This is my ongoing attempt to make flashcards more simple and convenient. Concards provides much of the functionality of other mainstream flashcard applications, but with a -unique focus on parsing cards embedded in text based files. +unique focus on parsing cards embedded within text files. ## Features -- Configure with your favorite editor! - Spaced repetition similar to [SM2](https://www.supermemo.com/english/ol/sm2.htm)! +- [UTF-8](https://en.wikipedia.org/wiki/UTF-8) as a first-class citizen! +- Configure with your favorite editor! +- Undo & Redo support! - Read from directories or files! - Reversible cards! - [Cloze](https://en.wikipedia.org/wiki/Cloze_test) cards! -- Undo & Redo support! -- [UTF-8](https://en.wikipedia.org/wiki/UTF-8) is a first-class citizen! ## Install Download the latest release from the [release @@ -101,7 +101,7 @@ Translating a word from one language to another often results in multiple definitions. Concards can represent these scenarios more efficiently when combining the `|` and `::`. ``` -#: apricot | almond :: 杏仁 +#: apricot | almond :: 杏仁 :# Generates these cards: #: apricot | 杏仁 diff --git a/internal/card/card.go b/internal/card/card.go index 3decc07..d6298f1 100644 --- a/internal/card/card.go +++ b/internal/card/card.go @@ -325,8 +325,9 @@ func flattenNode(n *clozeNode, loc int) []*clozeNode { nodes := []*clozeNode{} originalLoc := loc for _, curNode := range n.nodes { - nodes = append(nodes, flattenNode(curNode, loc+curNode.loc)...) - loc += len(nodes[0].text) + newNodes := flattenNode(curNode, loc+curNode.loc) + nodes = append(nodes, newNodes...) + loc += len(newNodes[0].text) } retNodes := []*clozeNode{} @@ -364,7 +365,8 @@ func trim(text string) (string, bool, bool) { return text[leading:trailing], leading > 0, trailing < len(text) } -func distributeNodeSpacesHelper(newText string, nodeIndex int, nodes []*clozeNode, i int, prevIsSpace, currIsSpace bool) (string, int) { +func distributeNodeSpacesHelper(newText string, nodeIndex int, nodes []*clozeNode, i int, prevIsSpace, currIsSpace bool) (bool, int) { + shouldAddRune := true for len(nodes) > nodeIndex && i == nodes[nodeIndex].loc { nt, l, _ := trim(nodes[nodeIndex].text) @@ -376,10 +378,14 @@ func distributeNodeSpacesHelper(newText string, nodeIndex int, nodes []*clozeNod nodes[nodeIndex].loc = len(newText) } + if l && prevIsSpace && currIsSpace { + shouldAddRune = false + } + nodeIndex++ } - return newText, nodeIndex + return shouldAddRune, nodeIndex } // Relies on a flattened node list (this is not recursive). @@ -391,14 +397,17 @@ func distributeNodeSpaces(nodeText string, nodes []*clozeNode) string { for i, r := range nodeText { currIsSpace := unicode.IsSpace(r) - newText, nodeIndex = distributeNodeSpacesHelper(newText, nodeIndex, nodes, i, prevIsSpace, currIsSpace) - newText += string(r) + shouldAddRune, ni := distributeNodeSpacesHelper(newText, nodeIndex, nodes, i, prevIsSpace, currIsSpace) + nodeIndex = ni + if shouldAddRune { + newText += string(r) + } prevIsSpace = !isBackslash && currIsSpace isBackslash = r == '\\' && !isBackslash } - newText, _ = distributeNodeSpacesHelper(newText, nodeIndex, nodes, len(nodeText), prevIsSpace, true) + distributeNodeSpacesHelper(newText, nodeIndex, nodes, len(nodeText), prevIsSpace, true) return newText } @@ -506,7 +515,7 @@ func NewCards(file string, cardStr string) ([]*Card, error) { nodes := flattenNode(node, 0) nodeText = distributeNodeSpaces(nodeText, nodes[1:]) - newCards := createCardsFromSubNodes(file, nodes[0].text, nodes[1:]) + newCards := createCardsFromSubNodes(file, nodeText, nodes[1:]) cards = append(cards, newCards...) if len(nodeText) > 0 { diff --git a/internal/card/card_test.go b/internal/card/card_test.go index 0d343d4..30ec913 100644 --- a/internal/card/card_test.go +++ b/internal/card/card_test.go @@ -292,3 +292,21 @@ func TestClozeQuadrupleColon(t *testing.T) { assert.Equal(t, "\\{h\\:e | l\\:l\\}o", c[0].String()) assert.Equal(t, "l\\:l\\}o | \\{h\\:e", c[1].String()) } + +func TestLongColonExample(t *testing.T) { + c, _ := card.NewCards(".", " {Pneumono:ultra:microscopic:silico:volcano:coniosis} ") + require.Len(t, c, 6) + assert.Equal(t, "{}ultramicroscopicsilicovolcanoconiosis | Pneumono", c[0].String()) + assert.Equal(t, "Pneumono{}microscopicsilicovolcanoconiosis | ultra", c[1].String()) + assert.Equal(t, "Pneumonoultra{}silicovolcanoconiosis | microscopic", c[2].String()) + assert.Equal(t, "Pneumonoultramicroscopic{}volcanoconiosis | silico", c[3].String()) + assert.Equal(t, "Pneumonoultramicroscopicsilico{}coniosis | volcano", c[4].String()) + assert.Equal(t, "Pneumonoultramicroscopicsilicovolcano{} | coniosis", c[5].String()) +} + +func TestWozniak(t *testing.T) { + c, _ := card.NewCards(".", "{ Piotr A. Woźniak } created the SM-2 spaced repetition algorithm in { 1987}.") + require.Len(t, c, 2) + assert.Equal(t, "{} created the SM-2 spaced repetition algorithm in 1987. | Piotr A. Woźniak", c[0].String()) + assert.Equal(t, "Piotr A. Woźniak created the SM-2 spaced repetition algorithm in {}. | 1987", c[1].String()) +} From b1f9b742b1aa257a01d45e88a3c8b3da65af487f Mon Sep 17 00:00:00 2001 From: Alan Morgan Date: Fri, 23 Oct 2020 22:00:03 -0600 Subject: [PATCH 5/5] [GH-71] Mainly spacing differences. --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 87ee430..a2a0225 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Concards makes this easier with the `::` operator #: saluton al la mundo :: hello world :# Generates these cards: + #: saluton al la mundo | hello world #: hello world | saluton al la mundo :# ``` @@ -92,6 +93,7 @@ If you are learning two languages, you can expand this with an extra `::`: #: spagetoj :: spaghetti :: 意面 :# Generates these cards: + #: spagetoj | spaghetti | 意面 #: spaghetti | spagetoj | 意面 #: 意面 | spagetoj | spaghetti :# @@ -104,6 +106,7 @@ combining the `|` and `::`. #: apricot | almond :: 杏仁 :# Generates these cards: + #: apricot | 杏仁 #: almond | 杏仁 #: 杏仁 | apricot | almond :# @@ -120,6 +123,7 @@ empty set of curly braces. #: {Hermann Ebbinghaus} published his findings on the forgetting curve in {1885}. :# Generates these cards: + #: {} published his findings on the forgetting curve in 1885. | Hermann Ebbinghaus #: Hermann Ebbinghaus published his findings on the forgetting curve in {}. | 1885 :# ``` @@ -129,6 +133,7 @@ Cloze nesting is supported: #: {Education is the {kindling of a flame}}, {not the {filling of a vessel}}. :# Generates these cards: + #: {}, not the filling of a vessel. | Education is the kindling of a flame #: Education is the {}, not the filling of a vessel. | kindling of a flame #: Education is the kindling of a flame, {}. | not the filling of a vessel @@ -145,6 +150,7 @@ Is the same as: #: {Pneumono}{ultra}{microscopic}{silico}{volcano}{coniosis} :# And generates these cards: + #: {}ultramicroscopicsilicovolcanoconiosis | Pneumono #: Pneumono{}microscopicsilicovolcanoconiosis | ultra #: Pneumonoultra{}silicovolcanoconiosis | microscopic @@ -159,6 +165,7 @@ braces. #: #{Sebastian Leitner} published about the Leitner System in #{1972}. :# Generates this card: + #: {} published about the Leitner System in {}. | Sebastian Leitner | 1972 :# ``` @@ -170,6 +177,7 @@ brace. Here is an example with 3 cloze groups: flashcard in order to exploit the ###{psychological} #{spacing effect}. :# Generates these cards: + #: Spaced repetition is an {} learning technique which incorporates increasing time intervals between each review of a flashcard in order to exploit the psychological {}. @@ -194,6 +202,7 @@ Finally, you can combine the cloze syntax with `::` and `|`: #: {新型:冠状:病毒} :: Coronavirus | COVID-19 :# Generates these cards: + #: {}冠状病毒 | 新型 #: 新型{}病毒 | 冠状 #: 新型冠状{} | 病毒 @@ -210,7 +219,8 @@ equivalent: #: { Piotr A. Woźniak } created the SM-2 spaced repetition algorithm in { 1987}. #:{Piotr A. Woźniak }created the SM-2 spaced repetition algorithm in{ 1987}. :# -Would generate these cards: +Generates these cards: + #: {} created the SM-2 spaced repetition algorithm in 1987. | Piotr A. Woźniak #: Piotr A. Woźniak created the SM-2 spaced repetition algorithm in {}. | 1987 :# ``` @@ -221,9 +231,9 @@ Backslash any reserved character or whitespace to include it in the card text: | \# \: \| \{ \} #: Leave my door open just a crack\ - Cause I feel like such an insomniac\ - Why do I tire of counting sheep?\ - When I'm far too tired to fall asleep +Cause I feel like such an insomniac\ +Why do I tire of counting sheep?\ +When I'm far too tired to fall asleep | Fireflies, by Owl City :# ```