@orkestrel/markdown 0.0.1 → 0.0.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.
@@ -1,4 +1,4 @@
1
- import type { BlockNode, MarkdownDocument, MarkdownHandlers, MarkdownInterface, MarkdownNode, MarkdownRewriteHandler } from './types.js';
1
+ import { BlockNode, MarkdownDocument, MarkdownHandlers, MarkdownInterface, MarkdownNode, MarkdownRewriteHandler } from './types.js';
2
2
  /**
3
3
  * A stateful, parsed markdown document - wraps a typed {@link MarkdownDocument} AST
4
4
  * with the query (`find` / `filter` / `reduce` / iteration), rewrite (`map`), fold, and
@@ -1,5 +1,5 @@
1
- import type { ContractInterface } from '@orkestrel/contract';
2
- import type { CodeBlockNode, CodeSpanNode, MarkdownDocument, MarkdownInterface, TextNode, ThematicBreakNode } from './types.js';
1
+ import { ContractInterface } from '@orkestrel/contract';
2
+ import { CodeBlockNode, CodeSpanNode, MarkdownDocument, MarkdownInterface, TextNode, ThematicBreakNode } from './types.js';
3
3
  /**
4
4
  * Create a stateful markdown handle from a markdown string or an already-parsed
5
5
  * {@link MarkdownDocument} - a typed AST plus the query, rewrite, and fold operations
@@ -1,4 +1,4 @@
1
- import type { EmphasisNode, InlineNode, LinkNode, ListItemParts, MarkdownDocument, MarkdownHandlers, MarkdownNode, MarkdownRewriteHandler, TableAlign } from './types.js';
1
+ import { EmphasisNode, InlineNode, LinkNode, ListItemParts, MarkdownDocument, MarkdownHandlers, MarkdownNode, MarkdownRewriteHandler, TableAlign } from './types.js';
2
2
  /**
3
3
  * Normalize line endings to `\n` and split a markdown document into its lines - CRLF
4
4
  * (`\r\n`) and bare CR (`\r`) both collapse to `\n` first, so a Windows-origin
@@ -7,6 +7,11 @@ import type { EmphasisNode, InlineNode, LinkNode, ListItemParts, MarkdownDocumen
7
7
  *
8
8
  * @param markdown - The raw markdown source
9
9
  * @returns The document's lines, line-terminators stripped
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * splitLines('a\r\nb\nc') // ['a', 'b', 'c']
14
+ * ```
10
15
  */
11
16
  export declare function splitLines(markdown: string): readonly string[];
12
17
  /**
@@ -15,6 +20,11 @@ export declare function splitLines(markdown: string): readonly string[];
15
20
  *
16
21
  * @param line - The line to measure
17
22
  * @returns The number of leading space / tab characters
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * leadingIndent(' text') // 2
27
+ * ```
18
28
  */
19
29
  export declare function leadingIndent(line: string): number;
20
30
  /**
@@ -25,6 +35,11 @@ export declare function leadingIndent(line: string): number;
25
35
  *
26
36
  * @param line - The candidate line
27
37
  * @returns The heading level (1–6) and its raw inline text, or `undefined`
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * extractHeading('## Title') // { level: 2, text: 'Title' }
42
+ * ```
28
43
  */
