shelving 1.316.0 → 1.317.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.
@@ -5,8 +5,8 @@
5
5
  - Extends: `FileExtractor`
6
6
 
7
7
  File extractor that parses a TypeScript source file into a tree element.
8
- - Uses the native TypeScript compiler's API (`typescript/unstable/async` — TypeScript 7+) to parse the AST.
9
- - Parsing runs on a shared native compiler server, spawned on demand into a virtual filesystem and closed again after a short idle — callers never manage its lifecycle.
8
+ - Uses the native TypeScript compiler's API (`typescript/async` — TypeScript 7.1+) to parse the AST with `API.createSourceFile()`.
9
+ - Parsing runs on a shared native compiler server, spawned on demand and closed again after a short idle — callers never manage its lifecycle.
10
10
  - Extracts exported, public, non-`_`-prefixed declarations as `tree-documentation` children.
11
11
  - Overloaded declarations sharing a name are merged into a single `tree-documentation` with multiple `signatures`. When a function (or constructor) is overloaded, the implementation declaration (the "base definition") is dropped entirely — only the overload signatures are documented.
12
12
  - A `@param name {Type}` (or `@returns {Type}`) whose `{Type}` is given is canonical: it supersedes the inferred type from the base definition and any overloads. Multiple `@param name` tags for one parameter each emit a row, letting a single parameter be documented as several typed variants.
@@ -9014,8 +9014,8 @@ extract(input: I): O | Promise<O>
9014
9014
  - Extends: `FileExtractor`
9015
9015
 
9016
9016
  File extractor that parses a TypeScript source file into a tree element.
9017
- - Uses the native TypeScript compiler's API (`typescript/unstable/async` — TypeScript 7+) to parse the AST.
9018
- - Parsing runs on a shared native compiler server, spawned on demand into a virtual filesystem and closed again after a short idle — callers never manage its lifecycle.
9017
+ - Uses the native TypeScript compiler's API (`typescript/async` — TypeScript 7.1+) to parse the AST with `API.createSourceFile()`.
9018
+ - Parsing runs on a shared native compiler server, spawned on demand and closed again after a short idle — callers never manage its lifecycle.
9019
9019
  - Extracts exported, public, non-`_`-prefixed declarations as `tree-documentation` children.
9020
9020
  - Overloaded declarations sharing a name are merged into a single `tree-documentation` with multiple `signatures`. When a function (or constructor) is overloaded, the implementation declaration (the "base definition") is dropped entirely — only the overload signatures are documented.
9021
9021
  - A `@param name {Type}` (or `@returns {Type}`) whose `{Type}` is given is canonical: it supersedes the inferred type from the base definition and any overloads. Multiple `@param name` tags for one parameter each emit a row, letting a single parameter be documented as several typed variants.
@@ -10030,7 +10030,7 @@ If the text reaches you straight from a `StringSchema`-validated field it is alr
10030
10030
  - [INLINE_RULE](markup/INLINE_RULE.md): Inline strong, emphasis, insert, delete, highlight.
10031
10031
  - [LINEBREAK_RULE](markup/LINEBREAK_RULE.md): Hard linebreak (<br /> tag).
10032
10032
  - [LINK_RULE](markup/LINK_RULE.md): Markdown-style link.
10033
- - [AUTOLINK_RULE](markup/AUTOLINK_RULE.md): Autolinked URL starts with scheme: (any scheme in MarkupOptions.schemes) and matches an unlimited number of non-space characters.
10033
+ - [AUTOLINK_RULE](markup/AUTOLINK_RULE.md): Autolinked URL starts with scheme: (any scheme in MarkupOptions.schemes) and matches an unlimited number of non-space characters (except < and >).
10034
10034
  - [ORDERED_RULE](markup/ORDERED_RULE.md): Ordered list.
10035
10035
  - [PARAGRAPH_RULE](markup/PARAGRAPH_RULE.md): Paragraph.
10036
10036
  - [SEPARATOR_RULE](markup/SEPARATOR_RULE.md): Separator (horizontal rule / thematic break).
