@mdsvex/plugin-toc 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  A table of contents for [mdsvex](https://mdsvex.pngwn.io): the headings of each document as data, a component that renders them as a nested list, and a `::toc` directive that puts that list in the document.
4
4
 
5
5
  ```bash
6
- pnpm add --save-dev @mdsvex/plugin-toc@next
6
+ pnpm add --save-dev @mdsvex/plugin-toc
7
7
  ```
8
8
 
9
9
  ```js
@@ -45,7 +45,7 @@ It needs Svelte 5.20 or later.
45
45
 
46
46
  - **`depth`**, 1 to 6.
47
47
  - **`id`**, the id the heading has in the page, so `'#' + id` links to it.
48
- - **`text`**, the text a reader sees, without markup. Emphasis, links and code are their text, an image is its alt, and a character reference such as `&` is its character. What only exists once the page runs is not in it: a `{expression}`, a component, a directive.
48
+ - **`text`**, the text a reader sees, without markup. Emphasis, links and code are their text, an image is its alt, and a character reference such as `&` is its character. With the `smart_punctuation` option of mdsvex on, the quotes, dashes and ellipses are the ones the heading shows. What only exists once the page runs is not in it: a `{expression}`, a component, a directive.
49
49
  - **`position`**, where the heading is in the source, as `{ start, end }` with an `offset`, a `line` from 1 and a `column` from 0 each.
50
50
 
51
51
  The list is flat because that is what the document holds and what is easy to filter. `toc_tree` nests it:
package/dist/index.js CHANGED
@@ -23,60 +23,6 @@ function depth_option(name, value, fallback) {
23
23
  return value;
24
24
  throw new TocError('option', `${name} must be a heading depth from 1 to 6, got ${JSON.stringify(value)}`);
25
25
  }
26
- const REFERENCE = /&(?:#(\d{1,7})|#[xX]([0-9a-fA-F]{1,6})|(amp|lt|gt|quot|apos|nbsp));/g;
27
- const NAMED = {
28
- amp: '&',
29
- lt: '<',
30
- gt: '>',
31
- quot: '"',
32
- apos: "'",
33
- nbsp: String.fromCharCode(0xa0),
34
- };
35
- /** a numeric reference and the few named ones html needs are their character, any other stays as written */
36
- function reference(_match, decimal, hex, name) {
37
- if (name !== undefined)
38
- return NAMED[name];
39
- const code = decimal !== undefined ? parseInt(decimal, 10) : parseInt(hex, 16);
40
- if (code === 0 || code > 0x10ffff || (code >= 0xd800 && code <= 0xdfff))
41
- return String.fromCharCode(0xfffd);
42
- return String.fromCodePoint(code);
43
- }
44
- const is_element = /^[a-z][^.:]*$/;
45
- /** the text heading_ids makes the id from, an image is its alt, what svelte or a component renders is nothing */
46
- function text_of(node) {
47
- let out = '';
48
- for (let child = node.first_child; child !== null; child = child.next) {
49
- switch (child.type) {
50
- case 'text': {
51
- const text = child.text_content;
52
- out +=
53
- text.indexOf('&') === -1 ? text : text.replace(REFERENCE, reference);
54
- break;
55
- }
56
- // code shows a reference as written
57
- case 'code_span':
58
- out += child.text_content;
59
- break;
60
- case 'mustache':
61
- case 'svelte_tag':
62
- case 'svelte_block':
63
- case 'html_comment':
64
- case 'directive_inline':
65
- case 'directive_leaf':
66
- case 'directive_container':
67
- break;
68
- case 'html': {
69
- const tag = child.attrs.tag;
70
- if (typeof tag === 'string' && is_element.test(tag))
71
- out += text_of(child);
72
- break;
73
- }
74
- default:
75
- out += text_of(child);
76
- }
77
- }
78
- return out;
79
- }
80
26
  /** anywhere inside, an anchor that wraps the content of the heading holds the comment too */
81
27
  function is_marked(node) {
82
28
  for (let child = node.first_child; child !== null; child = child.next) {
@@ -124,7 +70,7 @@ function close_heading(node, ctx, min, max) {
124
70
  if (last !== 0 && depth > last + 1) {
125
71
  ctx.warn('skipped_level', `a level ${depth} heading follows a level ${last} heading, a level is skipped`, node);
126
72
  }
127
- const text = text_of(node).trim();
73
+ const text = ctx.text(node).trim();
128
74
  if (!has_id) {
129
75
  if (HAS_WORD.test(text))
130
76
  seen.sluggable = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdsvex/plugin-toc",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Table of contents for mdsvex, the headings of a document as data and a component that lists them",
5
5
  "type": "module",
6
6
  "exports": {
@@ -54,7 +54,7 @@
54
54
  "author": "pngwn <hello@pngwn.io>",
55
55
  "license": "MIT",
56
56
  "peerDependencies": {
57
- "mdsvex": "^1.0.0-next.2",
57
+ "mdsvex": "^1.1.0",
58
58
  "svelte": "^5.20.0"
59
59
  },
60
60
  "devDependencies": {
@@ -63,10 +63,10 @@
63
63
  "npm-run-all2": "^7.0.2",
64
64
  "svelte": "^5.55.0",
65
65
  "vite": "^7.3.1",
66
- "@mdsvex/plugin-anchors": "^0.1.0",
67
- "@mdsvex/plugin-tabs": "^0.1.0",
68
- "@mdsvex/plugin-steps": "^0.1.0",
69
- "mdsvex": "^1.0.0"
66
+ "@mdsvex/plugin-anchors": "^0.1.1",
67
+ "@mdsvex/plugin-steps": "^0.1.1",
68
+ "@mdsvex/plugin-tabs": "^0.1.1",
69
+ "mdsvex": "^1.1.0"
70
70
  },
71
71
  "scripts": {
72
72
  "build": "run-s build:check build:package",