Skip to content

Commit

Permalink
multi-cloze support
Browse files Browse the repository at this point in the history
  • Loading branch information
linanwx committed Nov 30, 2022
1 parent 1dd9122 commit d2d6fbe
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 23 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ A ==cloze==.
```
Fruits include ==watermelons==, ==apples== and ==pears==.
Note that each cloze will be treated as a separate Pattern. Otherwise, you should write like this.
Fruits include ==watermelons, apples and pears==.
Fruits include ==watermelons, apples, and pears==.
Otherwise, you should add a #multicloze tag to the card.
```

##### Multicloze mode !Experimental

If a `#multicloze` tag has been found in the card, Aosr treats all cloze in the card as a group of cloze.

```
You should remember ==this== and ==that== at the same time. #multicloze
```

# Example
Expand Down Expand Up @@ -131,7 +140,7 @@ It consists of four parts. New, learn, review, and wait.

<img width="266" alt="屏幕快照 2022-11-15 的 12 45 09 下午" src="https://user-images.githubusercontent.com/16589958/201828532-4658642d-8f22-4845-b603-e07da46d3df5.png">

New means something new and hasn't been reviewed.
New means something new that hasn't been reviewed.

Review means something needs to review.

Expand All @@ -155,12 +164,12 @@ The comments will be automatically generated at the end of the document. Its loc

# What's the difference?

What's the difference with Aosr and obsidian-spaced-repetition?
What's the difference between Aosr and obsidian-spaced-repetition?

- The review time is calculated in minutes, not days. This helps to review the time calculation more accurately. And the calculation when reviewing across the zero point of the day will also be more accurate. For example, at 23:59 and 00:01 in the evening, the review time will not be rudely counted as the day before and the day after.
- The review interface will now open a standard page instead of a pop-up window. Under the standard page, you can do many obsidian activities at the same time, for example, you can review and comment on the document at the same time. In pop-up mode, this mode hinders further operation.
- The review process has been optimized. Now a learning process has been added to learn the last item that was marked as forgotten.
- Redesigned the format. The new format contributes to some minor changes. For example, cloze will no longer be disrupted by the addition of a new cloze. In addition, the new review format should also be easier to develop and expand.
- Redesigned the format. The new format contributes to some minor changes. For example, the cloze will no longer be disrupted by the addition of a new cloze. In addition, the new review format should also be easier to develop and expand.

However, some core functions, such as viewing review data statistics, are not available yet. I will improve the function according to my free time.

Expand All @@ -170,6 +179,6 @@ However, some core functions, such as viewing review data statistics, are not av

```
react (MIT) https://github.com/facebook/react
yaml (ISC) https://github.com/eemeli/yaml
YAML (ISC) https://github.com/eemeli/yaml
MUI (MIT) https://github.com/mui/material-ui
```
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "aosr",
"name": "Aosr",
"version": "1.0.9",
"version": "1.0.10",
"minAppVersion": "0.12.0",
"description": "Another obsidian spaced repetition",
"author": "linanwx",
Expand Down
90 changes: 73 additions & 17 deletions patternCloze.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@ import React from "react";
import { Operation } from "schedule";
import { TagParser } from "tag";

const hasClozeReg = /==(\S[\s\S]*?)==/m
const clozeReg = /==(\S[\s\S]*?)==/gm

class multiclozePattern extends Pattern {
insertPatternID() {
if (this.originalID) {
return
}
this.card.updateFile({
updateFunc: (filetext): string => {
let newtext = this.text.replace("#multicloze", `#multicloze ${this.TagID} `)
return filetext.replace(this.text, newtext)
}
})
}
async SubmitOpt(opt: Operation): Promise<void> {
this.card.getSchedule(this.TagID).apply(opt)
this.insertPatternID()
await this.card.commitFile()
}
Component = (props: PatternProps): JSX.Element => {
return <ClozePatternComponent text={this.text} patternProps={props} clozeOriginal={""} clozeInner={""} path={this.card.note.path} replaceAll={true}></ClozePatternComponent>
}
text: string
originalID: string
constructor(card: Card, text: string, originalID: string, tagid: string) {
super(card, tagid)
this.text = text
this.originalID = originalID
}
}

