nizel-plugin-heading-anchors 0.1.4 → 0.1.5
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 +5 -4
- package/dist/heading-anchors.iife.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# nizel-plugin-heading-anchors
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Subtle heading anchor links for [Nizel](https://npmjs.com/package/nizel).
|
|
4
4
|
|
|
5
|
-
The plugin appends a
|
|
5
|
+
The plugin appends a copyable section link to parsed headings that already have generated IDs. By default the link has no visible text, so apps can reveal it with CSS on hover or focus without adding a literal marker to the heading content.
|
|
6
6
|
|
|
7
7
|
The browser build exposes `NizelHeadingAnchors` from `dist/heading-anchors.iife.js`.
|
|
8
8
|
|
|
@@ -28,12 +28,13 @@ const nizel = useNizel({
|
|
|
28
28
|
| Option | Type | Default | Description |
|
|
29
29
|
| --- | --- | --- | --- |
|
|
30
30
|
| `className` | `string` | `'heading-anchor'` | CSS class for the generated anchor. |
|
|
31
|
-
| `label` | `string` | `'
|
|
31
|
+
| `label` | `string` | `''` | Optional visible marker text appended to the heading. |
|
|
32
|
+
| `ariaLabel` | `string` | `'Link to section'` | Accessible label for the generated anchor. |
|
|
32
33
|
|
|
33
34
|
## Output
|
|
34
35
|
|
|
35
36
|
```html
|
|
36
|
-
<h2 id="install">Install<a class="heading-anchor" href="#install" aria-
|
|
37
|
+
<h2 id="install">Install<a class="heading-anchor" href="#install" aria-label="Link to section"></a></h2>
|
|
37
38
|
```
|
|
38
39
|
|
|
39
40
|
## License
|
|
@@ -43,7 +43,7 @@ var NizelHeadingAnchors = (() => {
|
|
|
43
43
|
...node.children,
|
|
44
44
|
{
|
|
45
45
|
type: "inlineHtml",
|
|
46
|
-
value: `<a class="${escapeHtml(options.className ?? "heading-anchor")}" href="#${escapeHtml(node.id)}" aria-
|
|
46
|
+
value: `<a class="${escapeHtml(options.className ?? "heading-anchor")}" href="#${escapeHtml(node.id)}" aria-label="${escapeHtml(options.ariaLabel ?? "Link to section")}">${escapeHtml(options.label ?? "")}</a>`
|
|
47
47
|
}
|
|
48
48
|
]
|
|
49
49
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { NizelPlugin, NizelRootNode } from 'nizel';
|
|
|
2
2
|
export type HeadingAnchorsPluginOptions = {
|
|
3
3
|
className?: string;
|
|
4
4
|
label?: string;
|
|
5
|
+
ariaLabel?: string;
|
|
5
6
|
};
|
|
6
7
|
export declare const headingAnchorsPlugin: (options?: HeadingAnchorsPluginOptions) => NizelPlugin;
|
|
7
8
|
export declare const addHeadingAnchors: (ast: NizelRootNode, options?: HeadingAnchorsPluginOptions) => NizelRootNode;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAExD,MAAM,MAAM,2BAA2B,GAAG;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAExD,MAAM,MAAM,2BAA2B,GAAG;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,UAAS,2BAAgC,KAAG,WAO/E,CAAC;AAEH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,aAAa,EAClB,UAAS,2BAAgC,KACxC,aAeD,CAAC;AAIH,eAAe,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ export const addHeadingAnchors = (ast, options = {}) => ({
|
|
|
17
17
|
...node.children,
|
|
18
18
|
{
|
|
19
19
|
type: 'inlineHtml',
|
|
20
|
-
value: `<a class="${escapeHtml(options.className ?? 'heading-anchor')}" href="#${escapeHtml(node.id)}" aria-
|
|
20
|
+
value: `<a class="${escapeHtml(options.className ?? 'heading-anchor')}" href="#${escapeHtml(node.id)}" aria-label="${escapeHtml(options.ariaLabel ?? 'Link to section')}">${escapeHtml(options.label ?? '')}</a>`,
|
|
21
21
|
},
|
|
22
22
|
],
|
|
23
23
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,UAAuC,EAAE,EAAe,EAAE,CAAC,CAAC;IAC/F,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE;QACL,UAAU,CAAC,GAAG;YACZ,OAAO,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACzC,CAAC;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,GAAkB,EAClB,UAAuC,EAAE,EAC1B,EAAE,CAAC,CAAC;IACnB,GAAG,GAAG;IACN,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAClC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QACrD,OAAO;YACL,GAAG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