-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPattern.ts
More file actions
52 lines (47 loc) · 1.21 KB
/
Copy pathPattern.ts
File metadata and controls
52 lines (47 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { CardIDTag } from 'cardHead';
import { Component } from 'obsidian';
import { Operation, PatternSchedule } from 'schedule';
import { TagParser } from 'tag';
import { Card } from './card';
export type PatternProps ={
view:Component
showAns:boolean
}
// 卡片的展示模式
export abstract class Pattern {
TagID: string;
private pcard: Card;
get schedule(): PatternSchedule {
return this.card.getSchedule(this.TagID)
}
get card(): Card {
return this.pcard
}
constructor(card:Card, id:string) {
this.pcard = card
this.TagID = id
}
Pronounce() {}
abstract SubmitOpt(opt: Operation): Promise<void>;
abstract Component(props:PatternProps): JSX.Element;
abstract insertPatternID(): void;
async InitAosrID() {
this.insertPatternID()
await this.card.commitFile({ID:true})
}
}
export const cardParserRegFlags = "gm";
export function escapeRegExp(text: string): string {
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
export function prettyText (text:string):string {
let tags = TagParser.parse(text)
for (let tag of tags.Tags) {
if (tag.Head != CardIDTag) {
continue
}
text = text.replace(tag.Original, ()=>{return ""})
}
text = text.replace("#multicloze", ()=>{return ""})
return text
}