@notatki/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/export-notes.d.ts +3 -0
- package/dist/export-notes.d.ts.map +1 -0
- package/dist/export-notes.js +28 -0
- package/dist/export-notes.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/insert-note-id.d.ts +5 -0
- package/dist/insert-note-id.d.ts.map +1 -0
- package/dist/insert-note-id.js +20 -0
- package/dist/insert-note-id.js.map +1 -0
- package/dist/model.d.ts +128 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +125 -0
- package/dist/model.js.map +1 -0
- package/dist/nodes.d.ts +14 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +7 -0
- package/dist/nodes.js.map +1 -0
- package/dist/note-parser.d.ts +34 -0
- package/dist/note-parser.d.ts.map +1 -0
- package/dist/note-parser.js +233 -0
- package/dist/note-parser.js.map +1 -0
- package/dist/note.d.ts +42 -0
- package/dist/note.d.ts.map +1 -0
- package/dist/note.js +156 -0
- package/dist/note.js.map +1 -0
- package/dist/output.d.ts +7 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +25 -0
- package/dist/output.js.map +1 -0
- package/dist/print-model-nodes.d.ts +3 -0
- package/dist/print-model-nodes.d.ts.map +1 -0
- package/dist/print-model-nodes.js +39 -0
- package/dist/print-model-nodes.js.map +1 -0
- package/dist/print-note-nodes.d.ts +3 -0
- package/dist/print-note-nodes.d.ts.map +1 -0
- package/dist/print-note-nodes.js +34 -0
- package/dist/print-note-nodes.js.map +1 -0
- package/dist/reformat-model-nodes.d.ts +3 -0
- package/dist/reformat-model-nodes.d.ts.map +1 -0
- package/dist/reformat-model-nodes.js +5 -0
- package/dist/reformat-model-nodes.js.map +1 -0
- package/dist/reformat-note-nodes.d.ts +3 -0
- package/dist/reformat-note-nodes.d.ts.map +1 -0
- package/dist/reformat-note-nodes.js +31 -0
- package/dist/reformat-note-nodes.js.map +1 -0
- package/package.json +19 -0
- package/src/export-notes.ts +31 -0
- package/src/index.ts +10 -0
- package/src/insert-note-id.ts +23 -0
- package/src/model.ts +155 -0
- package/src/nodes.ts +7 -0
- package/src/note-parser.ts +277 -0
- package/src/note.ts +189 -0
- package/src/output.ts +27 -0
- package/src/print-model-nodes.ts +39 -0
- package/src/print-note-nodes.ts +31 -0
- package/src/reformat-model-nodes.ts +5 -0
- package/src/reformat-note-nodes.ts +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Aliaksandr Radzivanovich
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-notes.d.ts","sourceRoot":"","sources":["../src/export-notes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,CAiBzD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { formatField } from "@notatki/format";
|
|
2
|
+
import {} from "./note.js";
|
|
3
|
+
export function exportNotes(notes) {
|
|
4
|
+
const lines = [];
|
|
5
|
+
lines.push(`#separator:semicolon`);
|
|
6
|
+
lines.push(`#html:true`);
|
|
7
|
+
lines.push(`#guid column:1`);
|
|
8
|
+
lines.push(`#notetype column:2`);
|
|
9
|
+
lines.push(`#deck column:3`);
|
|
10
|
+
lines.push(`#tags column:4`);
|
|
11
|
+
for (const note of notes) {
|
|
12
|
+
lines.push([note.id, note.type.name, note.deck, note.tags, ...[...note].map(({ value }) => formatField(value))]
|
|
13
|
+
.map(escape)
|
|
14
|
+
.join(";"));
|
|
15
|
+
}
|
|
16
|
+
lines.push("");
|
|
17
|
+
return lines.join("\n");
|
|
18
|
+
}
|
|
19
|
+
function escape(value) {
|
|
20
|
+
if (value == null) {
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
if (value.includes(";") || value.includes("\n") || value.includes('"')) {
|
|
24
|
+
return `"${value.replaceAll('"', '""')}"`;
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=export-notes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-notes.js","sourceRoot":"","sources":["../src/export-notes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAa,MAAM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,CAAC;IAC5C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./export-notes.js";
|
|
2
|
+
export * from "./insert-note-id.js";
|
|
3
|
+
export * from "./model.js";
|
|
4
|
+
export * from "./note.js";
|
|
5
|
+
export * from "./note-parser.js";
|
|
6
|
+
export * from "./output.js";
|
|
7
|
+
export * from "./print-model-nodes.js";
|
|
8
|
+
export * from "./print-note-nodes.js";
|
|
9
|
+
export * from "./reformat-model-nodes.js";
|
|
10
|
+
export * from "./reformat-note-nodes.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./export-notes.js";
|
|
2
|
+
export * from "./insert-note-id.js";
|
|
3
|
+
export * from "./model.js";
|
|
4
|
+
export * from "./note.js";
|
|
5
|
+
export * from "./note-parser.js";
|
|
6
|
+
export * from "./output.js";
|
|
7
|
+
export * from "./print-model-nodes.js";
|
|
8
|
+
export * from "./print-note-nodes.js";
|
|
9
|
+
export * from "./reformat-model-nodes.js";
|
|
10
|
+
export * from "./reformat-note-nodes.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type NoteNode } from "@notatki/parser";
|
|
2
|
+
export type IdGenerator = () => string;
|
|
3
|
+
export declare const idGenerator: IdGenerator;
|
|
4
|
+
export declare function insertNoteId(nodes: NoteNode[], gen?: IdGenerator): boolean;
|
|
5
|
+
//# sourceMappingURL=insert-note-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insert-note-id.d.ts","sourceRoot":"","sources":["../src/insert-note-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIhD,MAAM,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC;AAEvC,eAAO,MAAM,WAAW,EAAE,WAAuC,CAAC;AAElE,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,GAAE,WAAyB,GAAG,OAAO,CAcvF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {} from "@notatki/parser";
|
|
2
|
+
import { loc } from "./nodes.js";
|
|
3
|
+
import { Note } from "./note.js";
|
|
4
|
+
export const idGenerator = () => crypto.randomUUID();
|
|
5
|
+
export function insertNoteId(nodes, gen = idGenerator) {
|
|
6
|
+
let changed = false;
|
|
7
|
+
for (const node of nodes) {
|
|
8
|
+
let field = node.fields.find(({ name }) => Note.isIdField(name.text));
|
|
9
|
+
if (field == null) {
|
|
10
|
+
node.fields.unshift((field = { name: { text: "id", loc }, value: { text: "", loc }, loc }));
|
|
11
|
+
}
|
|
12
|
+
const { value } = field;
|
|
13
|
+
if (!value.text) {
|
|
14
|
+
value.text = gen();
|
|
15
|
+
changed = true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return changed;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=insert-note-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insert-note-id.js","sourceRoot":"","sources":["../src/insert-note-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,MAAM,CAAC,MAAM,WAAW,GAAgB,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;AAElE,MAAM,UAAU,YAAY,CAAC,KAAiB,EAAE,MAAmB,WAAW;IAC5E,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACtE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;QAC9F,CAAC;QACD,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAChB,KAAK,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC;YACnB,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
export type Model = {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly id: number;
|
|
4
|
+
readonly cloze: boolean;
|
|
5
|
+
readonly fields: readonly ModelField[];
|
|
6
|
+
readonly cards: readonly ModelCard[];
|
|
7
|
+
readonly styling: string;
|
|
8
|
+
};
|
|
9
|
+
export type ModelField = {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly required: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type ModelCard = {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly front: string;
|
|
16
|
+
readonly back: string;
|
|
17
|
+
};
|
|
18
|
+
export declare class ModelMap implements Iterable<Model> {
|
|
19
|
+
#private;
|
|
20
|
+
static readonly basic: {
|
|
21
|
+
readonly name: "Basic";
|
|
22
|
+
readonly id: 1607392319;
|
|
23
|
+
readonly cloze: false;
|
|
24
|
+
readonly fields: readonly [{
|
|
25
|
+
readonly name: "Front";
|
|
26
|
+
readonly required: true;
|
|
27
|
+
}, {
|
|
28
|
+
readonly name: "Back";
|
|
29
|
+
readonly required: true;
|
|
30
|
+
}];
|
|
31
|
+
readonly cards: readonly [{
|
|
32
|
+
readonly name: "Card 1";
|
|
33
|
+
readonly front: "{{Front}}";
|
|
34
|
+
readonly back: "{{FrontSide}}<hr>{{Back}}";
|
|
35
|
+
}];
|
|
36
|
+
readonly styling: "";
|
|
37
|
+
};
|
|
38
|
+
static readonly basicAndReversedCard: {
|
|
39
|
+
readonly name: "Basic (and reversed card)";
|
|
40
|
+
readonly id: 1607392320;
|
|
41
|
+
readonly cloze: false;
|
|
42
|
+
readonly fields: readonly [{
|
|
43
|
+
readonly name: "Front";
|
|
44
|
+
readonly required: true;
|
|
45
|
+
}, {
|
|
46
|
+
readonly name: "Back";
|
|
47
|
+
readonly required: true;
|
|
48
|
+
}];
|
|
49
|
+
readonly cards: readonly [{
|
|
50
|
+
readonly name: "Card 1";
|
|
51
|
+
readonly front: "{{Front}}";
|
|
52
|
+
readonly back: "{{FrontSide}}<hr>{{Back}}";
|
|
53
|
+
}, {
|
|
54
|
+
readonly name: "Card 2";
|
|
55
|
+
readonly front: "{{Back}}";
|
|
56
|
+
readonly back: "{{FrontSide}}<hr>{{Front}}";
|
|
57
|
+
}];
|
|
58
|
+
readonly styling: "";
|
|
59
|
+
};
|
|
60
|
+
static readonly basicOptionalReversedCard: {
|
|
61
|
+
readonly name: "Basic (optional reversed card)";
|
|
62
|
+
readonly id: 1607392321;
|
|
63
|
+
readonly cloze: false;
|
|
64
|
+
readonly fields: readonly [{
|
|
65
|
+
readonly name: "Front";
|
|
66
|
+
readonly required: true;
|
|
67
|
+
}, {
|
|
68
|
+
readonly name: "Back";
|
|
69
|
+
readonly required: true;
|
|
70
|
+
}, {
|
|
71
|
+
readonly name: "Add Reverse";
|
|
72
|
+
readonly required: false;
|
|
73
|
+
}];
|
|
74
|
+
readonly cards: readonly [{
|
|
75
|
+
readonly name: "Card 1";
|
|
76
|
+
readonly front: "{{Front}}";
|
|
77
|
+
readonly back: "{{FrontSide}}<hr>{{Back}}";
|
|
78
|
+
}, {
|
|
79
|
+
readonly name: "Card 2";
|
|
80
|
+
readonly front: "{{#Add Reverse}}{{Back}}{{/Add Reverse}}";
|
|
81
|
+
readonly back: "{{FrontSide}}<hr>{{Front}}";
|
|
82
|
+
}];
|
|
83
|
+
readonly styling: "";
|
|
84
|
+
};
|
|
85
|
+
static readonly basicTypeInAnswer: {
|
|
86
|
+
readonly name: "Basic (type in the answer)";
|
|
87
|
+
readonly id: 1607392322;
|
|
88
|
+
readonly cloze: false;
|
|
89
|
+
readonly fields: readonly [{
|
|
90
|
+
readonly name: "Front";
|
|
91
|
+
readonly required: true;
|
|
92
|
+
}, {
|
|
93
|
+
readonly name: "Back";
|
|
94
|
+
readonly required: true;
|
|
95
|
+
}];
|
|
96
|
+
readonly cards: readonly [{
|
|
97
|
+
readonly name: "Card 1";
|
|
98
|
+
readonly front: "{{Front}}<br>{{type:Back}}";
|
|
99
|
+
readonly back: "{{Front}}<hr>{{Back}}";
|
|
100
|
+
}];
|
|
101
|
+
readonly styling: "";
|
|
102
|
+
};
|
|
103
|
+
static readonly cloze: {
|
|
104
|
+
readonly name: "Cloze";
|
|
105
|
+
readonly id: 1607392323;
|
|
106
|
+
readonly cloze: true;
|
|
107
|
+
readonly fields: readonly [{
|
|
108
|
+
readonly name: "Text";
|
|
109
|
+
readonly required: true;
|
|
110
|
+
}, {
|
|
111
|
+
readonly name: "Back Extra";
|
|
112
|
+
readonly required: false;
|
|
113
|
+
}];
|
|
114
|
+
readonly cards: readonly [{
|
|
115
|
+
readonly name: "Cloze";
|
|
116
|
+
readonly front: "{{cloze:Text}}";
|
|
117
|
+
readonly back: "{{cloze:Text}}<br>{{Back Extra}}";
|
|
118
|
+
}];
|
|
119
|
+
readonly styling: "";
|
|
120
|
+
};
|
|
121
|
+
static readonly internal: readonly Model[];
|
|
122
|
+
constructor(initial?: Iterable<Model>);
|
|
123
|
+
[Symbol.iterator](): Iterator<Model>;
|
|
124
|
+
add(model: Model): this;
|
|
125
|
+
has(name: string): boolean;
|
|
126
|
+
get(name: string): Model | null;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,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+
name: "Basic",
|
|
4
|
+
id: 1607392319,
|
|
5
|
+
cloze: false,
|
|
6
|
+
fields: [
|
|
7
|
+
{ name: "Front", required: true },
|
|
8
|
+
{ name: "Back", required: true },
|
|
9
|
+
],
|
|
10
|
+
cards: [
|
|
11
|
+
{
|
|
12
|
+
name: "Card 1",
|
|
13
|
+
front: "{{Front}}",
|
|
14
|
+
back: "{{FrontSide}}<hr>{{Back}}",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
styling: "",
|
|
18
|
+
};
|
|
19
|
+
static basicAndReversedCard = {
|
|
20
|
+
name: "Basic (and reversed card)",
|
|
21
|
+
id: 1607392320,
|
|
22
|
+
cloze: false,
|
|
23
|
+
fields: [
|
|
24
|
+
{ name: "Front", required: true },
|
|
25
|
+
{ name: "Back", required: true },
|
|
26
|
+
],
|
|
27
|
+
cards: [
|
|
28
|
+
{
|
|
29
|
+
name: "Card 1",
|
|
30
|
+
front: "{{Front}}",
|
|
31
|
+
back: "{{FrontSide}}<hr>{{Back}}",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "Card 2",
|
|
35
|
+
front: "{{Back}}",
|
|
36
|
+
back: "{{FrontSide}}<hr>{{Front}}",
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
styling: "",
|
|
40
|
+
};
|
|
41
|
+
static basicOptionalReversedCard = {
|
|
42
|
+
name: "Basic (optional reversed card)",
|
|
43
|
+
id: 1607392321,
|
|
44
|
+
cloze: false,
|
|
45
|
+
fields: [
|
|
46
|
+
{ name: "Front", required: true },
|
|
47
|
+
{ name: "Back", required: true },
|
|
48
|
+
{ name: "Add Reverse", required: false },
|
|
49
|
+
],
|
|
50
|
+
cards: [
|
|
51
|
+
{
|
|
52
|
+
name: "Card 1",
|
|
53
|
+
front: "{{Front}}",
|
|
54
|
+
back: "{{FrontSide}}<hr>{{Back}}",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "Card 2",
|
|
58
|
+
front: "{{#Add Reverse}}{{Back}}{{/Add Reverse}}",
|
|
59
|
+
back: "{{FrontSide}}<hr>{{Front}}",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
styling: "",
|
|
63
|
+
};
|
|
64
|
+
static basicTypeInAnswer = {
|
|
65
|
+
name: "Basic (type in the answer)",
|
|
66
|
+
id: 1607392322,
|
|
67
|
+
cloze: false,
|
|
68
|
+
fields: [
|
|
69
|
+
{ name: "Front", required: true },
|
|
70
|
+
{ name: "Back", required: true },
|
|
71
|
+
],
|
|
72
|
+
cards: [
|
|
73
|
+
{
|
|
74
|
+
name: "Card 1",
|
|
75
|
+
front: "{{Front}}<br>{{type:Back}}",
|
|
76
|
+
back: "{{Front}}<hr>{{Back}}",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
styling: "",
|
|
80
|
+
};
|
|
81
|
+
static cloze = {
|
|
82
|
+
name: "Cloze",
|
|
83
|
+
id: 1607392323,
|
|
84
|
+
cloze: true,
|
|
85
|
+
fields: [
|
|
86
|
+
{ name: "Text", required: true },
|
|
87
|
+
{ name: "Back Extra", required: false },
|
|
88
|
+
],
|
|
89
|
+
cards: [
|
|
90
|
+
{
|
|
91
|
+
name: "Cloze",
|
|
92
|
+
front: "{{cloze:Text}}",
|
|
93
|
+
back: "{{cloze:Text}}<br>{{Back Extra}}",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
styling: "",
|
|
97
|
+
};
|
|
98
|
+
static internal = [
|
|
99
|
+
ModelMap.basic,
|
|
100
|
+
ModelMap.basicAndReversedCard,
|
|
101
|
+
ModelMap.basicOptionalReversedCard,
|
|
102
|
+
ModelMap.basicTypeInAnswer,
|
|
103
|
+
ModelMap.cloze,
|
|
104
|
+
];
|
|
105
|
+
#map = new Map();
|
|
106
|
+
constructor(initial = ModelMap.internal) {
|
|
107
|
+
for (const model of initial) {
|
|
108
|
+
this.add(model);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
[Symbol.iterator]() {
|
|
112
|
+
return this.#map.values();
|
|
113
|
+
}
|
|
114
|
+
add(model) {
|
|
115
|
+
this.#map.set(model.name.toLowerCase(), model);
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
has(name) {
|
|
119
|
+
return this.#map.has(name.toLowerCase());
|
|
120
|
+
}
|
|
121
|
+
get(name) {
|
|
122
|
+
return this.#map.get(name.toLowerCase()) ?? null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAoBA,MAAM,OAAO,QAAQ;IACnB,MAAM,CAAU,KAAK,GAAG;QACtB,IAAI,EAAE,OAAO;QACb,EAAE,EAAE,UAAU;QACd,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE;YACjC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;SACjC;QACD,KAAK,EAAE;YACL;gBACE,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,WAAW;gBAClB,IAAI,EAAE,2BAA2B;aAClC;SACF;QACD,OAAO,EAAE,EAAE;KACa,CAAC;IAE3B,MAAM,CAAU,oBAAoB,GAAG;QACrC,IAAI,EAAE,2BAA2B;QACjC,EAAE,EAAE,UAAU;QACd,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE;YACjC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;SACjC;QACD,KAAK,EAAE;YACL;gBACE,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,WAAW;gBAClB,IAAI,EAAE,2BAA2B;aAClC;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,U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
|
+
readonly line: 0;
|
|
6
|
+
readonly column: 0;
|
|
7
|
+
};
|
|
8
|
+
readonly end: {
|
|
9
|
+
readonly offset: 0;
|
|
10
|
+
readonly line: 0;
|
|
11
|
+
readonly column: 0;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG;;;;;;;;;;;;CAIkB,CAAC"}
|
package/dist/nodes.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,iBAAiB,CAAC;AAErD,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,MAAM,EAAE,WAAW;IACnB,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;IACxC,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;CACN,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type LocationRange, type ModelNode, type NoteNode } from "@notatki/parser";
|
|
2
|
+
import { type Model } from "./model.js";
|
|
3
|
+
import { NoteList } from "./note.js";
|
|
4
|
+
export type NoteError = {
|
|
5
|
+
message: string;
|
|
6
|
+
location: LocationRange;
|
|
7
|
+
};
|
|
8
|
+
export declare class ParseError extends Error {
|
|
9
|
+
errors: readonly NoteError[];
|
|
10
|
+
constructor(errors: Iterable<NoteError>);
|
|
11
|
+
}
|
|
12
|
+
type ParseState = {
|
|
13
|
+
type: Model;
|
|
14
|
+
deck: string;
|
|
15
|
+
tags: string;
|
|
16
|
+
};
|
|
17
|
+
export declare class NoteParser {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(notes?: NoteList);
|
|
20
|
+
get notes(): NoteList;
|
|
21
|
+
get errors(): readonly NoteError[];
|
|
22
|
+
checkErrors(): void | never;
|
|
23
|
+
checkDuplicates(): void;
|
|
24
|
+
parseModels(path: string, text: string): this;
|
|
25
|
+
parseModelNodes(path: string, text: string): ModelNode[];
|
|
26
|
+
walkModelNodes(nodes: readonly ModelNode[]): void;
|
|
27
|
+
walkModelNode(node: ModelNode): void;
|
|
28
|
+
parseNotes(path: string, text: string): this;
|
|
29
|
+
parseNoteNodes(path: string, text: string): NoteNode[];
|
|
30
|
+
walkNoteNodes(nodes: readonly NoteNode[], state?: ParseState): void;
|
|
31
|
+
walkNoteNode(noteNode: NoteNode, state: ParseState): void;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=note-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"note-parser.d.ts","sourceRoot":"","sources":["../src/note-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,QAAQ,EAKd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,KAAK,EAA6C,MAAM,YAAY,CAAC;AACnF,OAAO,EAAQ,QAAQ,EAAE,MAAM,WAAW,CAAC;AAQ3C,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,aAAa,CAAC;CACzB,CAAC;AAEF,qBAAa,UAAW,SAAQ,KAAK;IACnC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;gBAEjB,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC;CAMxC;AAED,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,UAAU;;gBAIT,K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