nizel-plugin-heading-anchors 0.1.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/README.md +3 -0
- package/dist/heading-anchors.iife.js +55 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var NizelHeadingAnchors = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
addHeadingAnchors: () => addHeadingAnchors,
|
|
25
|
+
default: () => index_default,
|
|
26
|
+
headingAnchorsPlugin: () => headingAnchorsPlugin
|
|
27
|
+
});
|
|
28
|
+
var headingAnchorsPlugin = (options = {}) => ({
|
|
29
|
+
name: "heading-anchors",
|
|
30
|
+
hooks: {
|
|
31
|
+
afterParse(ast) {
|
|
32
|
+
return addHeadingAnchors(ast, options);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var addHeadingAnchors = (ast, options = {}) => ({
|
|
37
|
+
...ast,
|
|
38
|
+
children: ast.children.map((node) => {
|
|
39
|
+
if (node.type !== "heading" || !node.id) return node;
|
|
40
|
+
return {
|
|
41
|
+
...node,
|
|
42
|
+
children: [
|
|
43
|
+
...node.children,
|
|
44
|
+
{
|
|
45
|
+
type: "inlineHtml",
|
|
46
|
+
value: `<a class="${escapeHtml(options.className ?? "heading-anchor")}" href="#${escapeHtml(node.id)}" aria-hidden="true">${escapeHtml(options.label ?? "#")}</a>`
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
var escapeHtml = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
53
|
+
var index_default = headingAnchorsPlugin;
|
|
54
|
+
return __toCommonJS(index_exports);
|
|
55
|
+
})();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NizelPlugin, NizelRootNode } from 'nizel';
|
|
2
|
+
export type HeadingAnchorsPluginOptions = {
|
|
3
|
+
className?: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const headingAnchorsPlugin: (options?: HeadingAnchorsPluginOptions) => NizelPlugin;
|
|
7
|
+
export declare const addHeadingAnchors: (ast: NizelRootNode, options?: HeadingAnchorsPluginOptions) => NizelRootNode;
|
|
8
|
+
export default headingAnchorsPlugin;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;CAChB,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
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const headingAnchorsPlugin = (options = {}) => ({
|
|
2
|
+
name: 'heading-anchors',
|
|
3
|
+
hooks: {
|
|
4
|
+
afterParse(ast) {
|
|
5
|
+
return addHeadingAnchors(ast, options);
|
|
6
|
+
},
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
export const addHeadingAnchors = (ast, options = {}) => ({
|
|
10
|
+
...ast,
|
|
11
|
+
children: ast.children.map((node) => {
|
|
12
|
+
if (node.type !== 'heading' || !node.id)
|
|
13
|
+
return node;
|
|
14
|
+
return {
|
|
15
|
+
...node,
|
|
16
|
+
children: [
|
|
17
|
+
...node.children,
|
|
18
|
+
{
|
|
19
|
+
type: 'inlineHtml',
|
|
20
|
+
value: `<a class="${escapeHtml(options.className ?? 'heading-anchor')}" href="#${escapeHtml(node.id)}" aria-hidden="true">${escapeHtml(options.label ?? '#')}</a>`,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
const escapeHtml = (value) => value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
27
|
+
export default headingAnchorsPlugin;
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,oBAAoB,GAAG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
+
"description": "Heading anchor link plugin for Nizel.",
|
|
5
|
+
"repository": { "type": "git", "url": "https://github.com/silvandiepen/nizel" },
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
|
|
11
|
+
"./browser": { "types": "./dist/index.d.ts", "import": "./dist/index.js" }
|
|
12
|
+
},
|
|
13
|
+
"files": ["dist", "README.md"],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json && npm run build:browser",
|
|
16
|
+
"build:browser": "esbuild src/index.ts --bundle --platform=browser --format=iife --global-name=NizelHeadingAnchors --target=safari14 --outfile=dist/heading-anchors.iife.js",
|
|
17
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
18
|
+
"test": "npm run build && vitest run test/*.mjs"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": { "nizel": "^0.1.0" },
|
|
21
|
+
"devDependencies": { "esbuild": "^0.27.3" },
|
|
22
|
+
"publishConfig": { "access": "public", "provenance": true }
|
|
23
|
+
}
|