shelving 1.221.0 → 1.222.0
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/markup/rule/ordered.d.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
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
|
+
* - List block runs until a blank line that is not followed by another item or an indented continuation line.
|
|
7
|
+
* - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
|
|
6
8
|
* - Sparse lists are not supported.
|
|
7
9
|
*/
|
|
8
10
|
export declare const ORDERED_RULE: import("../MarkupRule.js").MarkupRule;
|
package/markup/rule/ordered.js
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createMarkupRule } from "../MarkupRule.js";
|
|
3
|
-
import { BLOCK_CONTENT_REGEXP, BLOCK_SPACE_REGEXP, createBlockRegExp, LINE_SPACE_REGEXP } from "../util/regexp.js";
|
|
3
|
+
import { BLOCK_CONTENT_REGEXP, BLOCK_SPACE_REGEXP, BLOCK_START_REGEXP, createBlockRegExp, LINE_SPACE_REGEXP } from "../util/regexp.js";
|
|
4
4
|
const _INDENT = /^\t/gm; // Nesting is recognised with tabs only.
|
|
5
5
|
const _NUMBER = "\\d{1,9}[.):]"; // Number for a numbered list, e.g. `1.` or `2)` or `3:` followed by one or more spaces.
|
|
6
6
|
const _ITEM = new RegExp(`(?:^|\n)(${_NUMBER})(?:${LINE_SPACE_REGEXP}+(${BLOCK_CONTENT_REGEXP}))?${BLOCK_SPACE_REGEXP}*(?=\n${_NUMBER}(?:\\s|$)|$)`, "g");
|
|
7
|
+
// End of a list block: the end of the string, or a blank line that is *not* followed by another
|
|
8
|
+
// item or an indented continuation line. A blank line before a new item or a continuation
|
|
9
|
+
// paragraph keeps the list going (a "loose" list); anything else ends the list.
|
|
10
|
+
const _END = `${BLOCK_SPACE_REGEXP}*(?:$|\\n${LINE_SPACE_REGEXP}*\\n(?!${LINE_SPACE_REGEXP}|${_NUMBER}))`;
|
|
11
|
+
// A list is "loose" when it contains a blank line. Loose items are parsed as blocks so their
|
|
12
|
+
// content is wrapped in `<p>` tags instead of rendered inline.
|
|
13
|
+
const _LOOSE = new RegExp(`\\n${LINE_SPACE_REGEXP}*\\n`);
|
|
7
14
|
/**
|
|
8
15
|
* Ordered list.
|
|
9
16
|
* - Line starting with number, followed by `.`, `)` or `:` character, then one or more space characters.
|
|
10
17
|
* - No spaces can appear before the number character.
|
|
11
18
|
* - Second-level list can be created by indenting with `\t` one tab.
|
|
19
|
+
* - List block runs until a blank line that is not followed by another item or an indented continuation line.
|
|
20
|
+
* - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
|
|
12
21
|
* - Sparse lists are not supported.
|
|
13
22
|
*/
|
|
14
|
-
export const ORDERED_RULE = createMarkupRule(createBlockRegExp(`(?<list>${_NUMBER}(?:${LINE_SPACE_REGEXP}+${BLOCK_CONTENT_REGEXP})?)
|
|
23
|
+
export const ORDERED_RULE = createMarkupRule(createBlockRegExp(`(?<list>${_NUMBER}(?:${LINE_SPACE_REGEXP}+${BLOCK_CONTENT_REGEXP})?)`, BLOCK_START_REGEXP, _END), (key, { list }, parser) => _jsx("ol", { children: Array.from(_getOrderedItems(list, parser)) }, key), ["block", "list"]);
|
|
15
24
|
/** Parse a markdown list into a set of items elements. */
|
|
16
25
|
function* _getOrderedItems(list, parser) {
|
|
26
|
+
// Items of a loose list are parsed as blocks so `PARAGRAPH_RULE` wraps their content in `<p>`.
|
|
27
|
+
const context = _LOOSE.test(list) ? "block" : "list";
|
|
17
28
|
let key = 0;
|
|
18
29
|
for (const [_unused, number = "", item = ""] of list.matchAll(_ITEM)) {
|
|
19
|
-
yield (_jsx("li", { value: Number.parseInt(number, 10), children: parser.parse(item.replace(_INDENT, ""),
|
|
30
|
+
yield (_jsx("li", { value: Number.parseInt(number, 10), children: parser.parse(item.replace(_INDENT, ""), context) }, key++));
|
|
20
31
|
}
|
|
21
32
|
}
|
|
@@ -5,7 +5,9 @@ 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
|
-
* - List block is
|
|
8
|
+
* - List block runs until a blank line that is not followed by another item or an indented continuation line.
|
|
9
|
+
* - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
|
|
10
|
+
* - 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.
|
|
9
11
|
* - Sparse lists are not supported.
|
|
10
12
|
*/
|
|
11
13
|
export declare const UNORDERED_RULE: import("../MarkupRule.js").MarkupRule;
|
package/markup/rule/unordered.js
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createMarkupRule } from "../MarkupRule.js";
|
|
3
|
-
import { BLOCK_CONTENT_REGEXP, BLOCK_SPACE_REGEXP, createBlockRegExp, LINE_SPACE_REGEXP } from "../util/regexp.js";
|
|
3
|
+
import { BLOCK_CONTENT_REGEXP, BLOCK_SPACE_REGEXP, BLOCK_START_REGEXP, createBlockRegExp, LINE_SPACE_REGEXP } from "../util/regexp.js";
|
|
4
4
|
const _INDENT = /^\t/gm; // Nesting is recognised with tabs only.
|
|
5
5
|
const _BULLET = "[-*•+]"; // Allowed bullet symbol.
|
|
6
6
|
const _ITEM = new RegExp(`(?:^|\n)${_BULLET}(?:${LINE_SPACE_REGEXP}+(${BLOCK_CONTENT_REGEXP}))?${BLOCK_SPACE_REGEXP}*(?=\n${_BULLET}(?:\\s|$)|$)`, "g");
|
|
7
|
+
// A GitHub-style todo checkbox at the start of an item: `[ ]` (unchecked) or `[x]` (checked,
|
|
8
|
+
// case-insensitive), which must be followed by whitespace or the end of the item.
|
|
9
|
+
const _CHECKBOX = /^\[([ xX])\](?!\S)[^\n\S]*/;
|
|
10
|
+
// End of a list block: the end of the string, or a blank line that is *not* followed by another
|
|
11
|
+
// item or an indented continuation line. A blank line before a new item or a continuation
|
|
12
|
+
// paragraph keeps the list going (a "loose" list); anything else ends the list.
|
|
13
|
+
const _END = `${BLOCK_SPACE_REGEXP}*(?:$|\\n${LINE_SPACE_REGEXP}*\\n(?!${LINE_SPACE_REGEXP}|${_BULLET}))`;
|
|
14
|
+
// A list is "loose" when it contains a blank line. Loose items are parsed as blocks so their
|
|
15
|
+
// content is wrapped in `<p>` tags instead of rendered inline.
|
|
16
|
+
const _LOOSE = new RegExp(`\\n${LINE_SPACE_REGEXP}*\\n`);
|
|
7
17
|
/**
|
|
8
18
|
* Unordered list.
|
|
9
19
|
* - Line starting with `-`, `*`, `•`, or `+` character followed by one or more space characters.
|
|
10
20
|
* - No spaces can appear before the bullet character.
|
|
11
21
|
* - Second-level list can be created by indenting with `\t` one tab.
|
|
12
|
-
* - List block is
|
|
22
|
+
* - List block runs until a blank line that is not followed by another item or an indented continuation line.
|
|
23
|
+
* - A list with blank lines between its items (or before a continuation paragraph) is "loose": its items are wrapped in `<p>` tags.
|
|
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.
|
|
13
25
|
* - Sparse lists are not supported.
|
|
14
26
|
*/
|
|
15
|
-
export const UNORDERED_RULE = createMarkupRule(createBlockRegExp(`(?<list>${_BULLET}(?:${LINE_SPACE_REGEXP}+${BLOCK_CONTENT_REGEXP})?)
|
|
27
|
+
export const UNORDERED_RULE = createMarkupRule(createBlockRegExp(`(?<list>${_BULLET}(?:${LINE_SPACE_REGEXP}+${BLOCK_CONTENT_REGEXP})?)`, BLOCK_START_REGEXP, _END), (key, { list }, parser) => _jsx("ul", { children: Array.from(_getItems(list, parser)) }, key), ["block", "list"]);
|
|
16
28
|
/** Parse a markdown list into a set of items elements. */
|
|
17
29
|
export function* _getItems(list, parser) {
|
|
30
|
+
// Items of a loose list are parsed as blocks so `PARAGRAPH_RULE` wraps their content in `<p>`.
|
|
31
|
+
const context = _LOOSE.test(list) ? "block" : "list";
|
|
18
32
|
let key = 0;
|
|
19
|
-
for (const [_unused,
|
|
20
|
-
|
|
33
|
+
for (const [_unused, raw = ""] of list.matchAll(_ITEM)) {
|
|
34
|
+
const item = raw.replace(_INDENT, "");
|
|
35
|
+
// A todo item renders a checkbox; the `<label>` wrapping the content toggles it on click.
|
|
36
|
+
const checkbox = _CHECKBOX.exec(item);
|
|
37
|
+
if (checkbox) {
|
|
38
|
+
yield (_jsx("li", { children: _jsxs("label", { children: [_jsx("input", { type: "checkbox", defaultChecked: checkbox[1] !== " " }), parser.parse(item.slice(checkbox[0].length), context)] }) }, key++));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
yield _jsx("li", { children: parser.parse(item, context) }, key++);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
21
44
|
}
|