nizel-kit 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
@@ -4,6 +4,12 @@ Browser and native WebView integration bundle for Nizel.
4
4
 
5
5
  `nizel-kit` packages the browser renderer plus a registry of official plugins. Native apps can show settings from `supportedPlugins`, store selected plugin IDs, and pass those IDs back to the renderer. The Swift app does not need to parse or convert Markdown extension syntax.
6
6
 
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install nizel-kit
11
+ ```
12
+
7
13
  ## Browser / IIFE
8
14
 
9
15
  Use `dist/nizel-kit.iife.js` in `WKWebView`, `JSContext`, or a browser shell. It exposes `NizelKit`.
@@ -32,3 +38,35 @@ let enabledPlugins = ["alert", "math", "typography"]
32
38
  Then pass that array into JavaScript when rendering.
33
39
 
34
40
  Code-rendering plugins use `exclusiveGroup: "code-renderer"`. If multiple code renderers are selected, `nizel-kit` keeps the last selected one so the renderer remains deterministic.
41
+
42
+ ## API
43
+
44
+ - `supportedPlugins` - serializable plugin metadata for settings screens.
45
+ - `defaultEnabledPlugins()` - plugin IDs enabled by default.
46
+ - `normalizeEnabledPlugins(ids)` - validates plugin IDs and resolves exclusive groups.
47
+ - `createPlugins(ids, pluginOptions)` - returns Nizel plugin instances.
48
+ - `useNizelKit(options)` - creates a browser processor with selected plugins.
49
+ - `markdownToHtml(markdown, options)` - renders Markdown to HTML.
50
+ - `mountMarkdown(target, markdown, options)` - renders into a browser/WebView DOM target.
51
+
52
+ ## Plugin IDs
53
+
54
+ `abbr`, `alert`, `autolink`, `citations`, `code-copy`, `deflist`, `details`, `diagrams`, `emoji`, `footnotes`, `frontmatter-ui`, `gfm`, `heading-anchors`, `math`, `media`, `sanitize`, `shiki`, `toc`, and `typography`.
55
+
56
+ ## Swift / WebView Shape
57
+
58
+ ```swift
59
+ struct NizelPluginSetting: Codable, Identifiable {
60
+ let id: String
61
+ let label: String
62
+ let description: String
63
+ let defaultEnabled: Bool
64
+ let category: String
65
+ }
66
+ ```
67
+
68
+ Load `nizel-kit.iife.js`, read `NizelKit.supportedPlugins` to build the settings UI, persist selected IDs, and call `NizelKit.markdownToHtml(markdown, { enabledPlugins })` when rendering.
69
+
70
+ ## License
71
+
72
+ MIT
@@ -155,8 +155,18 @@ var NizelKit = (() => {
155
155
  if (node.tag === "code" || node.tag === "pre") {
156
156
  return names.some((name) => name !== "class") || !/\blanguage-[A-Za-z0-9_-]+/.test(node.attrs.class ?? "");
157
157
  }
158
+ if (/^h[1-6]$/.test(node.tag)) {
159
+ return names.some((name) => {
160
+ if (name !== "id")
161
+ return true;
162
+ return node.attrs.id !== slugifyText(textContent(node));
163
+ });
164
+ }
158
165
  return true;
159
166
  }
167
+ function slugifyText(value) {
168
+ return value.toLowerCase().replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, "");
169
+ }
160
170
  function renderChildren(nodes, options, depth) {
161
171
  return nodes.map((node) => renderNode(node, options, depth)).join("");
162
172
  }
@@ -4633,6 +4643,7 @@ ${body}
4633
4643
  ...resolved.meta
4634
4644
  };
4635
4645
  let data = {
4646
+ ...meta,
4636
4647
  ...resolved.data ?? {},
4637
4648
  meta,
4638
4649
  frontmatter: extracted.frontmatter
@@ -4640,6 +4651,7 @@ ${body}
4640
4651
  if (resolved.template !== false) {
4641
4652
  meta = renderObjectTemplates(meta, data, resolved.template);
4642
4653
  data = {
4654
+ ...meta,
4643
4655
  ...resolved.data ?? {},
4644
4656
  meta,
4645
4657
  frontmatter: meta
package/dist/nizel-kit.js CHANGED
@@ -123,8 +123,18 @@ function hasUnsupportedAttrs(node) {
123
123
  if (node.tag === "code" || node.tag === "pre") {
124
124
  return names.some((name) => name !== "class") || !/\blanguage-[A-Za-z0-9_-]+/.test(node.attrs.class ?? "");
125
125
  }
126
+ if (/^h[1-6]$/.test(node.tag)) {
127
+ return names.some((name) => {
128
+ if (name !== "id")
129
+ return true;
130
+ return node.attrs.id !== slugifyText(textContent(node));
131
+ });
132
+ }
126
133
  return true;
127
134
  }
135
+ function slugifyText(value) {
136
+ return value.toLowerCase().replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, "");
137
+ }
128
138
  function renderChildren(nodes, options, depth) {
129
139
  return nodes.map((node) => renderNode(node, options, depth)).join("");
130
140
  }
@@ -4601,6 +4611,7 @@ function createNizel(options = {}) {
4601
4611
  ...resolved.meta
4602
4612
  };
4603
4613
  let data = {
4614
+ ...meta,
4604
4615
  ...resolved.data ?? {},
4605
4616
  meta,
4606
4617
  frontmatter: extracted.frontmatter
@@ -4608,6 +4619,7 @@ function createNizel(options = {}) {
4608
4619
  if (resolved.template !== false) {
4609
4620
  meta = renderObjectTemplates(meta, data, resolved.template);
4610
4621
  data = {
4622
+ ...meta,
4611
4623
  ...resolved.data ?? {},
4612
4624
  meta,
4613
4625
  frontmatter: meta
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nizel-kit",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Browser and native WebView integration kit for Nizel with official plugin registry.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,8 @@
28
28
  "build:browser": "esbuild src/index.ts --bundle --platform=browser --format=esm --target=safari14 --outfile=dist/nizel-kit.js && esbuild src/index.ts --bundle --platform=browser --format=iife --global-name=NizelKit --target=safari14 --outfile=dist/nizel-kit.iife.js",
29
29
  "typecheck": "tsc -p tsconfig.json --noEmit",
30
30
  "test": "npm run build && vitest run test/*.mjs",
31
- "test:watch": "npm run build && vitest test/*.mjs"
31
+ "test:watch": "npm run build && vitest test/*.mjs",
32
+ "test:run": "vitest run test/*.mjs"
32
33
  },
33
34
  "dependencies": {
34
35
  "nizel": "^0.1.0",