29
44
  export declare function extractHeading(line: string): {
30
45
  readonly level: number;
@@ -38,6 +53,11 @@ export declare function extractHeading(line: string): {
38
53
  *
39
54
  * @param line - The candidate line
40
55
  * @returns The fence marker run and its language tag, or `undefined`
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * extractFence('```ts') // { marker: '```', lang: 'ts' }
60
+ * ```
41
61
  */
42
62
  export declare function extractFence(line: string): {
43
63
  readonly marker: string;
@@ -51,6 +71,11 @@ export declare function extractFence(line: string): {
51
71
  *
52
72
  * @param line - The candidate line
53
73
  * @returns The list-item parts, or `undefined` when not a list item
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * extractListItem('- item') // { ordered: false, start: 1, content: 'item', indent: 0, marker: 2 }
78
+ * ```
54
79
  */
55
80
  export declare function extractListItem(line: string): ListItemParts | undefined;
56
81
  /**
@@ -59,6 +84,11 @@ export declare function extractListItem(line: string): ListItemParts | undefined
59
84
  *
60
85
  * @param line - A blockquote line (per {@link isQuote})
61
86
  * @returns The line with its leading `>` (and one space) removed
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * stripQuote('> text') // 'text'
91
+ * ```
62
92
  */
63
93
  export declare function stripQuote(line: string): string;
64
94
  /**
@@ -68,6 +98,11 @@ export declare function stripQuote(line: string): string;
68
98
  *
69
99
  * @param row - The raw table row line
70
100
  * @returns The row's cells, in column order
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * splitTableRow('|a|b|') // ['a', 'b']
105
+ * ```
71
106
  */
72
107
  export declare function splitTableRow(row: string): readonly string[];
73
108
  /**
@@ -76,6 +111,11 @@ export declare function splitTableRow(row: string): readonly string[];
76
111
  *
77
112
  * @param delimiter - The table's delimiter row
78
113
  * @returns One alignment per column, in column order
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * tableAlignments('| :--- | ---: |') // ['left', 'right']
118
+ * ```
79
119
  */
80
120
  export declare function tableAlignments(delimiter: string): readonly TableAlign[];
81
121
  /**
@@ -88,6 +128,11 @@ export declare function tableAlignments(delimiter: string): readonly TableAlign[
88
128
  * @param lines - The document's lines
89
129
  * @param index - The line index to test
90
130
  * @returns `true` when the line begins a different block
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * startsBlock(['text', '## Heading'], 1) // true
135
+ * ```
91
136
  */
92
137
  export declare function startsBlock(lines: readonly string[], index: number): boolean;
93
138
  /**
@@ -96,6 +141,11 @@ export declare function startsBlock(lines: readonly string[], index: number): bo
96
141
  *
97
142
  * @param text - The raw text possibly carrying `\x` escapes
98
143
  * @returns The text with escapable `\x` reduced to `x`
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * unescapeText('\\*hi\\*') // '*hi*'
148
+ * ```
99
149
  */
100
150
  export declare function unescapeText(text: string): string;
101
151
  /**
@@ -104,6 +154,12 @@ export declare function unescapeText(text: string): string;
104
154
  *
105
155
  * @param nodes - The inline nodes (possibly with adjacent text runs)
106
156
  * @returns The nodes with consecutive text nodes concatenated
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * coalesceText([{ element: 'text', value: 'a' }, { element: 'text', value: 'b' }])
161
+ * // [{ element: 'text', value: 'ab' }]
162
+ * ```
107
163
  */
108
164
  export declare function coalesceText(nodes: readonly InlineNode[]): readonly InlineNode[];
109
165
  /**
@@ -116,6 +172,11 @@ export declare function coalesceText(nodes: readonly InlineNode[]): readonly Inl
116
172
  * @param start - The index of the opening backtick
117
173
  * @param to - The exclusive end of the scan window
118
174
  * @returns The span text + end index, or `undefined`
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * scanCode('`code`', 0, 6) // { value: 'code', end: 6 }
179
+ * ```
119
180
  */
120
181
  export declare function scanCode(source: string, start: number, to: number): {
121
182
  readonly value: string;
@@ -134,6 +195,12 @@ export declare function scanCode(source: string, start: number, to: number): {
134
195
  * at {@link MAX_DEPTH} the link's text children degrade to literal text instead of
135
196
  * recursing further
136
197
  * @returns The parsed {@link LinkNode} + end index, or `undefined`
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * scanLink('[text](url)', 0, 11)
202
+ * // { node: { element: 'link', href: 'url', children: [...] }, end: 11 }
203
+ * ```
137
204
  */
138
205
  export declare function scanLink(source: string, start: number, to: number, depth?: number): {
139
206
  readonly node: LinkNode;
@@ -153,6 +220,12 @@ export declare function scanLink(source: string, start: number, to: number, dept
153
220
  * at {@link MAX_DEPTH} the emphasis's children degrade to literal text instead of
154
221
  * recursing further
155
222
  * @returns The parsed {@link EmphasisNode} + end index, or `undefined`
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * scanEmphasis('*em*', 0, 4)
227
+ * // { node: { element: 'emphasis', strong: false, children: [...] }, end: 4 }
228
+ * ```
156
229
  */
157
230
  export declare function scanEmphasis(source: string, start: number, to: number, depth?: number): {
158
231
  readonly node: EmphasisNode;
@@ -173,6 +246,11 @@ export declare function scanEmphasis(source: string, start: number, to: number,
173
246
  * it emits as a single literal text node - so pathological nesting (`[[[[…`,
174
247
  * `****…`) cannot exhaust the call stack.
175
248
  * @returns The parsed inline nodes (NOT yet coalesced)
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * scanInline('hi *there*', 0, 10) // [{ element: 'text', value: 'hi ' }, { element: 'emphasis', ... }]
253
+ * ```
176
254
  */
177
255
  export declare function scanInline(source: string, from: number, to: number, depth?: number): readonly InlineNode[];
178
256
  /**
@@ -182,6 +260,11 @@ export declare function scanInline(source: string, from: number, to: number, dep
182
260
  *
183
261
  * @param text - The raw text
184
262
  * @returns The HTML-escaped text
263
+ *
264
+ * @example
265
+ * ```ts
266
+ * escapeHtml('<a>&"\'') // '&lt;a&gt;&amp;&quot;&#39;'
267
+ * ```
185
268
  */
186
269
  export declare function escapeHtml(text: string): string;
187
270
  /**
@@ -197,6 +280,12 @@ export declare function escapeHtml(text: string): string;
197
280
  *
198
281
  * @param href - The raw link destination
199
282
  * @returns A safe, escaped `href` (empty when the scheme is unsafe or protocol-relative)
283
+ *
284
+ * @example
285
+ * ```ts
286
+ * sanitizeUrl('javascript:alert(1)') // ''
287
+ * sanitizeUrl('/path') // '/path'
288
+ * ```
200
289
  */
201
290
  export declare function sanitizeUrl(href: string): string;
202
291
  /**