@signalsafe/learning-core 0.0.0-stage → 0.1.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/README.md +4 -2
- package/dist/lessonContentValidation.d.ts +5 -0
- package/dist/lessonContentValidation.js +184 -0
- package/dist/markdown.d.ts +48 -0
- package/dist/markdown.js +303 -0
- package/docs/README.md +9 -0
- package/docs/release-candidate-2026-10-21.md +7 -0
- package/package.json +44 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Josh Martin
|
|
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 copies
|
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# learning-core TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Version 0.1.1 is the verified maintenance candidate. The prior version 0.1.0 is publicly available on npm; publication of this new version uses the existing immutable `ts-v0.1.1` tag workflow after the combined checks and review. See [usage and boundaries](docs/README.md) and [current reconciliation](../docs/release-reconciliation-2026-11-15.md).
|
|
4
|
+
|
|
5
|
+
Public exports and compatibility ranges remain unchanged. Hosts own their state, transport, permissions and product rules.
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
const LESSON_SIMULATION_CHANNELS = new Set(['email', 'sms', 'browser']);
|
|
2
|
+
/**
|
|
3
|
+
* Lesson content validation: checkpoints, dynamic blocks, and markdown lint.
|
|
4
|
+
* Used by the lesson form to block save on errors and show warnings.
|
|
5
|
+
*/
|
|
6
|
+
import { isEmptyMarkdownHeading, isH1MarkdownLine, isMarkdownHeadingWithTrailingSpace, isNumericRunId, isSafeLessonId, lineHasTrailingWhitespace, parseClosedDynamicBlock, parseQuotedAttributes, startsDynamicBlockLine, stripHtmlTags, } from './markdown.js';
|
|
7
|
+
const ALLOWED_BLOCK_TYPES = new Set(['checkpoint', 'sim_ref', 'scenario_ref']);
|
|
8
|
+
function validateCheckpointLine(trimmed) {
|
|
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']));
|
|
14
|
+
const question = (attrs['question'] ?? '').trim();
|
|
15
|
+
const optionsRaw = (attrs['options'] ?? '').trim();
|
|
16
|
+
const answer = (attrs['answer'] ?? '').trim();
|
|
17
|
+
if (!question)
|
|
18
|
+
return 'Checkpoint block must have question="...".';
|
|
19
|
+
if (!optionsRaw)
|
|
20
|
+
return 'Checkpoint block must have options="...|..." (pipe-separated, at least 2).';
|
|
21
|
+
const options = optionsRaw
|
|
22
|
+
.split('|')
|
|
23
|
+
.map((o) => o.trim())
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
if (options.length < 2)
|
|
26
|
+
return 'Checkpoint options must have at least 2 pipe-separated choices.';
|
|
27
|
+
if (!answer)
|
|
28
|
+
return 'Checkpoint block must have answer="..." matching one of the options.';
|
|
29
|
+
if (!options.includes(answer))
|
|
30
|
+
return 'Checkpoint answer must exactly match one of the options.';
|
|
31
|
+
const id = (attrs['id'] ?? '').trim();
|
|
32
|
+
if (id && !isSafeLessonId(id))
|
|
33
|
+
return 'Checkpoint id must be alphanumeric, dashes, or underscores only.';
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function validateSimRefLine(trimmed) {
|
|
37
|
+
const block = parseClosedDynamicBlock(trimmed);
|
|
38
|
+
if (block?.type !== 'sim_ref') {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const attrs = parseQuotedAttributes(block.attrsRaw, new Set(['channel', 'run_id', 'label']));
|
|
42
|
+
const channel = (attrs['channel'] ?? '').toLowerCase().trim();
|
|
43
|
+
const run_id = (attrs['run_id'] ?? '').trim();
|
|
44
|
+
if (!LESSON_SIMULATION_CHANNELS.has(channel))
|
|
45
|
+
return 'sim_ref channel must be email, sms, or browser.';
|
|
46
|
+
if (!isNumericRunId(run_id))
|
|
47
|
+
return 'sim_ref run_id must be a numeric run id.';
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function validateScenarioRefLine(trimmed) {
|
|
51
|
+
const block = parseClosedDynamicBlock(trimmed);
|
|
52
|
+
if (block?.type !== 'scenario_ref') {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const attrs = parseQuotedAttributes(block.attrsRaw, new Set(['scenario_id', 'scenario_version_id', 'label']));
|
|
56
|
+
const scenario_id = (attrs['scenario_id'] ?? '').trim();
|
|
57
|
+
const label = (attrs['label'] ?? '').trim();
|
|
58
|
+
if (!scenario_id)
|
|
59
|
+
return 'scenario_ref must have scenario_id="...".';
|
|
60
|
+
if (!isSafeLessonId(scenario_id))
|
|
61
|
+
return 'scenario_ref scenario_id must be alphanumeric, dashes, or underscores.';
|
|
62
|
+
if (!label)
|
|
63
|
+
return 'scenario_ref must have label="...".';
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
function getCheckpointId(trimmed) {
|
|
67
|
+
const block = parseClosedDynamicBlock(trimmed);
|
|
68
|
+
if (block?.type !== 'checkpoint') {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const attrs = parseQuotedAttributes(block.attrsRaw, new Set(['id', 'question', 'options', 'answer']));
|
|
72
|
+
const id = (attrs['id'] ?? '').trim();
|
|
73
|
+
return id || null;
|
|
74
|
+
}
|
|
75
|
+
const MAX_LINE_LENGTH_LINT = 200;
|
|
76
|
+
function validateDynamicBlockLine(trimmed, lineNum, state) {
|
|
77
|
+
if (!startsDynamicBlockLine(trimmed))
|
|
78
|
+
return false;
|
|
79
|
+
const blockMatch = parseClosedDynamicBlock(trimmed);
|
|
80
|
+
if (!blockMatch) {
|
|
81
|
+
state.errors.push(`Line ${lineNum}: Unclosed or invalid dynamic block. Use :::type attr="val" ... ::: on one line (checkpoint, sim_ref, or scenario_ref).`);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
const blockType = blockMatch.type;
|
|
85
|
+
if (!ALLOWED_BLOCK_TYPES.has(blockType)) {
|
|
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);
|
|
90
|
+
if (validationError) {
|
|
91
|
+
state.errors.push(`Line ${lineNum}: ${validationError}`);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
if (blockType === 'checkpoint') {
|
|
95
|
+
const id = getCheckpointId(trimmed);
|
|
96
|
+
if (id)
|
|
97
|
+
state.checkpointIds.push({ line: lineNum, id });
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
function getDynamicBlockValidationError(blockType, trimmed) {
|
|
102
|
+
switch (blockType) {
|
|
103
|
+
case 'checkpoint':
|
|
104
|
+
return validateCheckpointLine(trimmed);
|
|
105
|
+
case 'sim_ref':
|
|
106
|
+
return validateSimRefLine(trimmed);
|
|
107
|
+
case 'scenario_ref':
|
|
108
|
+
return validateScenarioRefLine(trimmed);
|
|
109
|
+
default:
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function addMarkdownLintWarnings(line, lineNum, state) {
|
|
114
|
+
if (line.length > MAX_LINE_LENGTH_LINT) {
|
|
115
|
+
state.warnings.push(`Line ${lineNum}: Line longer than ${MAX_LINE_LENGTH_LINT} characters (${line.length}).`);
|
|
116
|
+
}
|
|
117
|
+
if (isEmptyMarkdownHeading(line)) {
|
|
118
|
+
state.warnings.push(`Line ${lineNum}: Empty heading. Add heading text.`);
|
|
119
|
+
}
|
|
120
|
+
if (isH1MarkdownLine(line)) {
|
|
121
|
+
state.h1Count += 1;
|
|
122
|
+
}
|
|
123
|
+
if (isMarkdownHeadingWithTrailingSpace(line)) {
|
|
124
|
+
state.warnings.push(`Line ${lineNum}: Trailing whitespace after heading.`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function addDuplicateCheckpointWarnings(state) {
|
|
128
|
+
const idToLines = new Map();
|
|
129
|
+
for (const { line, id } of state.checkpointIds) {
|
|
130
|
+
const linesForId = idToLines.get(id) ?? [];
|
|
131
|
+
linesForId.push(line);
|
|
132
|
+
idToLines.set(id, linesForId);
|
|
133
|
+
}
|
|
134
|
+
for (const [id, lineList] of idToLines) {
|
|
135
|
+
if (lineList.length > 1) {
|
|
136
|
+
state.warnings.push(`Checkpoint id "${id}" is repeated on lines ${lineList.join(', ')}. Use unique ids.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function addTrailingWhitespaceWarnings(lines, state) {
|
|
141
|
+
const trailingLines = [];
|
|
142
|
+
lines.forEach((line, index) => {
|
|
143
|
+
if (lineHasTrailingWhitespace(line))
|
|
144
|
+
trailingLines.push(index + 1);
|
|
145
|
+
});
|
|
146
|
+
if (trailingLines.length === 0)
|
|
147
|
+
return;
|
|
148
|
+
state.warnings.push(trailingLines.length <= 3
|
|
149
|
+
? `Trailing whitespace on line(s) ${trailingLines.join(', ')}.`
|
|
150
|
+
: `Trailing whitespace on ${trailingLines.length} lines (e.g. ${trailingLines.slice(0, 2).join(', ')}).`);
|
|
151
|
+
}
|
|
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
|
+
export function validateLessonContent(md) {
|
|
162
|
+
const raw = stripHtmlTags(md ?? '');
|
|
163
|
+
const lines = raw.split(/\r?\n/);
|
|
164
|
+
const state = {
|
|
165
|
+
errors: [],
|
|
166
|
+
warnings: [],
|
|
167
|
+
checkpointIds: [],
|
|
168
|
+
h1Count: 0,
|
|
169
|
+
};
|
|
170
|
+
for (let i = 0; i < lines.length; i++) {
|
|
171
|
+
const line = lines[i] ?? '';
|
|
172
|
+
const trimmed = line.trim();
|
|
173
|
+
const lineNum = i + 1;
|
|
174
|
+
if (validateDynamicBlockLine(trimmed, lineNum, state))
|
|
175
|
+
continue;
|
|
176
|
+
addMarkdownLintWarnings(line, lineNum, state);
|
|
177
|
+
}
|
|
178
|
+
addDuplicateCheckpointWarnings(state);
|
|
179
|
+
if (state.h1Count > 1) {
|
|
180
|
+
state.warnings.push(`Multiple H1 headings (${state.h1Count}). Consider using a single H1 for the title.`);
|
|
181
|
+
}
|
|
182
|
+
addTrailingWhitespaceWarnings(lines, state);
|
|
183
|
+
return { errors: state.errors, warnings: dedupeWarnings(state.warnings) };
|
|
184
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linear-time parsers for lesson markdown (no backtracking-prone regex).
|
|
3
|
+
* Shared by lessonContentValidation and MarkdownPreview (Sonar S5852).
|
|
4
|
+
*/
|
|
5
|
+
/** Strip HTML tags in O(n) without `<[^>]*>`-style regex. */
|
|
6
|
+
export declare function stripHtmlTags(text: string): string;
|
|
7
|
+
/** Parse `key="value"` tokens; only keys in `allowed` are returned. */
|
|
8
|
+
export declare function parseQuotedAttributes(raw: string, allowed: Set<string>): Record<string, string>;
|
|
9
|
+
export declare function isSafeLessonId(id: string): boolean;
|
|
10
|
+
/** True when line opens a dynamic block (`:::word`) but may be unclosed. */
|
|
11
|
+
export declare function startsDynamicBlockLine(trimmed: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Parse a single-line `:::type attr="..." :::` block.
|
|
14
|
+
* Returns null when the line is not a well-formed closed block.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseClosedDynamicBlock(trimmed: string): {
|
|
17
|
+
type: string;
|
|
18
|
+
attrsRaw: string;
|
|
19
|
+
} | null;
|
|
20
|
+
export declare function isNumericRunId(value: string): boolean;
|
|
21
|
+
/** Heading level 1–3 with required space after hashes; `text` excludes leading # run. */
|
|
22
|
+
export declare function parseMarkdownHeading(line: string): {
|
|
23
|
+
level: 1 | 2 | 3;
|
|
24
|
+
text: string;
|
|
25
|
+
} | null;
|
|
26
|
+
export declare function isEmptyMarkdownHeading(line: string): boolean;
|
|
27
|
+
export declare function isH1MarkdownLine(line: string): boolean;
|
|
28
|
+
export declare function isMarkdownHeadingWithTrailingSpace(line: string): boolean;
|
|
29
|
+
export declare function parseBulletListItem(line: string): string | null;
|
|
30
|
+
export declare function parseOrderedListItem(line: string): {
|
|
31
|
+
num: number;
|
|
32
|
+
text: string;
|
|
33
|
+
} | null;
|
|
34
|
+
export declare function isCodeFenceLine(line: string): boolean;
|
|
35
|
+
export declare function lineHasTrailingWhitespace(line: string): boolean;
|
|
36
|
+
export type InlineSegment = {
|
|
37
|
+
type: 'text';
|
|
38
|
+
value: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'code';
|
|
41
|
+
value: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'link';
|
|
44
|
+
text: string;
|
|
45
|
+
url: string;
|
|
46
|
+
};
|
|
47
|
+
/** Parse inline `code`, [text](url), and plain text segments. */
|
|
48
|
+
export declare function parseInlineMarkdown(line: string): InlineSegment[];
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linear-time parsers for lesson markdown (no backtracking-prone regex).
|
|
3
|
+
* Shared by lessonContentValidation and MarkdownPreview (Sonar S5852).
|
|
4
|
+
*/
|
|
5
|
+
function isWordChar(ch) {
|
|
6
|
+
return ((ch >= 'a' && ch <= 'z') ||
|
|
7
|
+
(ch >= 'A' && ch <= 'Z') ||
|
|
8
|
+
(ch >= '0' && ch <= '9') ||
|
|
9
|
+
ch === '_');
|
|
10
|
+
}
|
|
11
|
+
function isAttrNameChar(ch) {
|
|
12
|
+
return isWordChar(ch);
|
|
13
|
+
}
|
|
14
|
+
/** Strip HTML tags in O(n) without `<[^>]*>`-style regex. */
|
|
15
|
+
export function stripHtmlTags(text) {
|
|
16
|
+
let out = '';
|
|
17
|
+
for (let i = 0; i < text.length; i++) {
|
|
18
|
+
const ch = text[i];
|
|
19
|
+
if (ch === '<') {
|
|
20
|
+
i++;
|
|
21
|
+
while (i < text.length && text[i] !== '>') {
|
|
22
|
+
i++;
|
|
23
|
+
}
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
out += ch;
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
function skipAttrSpaces(raw, i) {
|
|
31
|
+
while (i < raw.length && raw[i] === ' ') {
|
|
32
|
+
i++;
|
|
33
|
+
}
|
|
34
|
+
return i;
|
|
35
|
+
}
|
|
36
|
+
function readAttrKey(raw, i) {
|
|
37
|
+
const keyStart = i;
|
|
38
|
+
while (i < raw.length && isAttrNameChar(raw[i] ?? '')) {
|
|
39
|
+
i++;
|
|
40
|
+
}
|
|
41
|
+
if (i === keyStart) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return { key: raw.slice(keyStart, i), i };
|
|
45
|
+
}
|
|
46
|
+
function readQuotedAttrValue(raw, i) {
|
|
47
|
+
if (raw[i] !== '"') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
i++;
|
|
51
|
+
const valStart = i;
|
|
52
|
+
while (i < raw.length && raw[i] !== '"') {
|
|
53
|
+
i++;
|
|
54
|
+
}
|
|
55
|
+
const value = raw.slice(valStart, i).trim();
|
|
56
|
+
if (i < raw.length && raw[i] === '"') {
|
|
57
|
+
i++;
|
|
58
|
+
}
|
|
59
|
+
return { value, i };
|
|
60
|
+
}
|
|
61
|
+
/** Parse `key="value"` tokens; only keys in `allowed` are returned. */
|
|
62
|
+
export function parseQuotedAttributes(raw, allowed) {
|
|
63
|
+
const out = {};
|
|
64
|
+
let i = 0;
|
|
65
|
+
while (i < raw.length) {
|
|
66
|
+
i = skipAttrSpaces(raw, i);
|
|
67
|
+
if (i >= raw.length) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
const keyResult = readAttrKey(raw, i);
|
|
71
|
+
if (!keyResult) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
const { key, i: afterKey } = keyResult;
|
|
75
|
+
i = afterKey;
|
|
76
|
+
if (raw[i] !== '=') {
|
|
77
|
+
i++;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
i++;
|
|
81
|
+
const valueResult = readQuotedAttrValue(raw, i);
|
|
82
|
+
if (!valueResult) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
i = valueResult.i;
|
|
86
|
+
if (allowed.has(key)) {
|
|
87
|
+
out[key] = valueResult.value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
export function isSafeLessonId(id) {
|
|
93
|
+
if (!id) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
for (const ch of id) {
|
|
97
|
+
if (!isWordChar(ch) && ch !== '-') {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
/** True when line opens a dynamic block (`:::word`) but may be unclosed. */
|
|
104
|
+
export function startsDynamicBlockLine(trimmed) {
|
|
105
|
+
if (!trimmed.startsWith(':::')) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
let i = 3;
|
|
109
|
+
while (i < trimmed.length && trimmed[i] === ' ') {
|
|
110
|
+
i++;
|
|
111
|
+
}
|
|
112
|
+
return i < trimmed.length && isWordChar(trimmed[i] ?? '');
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Parse a single-line `:::type attr="..." :::` block.
|
|
116
|
+
* Returns null when the line is not a well-formed closed block.
|
|
117
|
+
*/
|
|
118
|
+
export function parseClosedDynamicBlock(trimmed) {
|
|
119
|
+
const line = trimmed;
|
|
120
|
+
if (!line.startsWith(':::')) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const closeAt = line.lastIndexOf(':::');
|
|
124
|
+
if (closeAt < 3) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const inner = line.slice(3, closeAt).trim();
|
|
128
|
+
let i = 0;
|
|
129
|
+
while (i < inner.length && inner[i] === ' ') {
|
|
130
|
+
i++;
|
|
131
|
+
}
|
|
132
|
+
const typeStart = i;
|
|
133
|
+
while (i < inner.length && isWordChar(inner[i] ?? '')) {
|
|
134
|
+
i++;
|
|
135
|
+
}
|
|
136
|
+
if (i === typeStart) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const type = inner.slice(typeStart, i).toLowerCase();
|
|
140
|
+
while (i < inner.length && inner[i] === ' ') {
|
|
141
|
+
i++;
|
|
142
|
+
}
|
|
143
|
+
return { type, attrsRaw: inner.slice(i).trim() };
|
|
144
|
+
}
|
|
145
|
+
export function isNumericRunId(value) {
|
|
146
|
+
if (!value) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
for (const ch of value) {
|
|
150
|
+
if (ch < '0' || ch > '9') {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
/** Heading level 1–3 with required space after hashes; `text` excludes leading # run. */
|
|
157
|
+
export function parseMarkdownHeading(line) {
|
|
158
|
+
if (line.startsWith('### ')) {
|
|
159
|
+
return { level: 3, text: line.slice(4).trimEnd() };
|
|
160
|
+
}
|
|
161
|
+
if (line.startsWith('## ')) {
|
|
162
|
+
return { level: 2, text: line.slice(3).trimEnd() };
|
|
163
|
+
}
|
|
164
|
+
if (line.startsWith('# ')) {
|
|
165
|
+
return { level: 1, text: line.slice(2).trimEnd() };
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
export function isEmptyMarkdownHeading(line) {
|
|
170
|
+
return line === '# ' || line === '## ' || line === '### ';
|
|
171
|
+
}
|
|
172
|
+
export function isH1MarkdownLine(line) {
|
|
173
|
+
return line.startsWith('# ') && line.length > 2 && line[2] !== '#';
|
|
174
|
+
}
|
|
175
|
+
export function isMarkdownHeadingWithTrailingSpace(line) {
|
|
176
|
+
if (!line.startsWith('#')) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
let i = 0;
|
|
180
|
+
while (i < line.length && line[i] === '#') {
|
|
181
|
+
i++;
|
|
182
|
+
}
|
|
183
|
+
return i > 0 && i <= 6 && (line[i] ?? '') === ' ' && line.endsWith(' ');
|
|
184
|
+
}
|
|
185
|
+
export function parseBulletListItem(line) {
|
|
186
|
+
const trimmed = line.trimStart();
|
|
187
|
+
if (trimmed.startsWith('- ')) {
|
|
188
|
+
return trimmed.slice(2).trim();
|
|
189
|
+
}
|
|
190
|
+
if (trimmed.startsWith('* ')) {
|
|
191
|
+
return trimmed.slice(2).trim();
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
export function parseOrderedListItem(line) {
|
|
196
|
+
let i = 0;
|
|
197
|
+
while (i < line.length && line[i] === ' ') {
|
|
198
|
+
i++;
|
|
199
|
+
}
|
|
200
|
+
const numStart = i;
|
|
201
|
+
while (i < line.length) {
|
|
202
|
+
const ch = line[i];
|
|
203
|
+
if (ch === undefined || ch < '0' || ch > '9') {
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
i++;
|
|
207
|
+
}
|
|
208
|
+
if (i === numStart || (line[i] ?? '') !== '.' || (line[i + 1] ?? '') !== ' ') {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
const num = Number.parseInt(line.slice(numStart, i), 10);
|
|
212
|
+
return { num, text: line.slice(i + 2).trim() };
|
|
213
|
+
}
|
|
214
|
+
export function isCodeFenceLine(line) {
|
|
215
|
+
const t = line.trim();
|
|
216
|
+
return t === '```' || (t.startsWith('```') && t.slice(3).trim() === '');
|
|
217
|
+
}
|
|
218
|
+
export function lineHasTrailingWhitespace(line) {
|
|
219
|
+
return line.length > 0 && (line.endsWith(' ') || line.endsWith('\t'));
|
|
220
|
+
}
|
|
221
|
+
function isAllowedLinkUrl(url) {
|
|
222
|
+
const lower = url.trim().toLowerCase();
|
|
223
|
+
return lower.startsWith('https://') || lower.startsWith('http://');
|
|
224
|
+
}
|
|
225
|
+
function tryParseInlineLink(rest) {
|
|
226
|
+
if (!rest.startsWith('[')) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
const closeBracket = rest.indexOf(']');
|
|
230
|
+
if (closeBracket < 1 || rest[closeBracket + 1] !== '(') {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
const closeParen = rest.indexOf(')', closeBracket + 2);
|
|
234
|
+
if (closeParen < 0) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const text = rest.slice(1, closeBracket);
|
|
238
|
+
const url = rest.slice(closeBracket + 2, closeParen).trim();
|
|
239
|
+
return {
|
|
240
|
+
segment: {
|
|
241
|
+
type: 'link',
|
|
242
|
+
text,
|
|
243
|
+
url: isAllowedLinkUrl(url) ? url : '',
|
|
244
|
+
},
|
|
245
|
+
consumed: closeParen + 1,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function tryParseInlineCode(rest) {
|
|
249
|
+
if (!rest.startsWith('`')) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
let run = 1;
|
|
253
|
+
while (run < rest.length && rest[run] === '`') {
|
|
254
|
+
run++;
|
|
255
|
+
}
|
|
256
|
+
const close = rest.indexOf('`'.repeat(run), run);
|
|
257
|
+
if (close < 0) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
segment: { type: 'code', value: rest.slice(run, close) },
|
|
262
|
+
consumed: close + run,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function nextInlineSpecialIndex(rest) {
|
|
266
|
+
const code = rest.indexOf('`');
|
|
267
|
+
const link = rest.indexOf('[');
|
|
268
|
+
if (code >= 0 && (link < 0 || code < link)) {
|
|
269
|
+
return code;
|
|
270
|
+
}
|
|
271
|
+
if (link >= 0) {
|
|
272
|
+
return link;
|
|
273
|
+
}
|
|
274
|
+
return rest.length;
|
|
275
|
+
}
|
|
276
|
+
/** Parse inline `code`, [text](url), and plain text segments. */
|
|
277
|
+
export function parseInlineMarkdown(line) {
|
|
278
|
+
const segments = [];
|
|
279
|
+
let rest = line;
|
|
280
|
+
while (rest.length > 0) {
|
|
281
|
+
const code = tryParseInlineCode(rest);
|
|
282
|
+
if (code) {
|
|
283
|
+
segments.push(code.segment);
|
|
284
|
+
rest = rest.slice(code.consumed);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const link = tryParseInlineLink(rest);
|
|
288
|
+
if (link) {
|
|
289
|
+
segments.push(link.segment);
|
|
290
|
+
rest = rest.slice(link.consumed);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const cut = nextInlineSpecialIndex(rest);
|
|
294
|
+
if (cut > 0) {
|
|
295
|
+
segments.push({ type: 'text', value: rest.slice(0, cut) });
|
|
296
|
+
rest = rest.slice(cut);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
segments.push({ type: 'text', value: rest });
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
return segments;
|
|
303
|
+
}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# learning-core TypeScript
|
|
2
|
+
|
|
3
|
+
This guide documents the current TypeScript candidate. See [current release gates](release-candidate-2026-10-21.md) for publication and adoption status.
|
|
4
|
+
|
|
5
|
+
Version 0.1.1 is the maintenance release candidate prepared on 2026-11-15. Framework-independent Markdown parsing and lesson content validation. No dependency on platform-core or React.
|
|
6
|
+
|
|
7
|
+
Hosts own permissions, HTTP contracts, validation policy, navigation and persistence. React components accept controlled values, feedback and events; they do not fetch data. Form values (including empty numeric input strings) are UI state, not generated HTTP schemas.
|
|
8
|
+
|
|
9
|
+
Run root npm typecheck, tests and build, plus the workspace lint, format:check and pack:dry-run commands. Run scripts/check_npm_artifact.mjs after building. Publishing requires an explicit release request.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# TypeScript release candidate — 2026-10-21
|
|
2
|
+
|
|
3
|
+
`@signalsafe/learning-core@0.1.0` is prepared for first publication. Public npm lookup returned HTTP 404; authenticated private availability and scope permissions still require confirmation before publication.
|
|
4
|
+
|
|
5
|
+
Strict type, lint, format, existing test, build, package dry-run and installed-artifact checks are required. Exact source and artifacts must be approved before publishing. Root workspace manifests are private build orchestration, not distributions.
|
|
6
|
+
|
|
7
|
+
After publication, regenerate consumer locks against the real registry archives, verify one coherent installed dependency graph and rerun actual host integration gates. Host authorization, transport and persistence remain host-owned.
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@signalsafe/learning-core",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"README.md",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"docs"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
"./markdown": {
|
|
15
|
+
"types": "./dist/markdown.d.ts",
|
|
16
|
+
"import": "./dist/markdown.js"
|
|
17
|
+
},
|
|
18
|
+
"./lessons": {
|
|
19
|
+
"types": "./dist/lessonContentValidation.d.ts",
|
|
20
|
+
"import": "./dist/lessonContentValidation.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.json",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"lint": "oxlint --deny-warnings src",
|
|
30
|
+
"format:check": "oxfmt --check .",
|
|
31
|
+
"test": "vitest run --configLoader runner --no-cache",
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
33
|
+
"pack:dry-run": "npm pack --dry-run --ignore-scripts"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
37
|
+
"oxfmt": "0.73.0",
|
|
38
|
+
"oxlint": "1.88.0",
|
|
39
|
+
"typescript": "7.0.2",
|
|
40
|
+
"vitest": "5.0.5"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=22.12.0"
|
|
44
|
+
}
|
|
45
|
+
}
|