@@ -10658,7 +10658,8 @@ new MarkupParser({ rules: [LINK_RULE] }).parse("[Google Maps](http://google.com/
10658
10658
  - Kind: constant
10659
10659
  - Import: `import { AUTOLINK_RULE } from "shelving/markup";`
10660
10660
 
10661
- Autolinked URL starts with `scheme:` (any scheme in `MarkupOptions.schemes`) and matches an unlimited number of non-space characters.
10661
+ Autolinked URL starts with `scheme:` (any scheme in `MarkupOptions.schemes`) and matches an unlimited number of non-space characters (except `<` and `>`).
10662
+ - URL can be wrapped in `<>` angle brackets (the standard Markdown autolink syntax), e.g. `<http://google.com/maps>`. The brackets are not part of the link.
10662
10663
  - If followed by space and then text in `()` round or `[]` square brackets that will be used as the title, e.g. `http://google.com/maps (Google Maps)` or `http://google.com/maps [Google Maps]` (this syntax is from Todoist and maybe other things too).
10663
10664
  - If no title is specified a cleaned up version of the URL will be used, e.g. `google.com/maps`
10664
10665
  - If link is not valid (using `new URL(url)` then unparsed text will be returned.
@@ -10682,6 +10683,7 @@ Ordered list.
10682
10683
  - Line starting with number, followed by `.`, `)` or `:` character, then one or more space characters.
10683
10684
  - No spaces can appear before the number character.
10684
10685
  - Second-level list can be created by indenting with `\t` one tab.
10686
+ - Continuation lines can also be indented with spaces to the width of the number and its spaces, e.g. three spaces after `1. `, so a fenced code block can go inside an item.
10685
10687
  - List block runs until a blank line that is not followed by another item or an indented continuation line.
10686
10688
  - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
10687
10689
  - Sparse lists are not supported.
@@ -10764,6 +10766,7 @@ Unordered list.
10764
10766
  - Line starting with `-`, `*`, `•`, or `+` character followed by one or more space characters.
10765
10767
  - No spaces can appear before the bullet character.
10766
10768
  - Second-level list can be created by indenting with `\t` one tab.
10769
+ - Continuation lines can also be indented with spaces to the width of the bullet and its spaces, e.g. two spaces after `- `, so a fenced code block can go inside an item.
10767
10770
  - List block runs until a blank line that is not followed by another item or an indented continuation line.
10768
10771
  - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
10769
10772
  - An item starting with `[ ]` or `[x]` (case-insensitive) is a todo item: a checkbox `<input>` plus the content wrapped in a `<label>` so clicking it toggles the checkbox.
@@ -3,7 +3,8 @@
3
3
  - Kind: constant
4
4
  - Import: `import { AUTOLINK_RULE } from "shelving/markup";`
5
5
 
6
- Autolinked URL starts with `scheme:` (any scheme in `MarkupOptions.schemes`) and matches an unlimited number of non-space characters.
6
+ Autolinked URL starts with `scheme:` (any scheme in `MarkupOptions.schemes`) and matches an unlimited number of non-space characters (except `<` and `>`).
7
+ - URL can be wrapped in `<>` angle brackets (the standard Markdown autolink syntax), e.g. `<http://google.com/maps>`. The brackets are not part of the link.
7
8
  - If followed by space and then text in `()` round or `[]` square brackets that will be used as the title, e.g. `http://google.com/maps (Google Maps)` or `http://google.com/maps [Google Maps]` (this syntax is from Todoist and maybe other things too).
8
9
  - If no title is specified a cleaned up version of the URL will be used, e.g. `google.com/maps`
9
10
  - If link is not valid (using `new URL(url)` then unparsed text will be returned.
@@ -7,6 +7,7 @@ Ordered list.
7
7
  - Line starting with number, followed by `.`, `)` or `:` character, then one or more space characters.
8
8
  - No spaces can appear before the number character.
9
9
  - Second-level list can be created by indenting with `\t` one tab.
10
+ - Continuation lines can also be indented with spaces to the width of the number and its spaces, e.g. three spaces after `1. `, so a fenced code block can go inside an item.
10
11
  - List block runs until a blank line that is not followed by another item or an indented continuation line.
11
12
  - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
12
13
  - Sparse lists are not supported.
@@ -7,6 +7,7 @@ Unordered list.
7
7
  - Line starting with `-`, `*`, `•`, or `+` character followed by one or more space characters.
8
8
  - No spaces can appear before the bullet character.
9
9
  - Second-level list can be created by indenting with `\t` one tab.
10
+ - Continuation lines can also be indented with spaces to the width of the bullet and its spaces, e.g. two spaces after `- `, so a fenced code block can go inside an item.
10
11
  - List block runs until a blank line that is not followed by another item or an indented continuation line.
11
12
  - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
12
13
  - An item starting with `[ ]` or `[x]` (case-insensitive) is a todo item: a checkbox `<input>` plus the content wrapped in a `<label>` so clicking it toggles the checkbox.
package/docs/markup.md CHANGED
@@ -168,7 +168,7 @@ If the text reaches you straight from a `StringSchema`-validated field it is alr
168
168
  - [INLINE_RULE](markup/INLINE_RULE.md): Inline strong, emphasis, insert, delete, highlight.
169
169
  - [LINEBREAK_RULE](markup/LINEBREAK_RULE.md): Hard linebreak (<br /> tag).
170
170
  - [LINK_RULE](markup/LINK_RULE.md): Markdown-style link.
171
- - [AUTOLINK_RULE](markup/AUTOLINK_RULE.md): Autolinked URL starts with scheme: (any scheme in MarkupOptions.schemes) and matches an unlimited number of non-space characters.
171
+ - [AUTOLINK_RULE](markup/AUTOLINK_RULE.md): Autolinked URL starts with scheme: (any scheme in MarkupOptions.schemes) and matches an unlimited number of non-space characters (except < and >).
172
172
  - [ORDERED_RULE](markup/ORDERED_RULE.md): Ordered list.
173
173
  - [PARAGRAPH_RULE](markup/PARAGRAPH_RULE.md): Paragraph.
174
174
  - [SEPARATOR_RULE](markup/SEPARATOR_RULE.md): Separator (horizontal rule / thematic break).
@@ -2,8 +2,8 @@ import type { TreeElementProps } from "../util/tree.js";
2
2
  import { FileExtractor } from "./FileExtractor.js";
3
3
  /**
4
4
  * File extractor that parses a TypeScript source file into a tree element.
5
- * - Uses the native TypeScript compiler's API (`typescript/unstable/async` — TypeScript 7+) to parse the AST.
6
- * - Parsing runs on a shared native compiler server, spawned on demand into a virtual filesystem and closed again after a short idle — callers never manage its lifecycle.
5
+ * - Uses the native TypeScript compiler's API (`typescript/async` — TypeScript 7.1+) to parse the AST with `API.createSourceFile()`.
6
+ * - Parsing runs on a shared native compiler server, spawned on demand and closed again after a short idle — callers never manage its lifecycle.
7
7
  * - Extracts exported, public, non-`_`-prefixed declarations as `tree-documentation` children.
8
8
  * - Overloaded declarations sharing a name are merged into a single `tree-documentation` with multiple `signatures`. When a function (or constructor) is overloaded, the implementation declaration (the "base definition") is dropped entirely — only the overload signatures are documented.
9
9
  * - A `@param name {Type}` (or `@returns {Type}`) whose `{Type}` is given is canonical: it supersedes the inferred type from the base definition and any overloads. Multiple `@param name` tags for one parameter each emit a row, letting a single parameter be documented as several typed variants.
@@ -1,13 +1,13 @@
1
- import { getTextOfJSDocComment, isArrayBindingPattern, isBindingElement, isClassDeclaration, isConstructorDeclaration, isEnumDeclaration, isFunctionDeclaration, isGetAccessorDeclaration, isIdentifier, isInterfaceDeclaration, isJSDoc, isJSDocParameterTag, isJSDocReturnTag, isJSDocSeeTag, isJSDocThrowsTag, isJSDocTypeExpression, isMethodDeclaration, isMethodSignatureDeclaration, isObjectBindingPattern, isPropertyDeclaration, isPropertySignatureDeclaration, isSetAccessorDeclaration, isTypeAliasDeclaration, isTypeLiteralNode, isTypeReferenceNode, isVariableStatement, SyntaxKind, } from "typescript/unstable/ast";
2
- import { API } from "typescript/unstable/async";
1
+ import { getTextOfJSDocComment, isArrayBindingPattern, isBindingElement, isClassDeclaration, isConstructorDeclaration, isEnumDeclaration, isFunctionDeclaration, isGetAccessorDeclaration, isIdentifier, isInterfaceDeclaration, isJSDoc, isJSDocParameterTag, isJSDocReturnTag, isJSDocSeeTag, isJSDocThrowsTag, isJSDocTypeExpression, isMethodDeclaration, isMethodSignatureDeclaration, isObjectBindingPattern, isPropertyDeclaration, isPropertySignatureDeclaration, isSetAccessorDeclaration, isTypeAliasDeclaration, isTypeLiteralNode, isTypeReferenceNode, isVariableStatement, SyntaxKind, } from "typescript/ast";
2
+ import { API } from "typescript/async";
3
3
  import { ValueError } from "../error/ValueError.js";
4
4
  import { BLACKHOLE } from "../util/function.js";
5
5
  import { FileExtractor } from "./FileExtractor.js";
6
6
  import { extractMarkdownProps } from "./MarkupExtractor.js";
7
7
  /**
8
8
  * File extractor that parses a TypeScript source file into a tree element.
9
- * - Uses the native TypeScript compiler's API (`typescript/unstable/async` — TypeScript 7+) to parse the AST.
10
- * - Parsing runs on a shared native compiler server, spawned on demand into a virtual filesystem and closed again after a short idle — callers never manage its lifecycle.
9
+ * - Uses the native TypeScript compiler's API (`typescript/async` — TypeScript 7.1+) to parse the AST with `API.createSourceFile()`.
10
+ * - Parsing runs on a shared native compiler server, spawned on demand and closed again after a short idle — callers never manage its lifecycle.
11
11
  * - Extracts exported, public, non-`_`-prefixed declarations as `tree-documentation` children.
12
12
  * - Overloaded declarations sharing a name are merged into a single `tree-documentation` with multiple `signatures`. When a function (or constructor) is overloaded, the implementation declaration (the "base definition") is dropped entirely — only the overload signatures are documented.
13
13
  * - A `@param name {Type}` (or `@returns {Type}`) whose `{Type}` is given is canonical: it supersedes the inferred type from the base definition and any overloads. Multiple `@param name` tags for one parameter each emit a row, letting a single parameter be documented as several typed variants.
@@ -55,93 +55,56 @@ export class TypescriptExtractor extends FileExtractor {
55
55
  }
56
56
  }
57
57
  // Constants.
58
- const _DIR = "/shelving-typescript-extractor";
59
- const _TSCONFIG_PATH = `${_DIR}/tsconfig.json`;
60
- const _TSCONFIG_JSON = JSON.stringify({ compilerOptions: { noEmit: true }, include: ["**/*.ts"] });
61
58
  const _IDLE_CLOSE_MS = 500;
62
- let _server;
63
- let _queue = Promise.resolve();
59
+ let _api;
64
60
  let _timer;
61
+ let _pending = 0;
65
62
  let _count = 0;
66
- let _previous;
67
- /** Is a path inside the virtual directory the compiler server is rooted in? */
68
- function _isVirtual(path) {
69
- return path === _DIR || path.startsWith(`${_DIR}/`);
70
- }
71
- /** Get the shared compiler server, spawning it on demand with a virtual filesystem rooted at `_DIR`. */
72
- function _getServer() {
73
- if (_server)
74
- return _server;
75
- const files = new Map([[_TSCONFIG_PATH, _TSCONFIG_JSON]]);
76
- // Paths outside the virtual directory return `undefined` so the server falls back to the real filesystem (e.g. bundled libs).
77
- const fs = {
78
- fileExists: f => (_isVirtual(f) ? files.has(f) : undefined),
79
- readFile: f => (_isVirtual(f) ? (files.get(f) ?? null) : undefined),
80
- directoryExists: d => (d === _DIR ? true : _isVirtual(d) ? false : undefined),
81
- getAccessibleEntries: d => d === _DIR
82
- ? { files: Array.from(files.keys(), f => f.slice(_DIR.length + 1)), directories: [] }
83
- : _isVirtual(d)
84
- ? { files: [], directories: [] }
85
- : undefined,
86
- realpath: p => (_isVirtual(p) ? p : undefined),
87
- };
88
- _server = { api: new API({ cwd: _DIR, fs }), files };
89
- return _server;
63
+ /** Get the shared compiler server, and spawn it if it does not exist. */
64
+ function _getAPI() {
65
+ if (_timer)
66
+ clearTimeout(_timer);
67
+ _timer = undefined;
68
+ _api ??= new API();
69
+ return _api;
90
70
  }
91
71
  /** Close the shared compiler server after a short idle, so the process can exit without callers managing the lifecycle. */
92
- async function _scheduleClose() {
72
+ function _scheduleClose() {
93
73
  if (_timer)
94
74
  clearTimeout(_timer);
95
75
  _timer = setTimeout(() => {
96
- const server = _server;
97
- _server = undefined;
98
- _previous = undefined;
76
+ const api = _api;
77
+ _api = undefined;
99
78
  _timer = undefined;
100
- try {
101
- void server?.api.close();
102
- }
103
- catch {
104
- // Closing can reject in-flight bookkeeping requests — harmless on shutdown.
105
- }
79
+ api?.close().catch(BLACKHOLE); // Closing can reject in-flight bookkeeping requests — harmless on shutdown.
106
80
  }, _IDLE_CLOSE_MS);
107
81
  }
108
82
  /**
109
83
  * Parse TypeScript source text into a `SourceFile` via the shared native compiler server.
110
- * - Each call writes the text as a fresh virtual file, snapshots the project, and materialises the file's AST.
111
- * - Calls are serialised through a queue so concurrent extractions don't interleave snapshot updates.
84
+ * - Uses `API.createSourceFile()` (TypeScript 7.1+), which parses one file without a project, a program, or a filesystem.
85
+ * - The server closes after a short idle when no parse is in progress.
112
86
  *
113
87
  * @throws `ValueError` If the server fails to produce a source file for the text.
114
88
  */
115
- function _parseSourceFile(text) {
116
- const task = async () => {
117
- if (_timer)
118
- clearTimeout(_timer);
119
- const { api, files } = _getServer();
120
- const path = `${_DIR}/${_count++}.ts`;
121
- files.set(path, text);
122
- // Drop the previous parse's file so the virtual project stays a single file (keeps snapshots cheap).
123
- const deleted = _previous;
124
- if (deleted)
125
- files.delete(deleted);
126
- _previous = path;
127
- const snapshot = await api.updateSnapshot({
128
- openProjects: [_TSCONFIG_PATH],
129
- fileChanges: { created: [path], ...(deleted ? { deleted: [deleted] } : {}) },
130
- });
89
+ async function _parseSourceFile(text) {
90
+ const api = _getAPI();
91
+ _pending++;
92
+ try {
93
+ const retained = await api.createSourceFile(`/${_count++}.ts`, text);
131
94
  try {
132
- const source = await snapshot.getProject(_TSCONFIG_PATH)?.program.getSourceFile(path);
95
+ const source = retained.sourceFile;
133
96
  if (!source)
134
97
  throw new ValueError("Unable to parse TypeScript source", { received: text });
135
98
  return source;
136
99
  }
137
100
  finally {
138
- await snapshot.dispose();
139
- await _scheduleClose();
101
+ await retained.dispose();
140
102
  }
141
- };
142
- const result = _queue.then(task, task);
143
- _queue = result.catch(BLACKHOLE);
144
- return result;
103
+ }
104
+ finally {
105
+ if (--_pending === 0)
106
+ _scheduleClose();
107
+ }
145
108
  }
146
109
  /** Read a node's modifiers (excluding decorators), or `undefined` when it has none. */
147
110
  function _getModifiers(node) {
@@ -11,7 +11,8 @@
11
11
  */
12
12
  export declare const LINK_RULE: import("../MarkupRule.js").MarkupRule;
13
13
  /**
14
- * Autolinked URL starts with `scheme:` (any scheme in `MarkupOptions.schemes`) and matches an unlimited number of non-space characters.
14
+ * Autolinked URL starts with `scheme:` (any scheme in `MarkupOptions.schemes`) and matches an unlimited number of non-space characters (except `<` and `>`).
15
+ * - URL can be wrapped in `<>` angle brackets (the standard Markdown autolink syntax), e.g. `<http://google.com/maps>`. The brackets are not part of the link.
15
16
  * - If followed by space and then text in `()` round or `[]` square brackets that will be used as the title, e.g. `http://google.com/maps (Google Maps)` or `http://google.com/maps [Google Maps]` (this syntax is from Todoist and maybe other things too).
16
17
  * - If no title is specified a cleaned up version of the URL will be used, e.g. `google.com/maps`
17
18
  * - If link is not valid (using `new URL(url)` then unparsed text will be returned.
@@ -20,8 +20,13 @@ function _renderLink(key, { title, href }, parser) {
20
20
  */
21
21
  export const LINK_RULE = createMarkupRule(getRegExp(/\[(?<title>[^\]\n]*?)\]\((?<href>[^)\n]*?)\)/), //
22
22
  _renderLink, ["inline", "list"]);
23
+ /** Render an autolink from whichever of its two URL forms matched. */
24
+ function _renderAutolink(key, { angled, href = "", ...data }, parser) {
25
+ return _renderLink(key, { ...data, href: angled ?? href }, parser);
26
+ }
23
27
  /**
24
- * Autolinked URL starts with `scheme:` (any scheme in `MarkupOptions.schemes`) and matches an unlimited number of non-space characters.
28
+ * Autolinked URL starts with `scheme:` (any scheme in `MarkupOptions.schemes`) and matches an unlimited number of non-space characters (except `<` and `>`).
29
+ * - URL can be wrapped in `<>` angle brackets (the standard Markdown autolink syntax), e.g. `<http://google.com/maps>`. The brackets are not part of the link.
25
30
  * - If followed by space and then text in `()` round or `[]` square brackets that will be used as the title, e.g. `http://google.com/maps (Google Maps)` or `http://google.com/maps [Google Maps]` (this syntax is from Todoist and maybe other things too).
26
31
  * - If no title is specified a cleaned up version of the URL will be used, e.g. `google.com/maps`
27
32
  * - If link is not valid (using `new URL(url)` then unparsed text will be returned.
@@ -32,5 +37,5 @@ _renderLink, ["inline", "list"]);
32
37
  */
33
38
  export const AUTOLINK_RULE = createMarkupRule(
34
39
  // Scheme length is bounded (`{3,64}?`) so a long run of letters with no `:` can't force O(n²) backtracking.
35
- getRegExp(/(?<href>[a-z]{3,64}?:\S+)(?: +(?:\((?<title>[^)\n]*?)\)))?/), //
36
- _renderLink, ["inline", "list"]);
40
+ getRegExp(/(?:<(?<angled>[a-z]{3,64}?:[^\s<>]+)>|(?<href>[a-z]{3,64}?:[^\s<>]+))(?: +(?:\((?<title>[^)\n]*?)\)))?/), //
41
+ _renderAutolink, ["inline", "list"]);
@@ -3,6 +3,7 @@
3
3
  * - Line starting with number, followed by `.`, `)` or `:` character, then one or more space characters.
4
4
  * - No spaces can appear before the number character.
5
5
  * - Second-level list can be created by indenting with `\t` one tab.
6
+ * - Continuation lines can also be indented with spaces to the width of the number and its spaces, e.g. three spaces after `1. `, so a fenced code block can go inside an item.
6
7
  * - List block runs until a blank line that is not followed by another item or an indented continuation line.
7
8
  * - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
8
9
  * - Sparse lists are not supported.
@@ -1,9 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createMarkupRule } from "../MarkupRule.js";
3
3
  import { BLOCK_CONTENT_REGEXP, BLOCK_SPACE_REGEXP, BLOCK_START_REGEXP, createBlockRegExp, LINE_SPACE_REGEXP } from "../util/regexp.js";
4
- const _INDENT = /^\t/gm; // Nesting is recognised with tabs only.
5
4
  const _NUMBER = "\\d{1,9}[.):]"; // Number for a numbered list, e.g. `1.` or `2)` or `3:` followed by one or more spaces.
6
- const _ITEM = new RegExp(`(?:^|\n)(${_NUMBER})(?:${LINE_SPACE_REGEXP}+(${BLOCK_CONTENT_REGEXP}))?${BLOCK_SPACE_REGEXP}*(?=\n${_NUMBER}(?:\\s|$)|$)`, "g");
5
+ const _ITEM = new RegExp(`(?:^|\n)(${_NUMBER})(?:(${LINE_SPACE_REGEXP}+)(${BLOCK_CONTENT_REGEXP}))?${BLOCK_SPACE_REGEXP}*(?=\n${_NUMBER}(?:\\s|$)|$)`, "g");
7
6
  // End of a list block: the end of the string, or a blank line that is *not* followed by another
8
7
  // item or an indented continuation line. A blank line before a new item or a continuation
9
8
  // paragraph keeps the list going (a "loose" list); anything else ends the list.
@@ -16,6 +15,7 @@ const _LOOSE = new RegExp(`\\n${LINE_SPACE_REGEXP}*\\n`);
16
15
  * - Line starting with number, followed by `.`, `)` or `:` character, then one or more space characters.
17
16
  * - No spaces can appear before the number character.
18
17
  * - Second-level list can be created by indenting with `\t` one tab.
18
+ * - Continuation lines can also be indented with spaces to the width of the number and its spaces, e.g. three spaces after `1. `, so a fenced code block can go inside an item.
19
19
  * - List block runs until a blank line that is not followed by another item or an indented continuation line.
20
20
  * - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
21
21
  * - Sparse lists are not supported.
@@ -29,7 +29,15 @@ function* _getOrderedItems(list, parser) {
29
29
  // Items of a loose list are parsed as blocks so `PARAGRAPH_RULE` wraps their content in `<p>`.
30
30
  const context = _LOOSE.test(list) ? "block" : "list";
31
31
  let key = 0;
32
- for (const [_unused, number = "", item = ""] of list.matchAll(_ITEM)) {
33
- yield (_jsx("li", { value: Number.parseInt(number, 10), children: parser.parse(item.replace(_INDENT, ""), context) }, key++));
32
+ for (const [_unused, number = "", space = "", item = ""] of list.matchAll(_ITEM)) {
33
+ yield (_jsx("li", { value: Number.parseInt(number, 10), children: parser.parse(_unindent(item, number.length + space.length), context) }, key++));
34
34
  }
35
35
  }
36
+ /**
37
+ * Remove one level of indent from each continuation line of a list item.
38
+ * - One tab is one level (used for nested lists).
39
+ * - Up to `width` spaces is one level, where `width` is the width of the item's marker plus its spaces (as in standard Markdown).
40
+ */
41
+ function _unindent(item, width) {
42
+ return item.replace(new RegExp(`^(?:\\t| {1,${width}})`, "gm"), "");
43
+ }
@@ -5,6 +5,7 @@ import type { MarkupParser } from "../MarkupParser.js";
5
5
  * - Line starting with `-`, `*`, `•`, or `+` character followed by one or more space characters.
6
6
  * - No spaces can appear before the bullet character.
7
7
  * - Second-level list can be created by indenting with `\t` one tab.
8
+ * - Continuation lines can also be indented with spaces to the width of the bullet and its spaces, e.g. two spaces after `- `, so a fenced code block can go inside an item.
8
9
  * - List block runs until a blank line that is not followed by another item or an indented continuation line.
9
10
  * - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
10
11
  * - An item starting with `[ ]` or `[x]` (case-insensitive) is a todo item: a checkbox `<input>` plus the content wrapped in a `<label>` so clicking it toggles the checkbox.
@@ -1,9 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { createMarkupRule } from "../MarkupRule.js";
3
3
  import { BLOCK_CONTENT_REGEXP, BLOCK_SPACE_REGEXP, BLOCK_START_REGEXP, createBlockRegExp, LINE_SPACE_REGEXP } from "../util/regexp.js";
4
- const _INDENT = /^\t/gm; // Nesting is recognised with tabs only.
5
4
  const _BULLET = "[-*•+]"; // Allowed bullet symbol.
6
- const _ITEM = new RegExp(`(?:^|\n)${_BULLET}(?:${LINE_SPACE_REGEXP}+(${BLOCK_CONTENT_REGEXP}))?${BLOCK_SPACE_REGEXP}*(?=\n${_BULLET}(?:\\s|$)|$)`, "g");
5
+ const _ITEM = new RegExp(`(?:^|\n)${_BULLET}(?:(${LINE_SPACE_REGEXP}+)(${BLOCK_CONTENT_REGEXP}))?${BLOCK_SPACE_REGEXP}*(?=\n${_BULLET}(?:\\s|$)|$)`, "g");
7
6
  // A GitHub-style todo checkbox at the start of an item: `[ ]` (unchecked) or `[x]` (checked,
8
7
  // case-insensitive), which must be followed by whitespace or the end of the item.
9
8
  const _CHECKBOX = /^\[([ xX])\](?!\S)[^\n\S]*/;
@@ -19,6 +18,7 @@ const _LOOSE = new RegExp(`\\n${LINE_SPACE_REGEXP}*\\n`);
19
18
  * - Line starting with `-`, `*`, `•`, or `+` character followed by one or more space characters.
20
19
  * - No spaces can appear before the bullet character.
21
20
  * - Second-level list can be created by indenting with `\t` one tab.
21
+ * - Continuation lines can also be indented with spaces to the width of the bullet and its spaces, e.g. two spaces after `- `, so a fenced code block can go inside an item.
22
22
  * - List block runs until a blank line that is not followed by another item or an indented continuation line.
23
23
  * - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
24
24
  * - An item starting with `[ ]` or `[x]` (case-insensitive) is a todo item: a checkbox `<input>` plus the content wrapped in a `<label>` so clicking it toggles the checkbox.
@@ -33,8 +33,8 @@ export function* _getItems(list, parser) {
33
33
  // Items of a loose list are parsed as blocks so `PARAGRAPH_RULE` wraps their content in `<p>`.
34
34
  const context = _LOOSE.test(list) ? "block" : "list";
35
35
  let key = 0;
36
- for (const [_unused, raw = ""] of list.matchAll(_ITEM)) {
37
- const item = raw.replace(_INDENT, "");
36
+ for (const [_unused, space = "", raw = ""] of list.matchAll(_ITEM)) {
37
+ const item = _unindent(raw, 1 + space.length);
38
38
  // A todo item renders a checkbox; the `<label>` wrapping the content toggles it on click.
39
39
  const checkbox = _CHECKBOX.exec(item);
40
40
  if (checkbox) {
@@ -45,3 +45,11 @@ export function* _getItems(list, parser) {
45
45
  }
46
46
  }
47
47
  }
48
+ /**
49
+ * Remove one level of indent from each continuation line of a list item.
50
+ * - One tab is one level (used for nested lists).
51
+ * - Up to `width` spaces is one level, where `width` is the width of the item's marker plus its spaces (as in standard Markdown).
52
+ */
53
+ function _unindent(item, width) {
54
+ return item.replace(new RegExp(`^(?:\\t| {1,${width}})`, "gm"), "");
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.316.0",
3
+ "version": "1.317.1",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "@types/react-dom": "^19.3.0",
17
17
  "stylelint": "^17.16.0",
18
18
  "stylelint-config-standard": "^40.0.0",
19
- "typescript": "^7.0.2"
19
+ "typescript": "7.1.0-beta"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@heroicons/react": ">=2.0.0"
package/test/basics.d.ts CHANGED
@@ -14,10 +14,10 @@ export declare const BASIC_SCHEMA: import("../schema/DataSchema.js").DataSchema<
14
14
  odd: boolean;
15
15
  even: boolean;
16
16
  sub: {
17
- str: /*elided*/ any;
18
- num: /*elided*/ any;
19
- odd: /*elided*/ any;
20
- even: /*elided*/ any;
17
+ str: string;
18
+ num: number;
19
+ odd: boolean;
20
+ even: boolean;
21
21
  };
22
22
  }>;
23
23
  /**
@@ -111,9 +111,9 @@ export declare const BASICS_COLLECTION: Collection<"basics", string, {
111
111
  odd: boolean;
112
112
  even: boolean;
113
113
  sub: {
114
- str: /*elided*/ any;
115
- num: /*elided*/ any;
116
- odd: /*elided*/ any;
117
- even: /*elided*/ any;
114
+ str: string;
115
+ num: number;
116
+ odd: boolean;
117
+ even: boolean;
118
118
  };
119
119
  }>;
package/test/people.d.ts CHANGED
@@ -8,8 +8,8 @@ import type { ValidatorType } from "../util/validate.js";
8
8
  */
9
9
  export declare const PERSON_SCHEMA: import("../schema/DataSchema.js").DataSchema<{
10
10
  name: {
11
- first: /*elided*/ any;
12
- last: /*elided*/ any;
11
+ first: string;
12
+ last: string;
13
13
  };
14
14
  birthday: string | null;
15
15
  }>;
@@ -68,8 +68,8 @@ export declare const people: ReadonlyArray<PersonItem>;
68
68
  */
69
69
  export declare const PEOPLE_COLLECTION: Collection<"people", string, {
70
70
  name: {
71
- first: /*elided*/ any;
72
- last: /*elided*/ any;
71
+ first: string;
72
+ last: string;
73
73
  };
74
74
  birthday: string | null;
75
75
  }>;
@@ -5,7 +5,7 @@ import type { TreeElements } from "../../util/tree.js";
5
5
  *
6
6
  * @see https://shelving.cc/ui/TreeCardMapping
7
7
  */
8
- export declare const TreeCardMapping: import("react").FunctionComponent<import("../misc/Mapper.js").MappingProps>, TreeCardMapper: import("react").FunctionComponent<import("../misc/Mapper.js").MapperProps>;
8
+ export declare const [TreeCardMapping, TreeCardMapper]: [Mapping: import("react").FunctionComponent<import("../misc/Mapper.js").MappingProps>, Mapper: import("react").FunctionComponent<import("../misc/Mapper.js").MapperProps>];
9
9
  /**
10
10
  * Props for the `TreeCards` component — the tree elements to render as cards.
11
11
  *
@@ -29,7 +29,7 @@ export declare function TreeMenuItem({ path, name, title, children }: TreeElemen
29
29
  *
30
30
  * @see https://shelving.cc/ui/TreeMenuMapping
31
31
  */
32
- export declare const TreeMenuMapping: import("react").FunctionComponent<import("../misc/Mapper.js").MappingProps>, TreeMenuMapper: import("react").FunctionComponent<import("../misc/Mapper.js").MapperProps>;
32
+ export declare const [TreeMenuMapping, TreeMenuMapper]: [Mapping: import("react").FunctionComponent<import("../misc/Mapper.js").MappingProps>, Mapper: import("react").FunctionComponent<import("../misc/Mapper.js").MapperProps>];
33
33
  /**
34
34
  * Props for the `TreeMenu` component — the root tree element plus its URL path.
35
35
  *
@@ -5,7 +5,7 @@ import type { PossibleMeta } from "../util/index.js";
5
5
  *
6
6
  * @see https://shelving.cc/ui/TreeRouterMapping
7
7
  */
8
- export declare const TreeRouterMapping: import("react").FunctionComponent<import("../misc/Mapper.js").MappingProps>, TreeRouterMapper: import("react").FunctionComponent<import("../misc/Mapper.js").MapperProps>;
8
+ export declare const [TreeRouterMapping, TreeRouterMapper]: [Mapping: import("react").FunctionComponent<import("../misc/Mapper.js").MappingProps>, Mapper: import("react").FunctionComponent<import("../misc/Mapper.js").MapperProps>];
9
9
  /**
10
10
  * Props for the `TreeRouter` component — the tree to route plus an optional fallback and app meta.
11
11
  *