@signalsafe/learning-core 0.1.1 → 0.1.2
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/dist/lessonContentValidation.js +17 -48
- package/dist/markdown.js +8 -11
- package/package.json +10 -6
|
@@ -4,13 +4,8 @@ const LESSON_SIMULATION_CHANNELS = new Set(['email', 'sms', 'browser']);
|
|
|
4
4
|
* Used by the lesson form to block save on errors and show warnings.
|
|
5
5
|
*/
|
|
6
6
|
import { isEmptyMarkdownHeading, isH1MarkdownLine, isMarkdownHeadingWithTrailingSpace, isNumericRunId, isSafeLessonId, lineHasTrailingWhitespace, parseClosedDynamicBlock, parseQuotedAttributes, startsDynamicBlockLine, stripHtmlTags, } from './markdown.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const block = parseClosedDynamicBlock(trimmed);
|
|
10
|
-
if (block?.type !== 'checkpoint') {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const attrs = parseQuotedAttributes(block.attrsRaw, new Set(['id', 'question', 'options', 'answer']));
|
|
7
|
+
function validateCheckpointLine(attrsRaw) {
|
|
8
|
+
const attrs = parseQuotedAttributes(attrsRaw, new Set(['id', 'question', 'options', 'answer']));
|
|
14
9
|
const question = (attrs['question'] ?? '').trim();
|
|
15
10
|
const optionsRaw = (attrs['options'] ?? '').trim();
|
|
16
11
|
const answer = (attrs['answer'] ?? '').trim();
|
|
@@ -33,12 +28,8 @@ function validateCheckpointLine(trimmed) {
|
|
|
33
28
|
return 'Checkpoint id must be alphanumeric, dashes, or underscores only.';
|
|
34
29
|
return null;
|
|
35
30
|
}
|
|
36
|
-
function validateSimRefLine(
|
|
37
|
-
const
|
|
38
|
-
if (block?.type !== 'sim_ref') {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
const attrs = parseQuotedAttributes(block.attrsRaw, new Set(['channel', 'run_id', 'label']));
|
|
31
|
+
function validateSimRefLine(attrsRaw) {
|
|
32
|
+
const attrs = parseQuotedAttributes(attrsRaw, new Set(['channel', 'run_id', 'label']));
|
|
42
33
|
const channel = (attrs['channel'] ?? '').toLowerCase().trim();
|
|
43
34
|
const run_id = (attrs['run_id'] ?? '').trim();
|
|
44
35
|
if (!LESSON_SIMULATION_CHANNELS.has(channel))
|
|
@@ -47,12 +38,8 @@ function validateSimRefLine(trimmed) {
|
|
|
47
38
|
return 'sim_ref run_id must be a numeric run id.';
|
|
48
39
|
return null;
|
|
49
40
|
}
|
|
50
|
-
function validateScenarioRefLine(
|
|
51
|
-
const
|
|
52
|
-
if (block?.type !== 'scenario_ref') {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
const attrs = parseQuotedAttributes(block.attrsRaw, new Set(['scenario_id', 'scenario_version_id', 'label']));
|
|
41
|
+
function validateScenarioRefLine(attrsRaw) {
|
|
42
|
+
const attrs = parseQuotedAttributes(attrsRaw, new Set(['scenario_id', 'scenario_version_id', 'label']));
|
|
56
43
|
const scenario_id = (attrs['scenario_id'] ?? '').trim();
|
|
57
44
|
const label = (attrs['label'] ?? '').trim();
|
|
58
45
|
if (!scenario_id)
|
|
@@ -63,12 +50,8 @@ function validateScenarioRefLine(trimmed) {
|
|
|
63
50
|
return 'scenario_ref must have label="...".';
|
|
64
51
|
return null;
|
|
65
52
|
}
|
|
66
|
-
function getCheckpointId(
|
|
67
|
-
const
|
|
68
|
-
if (block?.type !== 'checkpoint') {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
const attrs = parseQuotedAttributes(block.attrsRaw, new Set(['id', 'question', 'options', 'answer']));
|
|
53
|
+
function getCheckpointId(attrsRaw) {
|
|
54
|
+
const attrs = parseQuotedAttributes(attrsRaw, new Set(['id', 'question', 'options', 'answer']));
|
|
72
55
|
const id = (attrs['id'] ?? '').trim();
|
|
73
56
|
return id || null;
|
|
74
57
|
}
|
|
@@ -82,32 +65,28 @@ function validateDynamicBlockLine(trimmed, lineNum, state) {
|
|
|
82
65
|
return true;
|
|
83
66
|
}
|
|
84
67
|
const blockType = blockMatch.type;
|
|
85
|
-
|
|
86
|
-
state.errors.push(`Line ${lineNum}: Unknown dynamic block type "${blockType}". Use :::checkpoint, :::sim_ref, or :::scenario_ref.`);
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
const validationError = getDynamicBlockValidationError(blockType, trimmed);
|
|
68
|
+
const validationError = getDynamicBlockValidationError(blockType, blockMatch.attrsRaw);
|
|
90
69
|
if (validationError) {
|
|
91
70
|
state.errors.push(`Line ${lineNum}: ${validationError}`);
|
|
92
71
|
return true;
|
|
93
72
|
}
|
|
94
73
|
if (blockType === 'checkpoint') {
|
|
95
|
-
const id = getCheckpointId(
|
|
74
|
+
const id = getCheckpointId(blockMatch.attrsRaw);
|
|
96
75
|
if (id)
|
|
97
76
|
state.checkpointIds.push({ line: lineNum, id });
|
|
98
77
|
}
|
|
99
78
|
return true;
|
|
100
79
|
}
|
|
101
|
-
function getDynamicBlockValidationError(blockType,
|
|
80
|
+
function getDynamicBlockValidationError(blockType, attrsRaw) {
|
|
102
81
|
switch (blockType) {
|
|
103
82
|
case 'checkpoint':
|
|
104
|
-
return validateCheckpointLine(
|
|
83
|
+
return validateCheckpointLine(attrsRaw);
|
|
105
84
|
case 'sim_ref':
|
|
106
|
-
return validateSimRefLine(
|
|
85
|
+
return validateSimRefLine(attrsRaw);
|
|
107
86
|
case 'scenario_ref':
|
|
108
|
-
return validateScenarioRefLine(
|
|
87
|
+
return validateScenarioRefLine(attrsRaw);
|
|
109
88
|
default:
|
|
110
|
-
return
|
|
89
|
+
return `Unknown dynamic block type "${blockType}". Use :::checkpoint, :::sim_ref, or :::scenario_ref.`;
|
|
111
90
|
}
|
|
112
91
|
}
|
|
113
92
|
function addMarkdownLintWarnings(line, lineNum, state) {
|
|
@@ -149,15 +128,6 @@ function addTrailingWhitespaceWarnings(lines, state) {
|
|
|
149
128
|
? `Trailing whitespace on line(s) ${trailingLines.join(', ')}.`
|
|
150
129
|
: `Trailing whitespace on ${trailingLines.length} lines (e.g. ${trailingLines.slice(0, 2).join(', ')}).`);
|
|
151
130
|
}
|
|
152
|
-
function dedupeWarnings(warnings) {
|
|
153
|
-
const seenWarn = new Set();
|
|
154
|
-
return warnings.filter((warning) => {
|
|
155
|
-
if (seenWarn.has(warning))
|
|
156
|
-
return false;
|
|
157
|
-
seenWarn.add(warning);
|
|
158
|
-
return true;
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
131
|
export function validateLessonContent(md) {
|
|
162
132
|
const raw = stripHtmlTags(md ?? '');
|
|
163
133
|
const lines = raw.split(/\r?\n/);
|
|
@@ -167,8 +137,7 @@ export function validateLessonContent(md) {
|
|
|
167
137
|
checkpointIds: [],
|
|
168
138
|
h1Count: 0,
|
|
169
139
|
};
|
|
170
|
-
for (
|
|
171
|
-
const line = lines[i] ?? '';
|
|
140
|
+
for (const [i, line] of lines.entries()) {
|
|
172
141
|
const trimmed = line.trim();
|
|
173
142
|
const lineNum = i + 1;
|
|
174
143
|
if (validateDynamicBlockLine(trimmed, lineNum, state))
|
|
@@ -180,5 +149,5 @@ export function validateLessonContent(md) {
|
|
|
180
149
|
state.warnings.push(`Multiple H1 headings (${state.h1Count}). Consider using a single H1 for the title.`);
|
|
181
150
|
}
|
|
182
151
|
addTrailingWhitespaceWarnings(lines, state);
|
|
183
|
-
return { errors: state.errors, warnings:
|
|
152
|
+
return { errors: state.errors, warnings: state.warnings };
|
|
184
153
|
}
|
package/dist/markdown.js
CHANGED
|
@@ -35,7 +35,7 @@ function skipAttrSpaces(raw, i) {
|
|
|
35
35
|
}
|
|
36
36
|
function readAttrKey(raw, i) {
|
|
37
37
|
const keyStart = i;
|
|
38
|
-
while (i < raw.length && isAttrNameChar(raw
|
|
38
|
+
while (i < raw.length && isAttrNameChar(raw.charAt(i))) {
|
|
39
39
|
i++;
|
|
40
40
|
}
|
|
41
41
|
if (i === keyStart) {
|
|
@@ -53,7 +53,7 @@ function readQuotedAttrValue(raw, i) {
|
|
|
53
53
|
i++;
|
|
54
54
|
}
|
|
55
55
|
const value = raw.slice(valStart, i).trim();
|
|
56
|
-
if (i < raw.length
|
|
56
|
+
if (i < raw.length) {
|
|
57
57
|
i++;
|
|
58
58
|
}
|
|
59
59
|
return { value, i };
|
|
@@ -109,7 +109,7 @@ export function startsDynamicBlockLine(trimmed) {
|
|
|
109
109
|
while (i < trimmed.length && trimmed[i] === ' ') {
|
|
110
110
|
i++;
|
|
111
111
|
}
|
|
112
|
-
return i < trimmed.length && isWordChar(trimmed
|
|
112
|
+
return i < trimmed.length && isWordChar(trimmed.charAt(i));
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* Parse a single-line `:::type attr="..." :::` block.
|
|
@@ -126,11 +126,8 @@ export function parseClosedDynamicBlock(trimmed) {
|
|
|
126
126
|
}
|
|
127
127
|
const inner = line.slice(3, closeAt).trim();
|
|
128
128
|
let i = 0;
|
|
129
|
-
while (i < inner.length && inner[i] === ' ') {
|
|
130
|
-
i++;
|
|
131
|
-
}
|
|
132
129
|
const typeStart = i;
|
|
133
|
-
while (i < inner.length && isWordChar(inner
|
|
130
|
+
while (i < inner.length && isWordChar(inner.charAt(i))) {
|
|
134
131
|
i++;
|
|
135
132
|
}
|
|
136
133
|
if (i === typeStart) {
|
|
@@ -180,7 +177,7 @@ export function isMarkdownHeadingWithTrailingSpace(line) {
|
|
|
180
177
|
while (i < line.length && line[i] === '#') {
|
|
181
178
|
i++;
|
|
182
179
|
}
|
|
183
|
-
return i
|
|
180
|
+
return i <= 6 && (line[i] ?? '') === ' ' && line.endsWith(' ');
|
|
184
181
|
}
|
|
185
182
|
export function parseBulletListItem(line) {
|
|
186
183
|
const trimmed = line.trimStart();
|
|
@@ -199,8 +196,8 @@ export function parseOrderedListItem(line) {
|
|
|
199
196
|
}
|
|
200
197
|
const numStart = i;
|
|
201
198
|
while (i < line.length) {
|
|
202
|
-
const ch = line
|
|
203
|
-
if (ch
|
|
199
|
+
const ch = line.charAt(i);
|
|
200
|
+
if (ch < '0' || ch > '9') {
|
|
204
201
|
break;
|
|
205
202
|
}
|
|
206
203
|
i++;
|
|
@@ -213,7 +210,7 @@ export function parseOrderedListItem(line) {
|
|
|
213
210
|
}
|
|
214
211
|
export function isCodeFenceLine(line) {
|
|
215
212
|
const t = line.trim();
|
|
216
|
-
return t === '```'
|
|
213
|
+
return t === '```';
|
|
217
214
|
}
|
|
218
215
|
export function lineHasTrailingWhitespace(line) {
|
|
219
216
|
return line.length > 0 && (line.endsWith(' ') || line.endsWith('\t'));
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signalsafe/learning-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/SignalSafeSoftware/learning-core.git"
|
|
8
|
+
},
|
|
5
9
|
"files": [
|
|
6
10
|
"dist",
|
|
7
11
|
"README.md",
|
|
@@ -28,16 +32,16 @@
|
|
|
28
32
|
"typecheck": "tsc --noEmit",
|
|
29
33
|
"lint": "oxlint --deny-warnings src",
|
|
30
34
|
"format:check": "oxfmt --check .",
|
|
31
|
-
"test": "vitest run --configLoader runner --no-cache",
|
|
35
|
+
"test": "vitest run --configLoader runner --no-cache --coverage",
|
|
32
36
|
"prepublishOnly": "npm run build",
|
|
33
37
|
"pack:dry-run": "npm pack --dry-run --ignore-scripts"
|
|
34
38
|
},
|
|
35
39
|
"devDependencies": {
|
|
36
|
-
"@vitest/coverage-v8": "5.0
|
|
37
|
-
"oxfmt": "0.
|
|
38
|
-
"oxlint": "1.
|
|
40
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
41
|
+
"oxfmt": "0.78.0",
|
|
42
|
+
"oxlint": "1.93.0",
|
|
39
43
|
"typescript": "7.0.2",
|
|
40
|
-
"vitest": "5.0
|
|
44
|
+
"vitest": "5.1.0"
|
|
41
45
|
},
|
|
42
46
|
"engines": {
|
|
43
47
|
"node": ">=22.12.0"
|