shelving 1.266.0 → 1.267.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.
@@ -3,6 +3,7 @@
3
3
  * - `#` 1-6 hashes, then one or more spaces, then the title.
4
4
  * - `#` must be the first character on the line.
5
5
  * - Markdown's underline syntax is not supported (for simplification).
6
+ * - Each heading gets a `getSlug()` `id` derived from its text, so same-page `#anchor` links resolve to it (e.g. `## React integration` becomes `id="react-integration"`). An all-punctuation heading that slugs to nothing gets no `id`.
6
7
  *
7
8
  * @example new MarkupParser({ rules: [HEADING_RULE] }).parse("# Title")
8
9
  * @see https://shelving.cc/markup/HEADING_RULE
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { getSlug } from "../../util/string.js";
2
3
  import { createMarkupRule } from "../MarkupRule.js";
3
4
  import { createLineRegExp, LINE_CONTENT_REGEXP, LINE_SPACE_REGEXP } from "../util/regexp.js";
4
5
  /**
@@ -6,6 +7,7 @@ import { createLineRegExp, LINE_CONTENT_REGEXP, LINE_SPACE_REGEXP } from "../uti
6
7
  * - `#` 1-6 hashes, then one or more spaces, then the title.
7
8
  * - `#` must be the first character on the line.
8
9
  * - Markdown's underline syntax is not supported (for simplification).
10
+ * - Each heading gets a `getSlug()` `id` derived from its text, so same-page `#anchor` links resolve to it (e.g. `## React integration` becomes `id="react-integration"`). An all-punctuation heading that slugs to nothing gets no `id`.
9
11
  *
10
12
  * @example new MarkupParser({ rules: [HEADING_RULE] }).parse("# Title")
11
13
  * @see https://shelving.cc/markup/HEADING_RULE
@@ -13,5 +15,7 @@ import { createLineRegExp, LINE_CONTENT_REGEXP, LINE_SPACE_REGEXP } from "../uti
13
15
  export const HEADING_RULE = createMarkupRule(createLineRegExp(`(?<prefix>#{1,6})(?:${LINE_SPACE_REGEXP}+(?<heading>${LINE_CONTENT_REGEXP}))?`), (key, { prefix, heading = "" }, parser) => {
14
16
  // The hash count picks the heading level; cast the dynamic tag to the known `h1`–`h6` set.
15
17
  const Heading = `h${prefix.length}`;
16
- return _jsx(Heading, { children: parser.parse(heading.trim(), "inline") }, key);
18
+ const title = heading.trim();
19
+ // Slug the raw title (before inline parsing) for the `id`, so `#anchor` fragment links land on the heading.
20
+ return (_jsx(Heading, { id: getSlug(title), children: parser.parse(title, "inline") }, key));
17
21
  }, ["block"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.266.0",
3
+ "version": "1.267.0",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",