class clozePattern extends Pattern {
text: string // 整段文本
clozeOriginal: string // 带==和标签的完形文本
Expand All @@ -24,14 +56,14 @@ class clozePattern extends Pattern {
return
}
this.card.updateFile({
updateFunc: (filetext):string=>{
updateFunc: (filetext): string => {
let newCloze = `${this.clozeOriginal} ${this.TagID} `
return filetext.replace(this.clozeOriginal, newCloze)
}
})
}
Component = (props: PatternProps): JSX.Element => {
return <ClozePatternComponent text={this.text} patternProps={props} clozeOriginal={this.clozeOriginal} clozeInner={this.clozeInner} path={this.card.note.path}></ClozePatternComponent>
return <ClozePatternComponent text={this.text} patternProps={props} clozeOriginal={this.clozeOriginal} clozeInner={this.clozeInner} path={this.card.note.path} replaceAll={false}></ClozePatternComponent>
}
constructor(card: Card, text: string, clozeOriginal: string, clozeInner: string, originalID: string, tagid: string) {
super(card, tagid)
Expand All @@ -43,10 +75,11 @@ class clozePattern extends Pattern {
}

type clozePatternComponentProps = {
text:string
clozeOriginal:string
clozeInner:string
path:string
text: string
clozeOriginal: string
clozeInner: string
replaceAll: boolean
path: string
patternProps: PatternProps
}

Expand All @@ -64,8 +97,15 @@ class ClozePatternComponent extends React.Component<clozePatternComponentProps,
this.loadFlag = true
this.state.markdownDivMask.empty()
this.state.markdownDivUnmask.empty()
let masktext = this.props.text.replace(this.props.clozeOriginal, `<span style="border-bottom: 2px solid #dbdbdb;"><mark class="fuzzy">${this.props.clozeInner}</mark></span>`)
let unmasktext = this.props.text.replace(this.props.clozeOriginal, `<span style="border-bottom: 2px solid #dbdbdb;">${this.props.clozeInner}</span>`)
let masktext: string
let unmasktext: string
if (this.props.replaceAll) {
masktext = this.props.text.replace(clozeReg, `<span style="border-bottom: 2px solid #dbdbdb;"><mark class="fuzzy">$1</mark></span>`)
unmasktext = this.props.text.replace(clozeReg, `<span style="border-bottom: 2px solid #dbdbdb;">$1</span>`)
} else {
masktext = this.props.text.replace(this.props.clozeOriginal, `<span style="border-bottom: 2px solid #dbdbdb;"><mark class="fuzzy">${this.props.clozeInner}</mark></span>`)
unmasktext = this.props.text.replace(this.props.clozeOriginal, `<span style="border-bottom: 2px solid #dbdbdb;">${this.props.clozeInner}</span>`)
}
masktext = prettyText(masktext)
unmasktext = prettyText(unmasktext)
await renderMarkdown(masktext, this.state.markdownDivMask, this.props.path, this.props.patternProps.view)
Expand Down Expand Up @@ -103,16 +143,32 @@ export class ClozeParser implements PatternParser {
let reg = /==(\S[\s\S]*?)==((?: #[\w\/]+\b)*)/gm
let results: Pattern[] = []
for (let body of card.bodyList) {
for (let i = 0; i < 10000; i++) {
let regArr = reg.exec(body)
if (regArr == null) {
break
let bodytag = TagParser.parse(body)
let multicloze = bodytag.findTag("multicloze")
if (multicloze) {
let has = hasClozeReg.test(body)
if (has) {
let newID = `#${CardIDTag}/${card.ID}/mc/${cyrb53(body, 4)}`
let originalID = bodytag.findTag(CardIDTag, card.ID, "mc")?.Original || ""
let result = new multiclozePattern(card, body, originalID, originalID || newID)
results.push(result)
} else {
console.log(`missing multicloze tag. ${body} ${bodytag}`)
console.log(bodytag)

}
} else {
for (let i = 0; i < 10000; i++) {
let regArr = reg.exec(body)
if (regArr == null) {
break
}
let newID = `#${CardIDTag}/${card.ID}/c/${cyrb53(regArr[0], 4)}`
let tagInfo = TagParser.parse(regArr[2] || "")
let originalID = tagInfo.findTag(CardIDTag, card.ID, "c")?.Original || ""
let result = new clozePattern(card, body, regArr[0], regArr[1], originalID, originalID || newID)
results.push(result)
}
let newID = `#${CardIDTag}/${card.ID}/c/${cyrb53(regArr[0], 4)}`
let tagInfo = TagParser.parse(regArr[2] || "")
let originalID = tagInfo.findTag(CardIDTag, card.ID, "c")?.Original || ""
let result = new clozePattern(card, body, regArr[0], regArr[1], originalID, originalID || newID)
results.push(result)
}
}
return results
Expand Down

0 comments on commit d2d6fbe

Please sign in to comment.