hast-util-dl-list 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/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yohei Kanamura
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# hast-util-dl-list
|
|
2
|
+
|
|
3
|
+
HAST handlers for rendering mdast definition list nodes
|
|
4
|
+
as `<dl>`, `<dt>`, and `<dd>` elements.
|
|
5
|
+
|
|
6
|
+
This package is designed to be used with `remark-rehype`.
|
|
7
|
+
|
|
8
|
+
For the detailed definition list syntax,
|
|
9
|
+
→ **[docs/syntax.md](https://github.com/kanemu/unified-dl-list/blob/main/docs/syntax.md)**.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install hast-util-dl-list
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or with pnpm:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add hast-util-dl-list
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { unified } from 'unified'
|
|
27
|
+
import remarkParse from 'remark-parse'
|
|
28
|
+
import remarkRehype from 'remark-rehype'
|
|
29
|
+
import rehypeStringify from 'rehype-stringify'
|
|
30
|
+
import { remarkDlList } from 'remark-dl-list'
|
|
31
|
+
import { dlListHandlers } from 'hast-util-dl-list'
|
|
32
|
+
|
|
33
|
+
const html = await unified()
|
|
34
|
+
.use(remarkParse)
|
|
35
|
+
.use(remarkDlList)
|
|
36
|
+
.use(remarkRehype, {
|
|
37
|
+
handlers: dlListHandlers()
|
|
38
|
+
})
|
|
39
|
+
.use(rehypeStringify)
|
|
40
|
+
.process(`
|
|
41
|
+
: term
|
|
42
|
+
: description
|
|
43
|
+
`)
|
|
44
|
+
|
|
45
|
+
console.log(String(html))
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## What this package does
|
|
49
|
+
|
|
50
|
+
* Provides HAST handlers for mdast definition list nodes
|
|
51
|
+
* Converts definition lists into `<dl>`, `<dt>`, and `<dd>`
|
|
52
|
+
* Preserves `data.hProperties` and `data.hName`
|
|
53
|
+
|
|
54
|
+
## What this package does NOT do
|
|
55
|
+
|
|
56
|
+
* Does not parse markdown
|
|
57
|
+
* Does not serialize markdown
|
|
58
|
+
* Does not install remark or rehype plugins automatically
|
|
59
|
+
|
|
60
|
+
## Related packages
|
|
61
|
+
|
|
62
|
+
This package is part of the **[unified-dl-list](https://github.com/kanemu/unified-dl-list)** monorepo:
|
|
63
|
+
|
|
64
|
+
- [`remark-dl-list`](https://github.com/kanemu/unified-dl-list/tree/main/packages/remark-dl-list)
|
|
65
|
+
- [`micromark-extension-dl-list`](https://github.com/kanemu/unified-dl-list/tree/main/packages/micromark-extension-dl-list)
|
|
66
|
+
- [`mdast-util-dl-list`](https://github.com/kanemu/unified-dl-list/tree/main/packages/mdast-util-dl-list)
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Handlers, State } from 'mdast-util-to-hast';
|
|
2
|
+
import { Properties, Element } from 'hast';
|
|
3
|
+
import { Data } from 'mdast';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Handlers for mdast definition list nodes.
|
|
7
|
+
*
|
|
8
|
+
* These handlers are meant to be passed to `mdast-util-to-hast` / `remark-rehype`.
|
|
9
|
+
*/
|
|
10
|
+
declare function dlListHandlers(): Handlers;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Context object passed to each handler.
|
|
14
|
+
* This is the same `state` object provided by mdast-util-to-hast.
|
|
15
|
+
*/
|
|
16
|
+
type HastState = State;
|
|
17
|
+
/**
|
|
18
|
+
* Minimal shape of mdast nodes this package cares about.
|
|
19
|
+
*
|
|
20
|
+
* - `data.hName`, `data.hProperties`, `data.hChildren` are respected by `state.applyData`.
|
|
21
|
+
* - Keep loose: mdast is extensible and downstream plugins may attach fields.
|
|
22
|
+
*/
|
|
23
|
+
interface MdastNode {
|
|
24
|
+
type: string;
|
|
25
|
+
children?: MdastNode[];
|
|
26
|
+
data?: Data & {
|
|
27
|
+
hName?: string;
|
|
28
|
+
hProperties?: Properties;
|
|
29
|
+
hChildren?: MdastNode[];
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resulting hast Element produced by handlers.
|
|
35
|
+
*/
|
|
36
|
+
type HastElement = Element;
|
|
37
|
+
|
|
38
|
+
export { type HastElement, type HastState, type MdastNode, dlListHandlers };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/handlers.ts
|
|
2
|
+
import { h } from "hastscript";
|
|
3
|
+
function createDl(state, node) {
|
|
4
|
+
const children = state.all(node);
|
|
5
|
+
const dl = h("dl", children);
|
|
6
|
+
state.applyData(node, dl);
|
|
7
|
+
return dl;
|
|
8
|
+
}
|
|
9
|
+
function createDlItem(state, node) {
|
|
10
|
+
return state.all(node);
|
|
11
|
+
}
|
|
12
|
+
function createDt(state, node) {
|
|
13
|
+
const children = state.all(node);
|
|
14
|
+
const dt = h("dt", children);
|
|
15
|
+
state.applyData(node, dt);
|
|
16
|
+
return dt;
|
|
17
|
+
}
|
|
18
|
+
function createDd(state, node) {
|
|
19
|
+
const children = state.all(node);
|
|
20
|
+
const dd = h("dd", children);
|
|
21
|
+
state.applyData(node, dd);
|
|
22
|
+
return dd;
|
|
23
|
+
}
|
|
24
|
+
function dlListHandlers() {
|
|
25
|
+
return {
|
|
26
|
+
definitionList(state, node) {
|
|
27
|
+
return createDl(state, node);
|
|
28
|
+
},
|
|
29
|
+
definitionItem(state, node) {
|
|
30
|
+
return createDlItem(state, node);
|
|
31
|
+
},
|
|
32
|
+
definitionTerm(state, node) {
|
|
33
|
+
return createDt(state, node);
|
|
34
|
+
},
|
|
35
|
+
definitionDescription(state, node) {
|
|
36
|
+
return createDd(state, node);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
dlListHandlers
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/handlers.ts"],"sourcesContent":["import { h } from 'hastscript'\nimport type { Handlers } from 'mdast-util-to-hast'\nimport type { HastState, MdastNode, HastElement } from './types'\n\n/**\n * Create a <dl> element from a definitionList mdast node.\n */\nfunction createDl(state: HastState, node: MdastNode): HastElement {\n const children = state.all(node as any) as any[]\n const dl = h('dl', children) as HastElement\n state.applyData(node as any, dl)\n return dl\n}\n\n/**\n * definitionItem itself does not map to an HTML element.\n * It expands to dt + dd elements.\n */\nfunction createDlItem(state: HastState, node: MdastNode): HastElement[] {\n return state.all(node as any) as HastElement[]\n}\n\n/**\n * Create a <dt> element.\n */\nfunction createDt(state: HastState, node: MdastNode): HastElement {\n const children = state.all(node as any) as any[]\n const dt = h('dt', children) as HastElement\n state.applyData(node as any, dt)\n return dt\n}\n\n/**\n * Create a <dd> element.\n *\n * mdast-util-dl-list may unwrap a single paragraph into phrasing children:\n * - phrasing-only children -> <dd>desc</dd>\n * - block children (paragraph/list/...) -> <dd><p>...</p>...</dd>\n */\nfunction createDd(state: HastState, node: MdastNode): HastElement {\n const children = state.all(node as any) as any[]\n const dd = h('dd', children) as HastElement\n state.applyData(node as any, dd)\n return dd\n}\n\n/**\n * Handlers for mdast definition list nodes.\n *\n * These handlers are meant to be passed to `mdast-util-to-hast` / `remark-rehype`.\n */\nexport function dlListHandlers(): Handlers {\n return {\n definitionList(state: HastState, node: MdastNode) {\n return createDl(state, node)\n },\n\n definitionItem(state: HastState, node: MdastNode) {\n return createDlItem(state, node)\n },\n\n definitionTerm(state: HastState, node: MdastNode) {\n return createDt(state, node)\n },\n\n definitionDescription(state: HastState, node: MdastNode) {\n return createDd(state, node)\n }\n } as unknown as Handlers\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAOlB,SAAS,SAAS,OAAkB,MAA8B;AAC9D,QAAM,WAAW,MAAM,IAAI,IAAW;AACtC,QAAM,KAAK,EAAE,MAAM,QAAQ;AAC3B,QAAM,UAAU,MAAa,EAAE;AAC/B,SAAO;AACX;AAMA,SAAS,aAAa,OAAkB,MAAgC;AACpE,SAAO,MAAM,IAAI,IAAW;AAChC;AAKA,SAAS,SAAS,OAAkB,MAA8B;AAC9D,QAAM,WAAW,MAAM,IAAI,IAAW;AACtC,QAAM,KAAK,EAAE,MAAM,QAAQ;AAC3B,QAAM,UAAU,MAAa,EAAE;AAC/B,SAAO;AACX;AASA,SAAS,SAAS,OAAkB,MAA8B;AAC9D,QAAM,WAAW,MAAM,IAAI,IAAW;AACtC,QAAM,KAAK,EAAE,MAAM,QAAQ;AAC3B,QAAM,UAAU,MAAa,EAAE;AAC/B,SAAO;AACX;AAOO,SAAS,iBAA2B;AACvC,SAAO;AAAA,IACH,eAAe,OAAkB,MAAiB;AAC9C,aAAO,SAAS,OAAO,IAAI;AAAA,IAC/B;AAAA,IAEA,eAAe,OAAkB,MAAiB;AAC9C,aAAO,aAAa,OAAO,IAAI;AAAA,IACnC;AAAA,IAEA,eAAe,OAAkB,MAAiB;AAC9C,aAAO,SAAS,OAAO,IAAI;AAAA,IAC/B;AAAA,IAEA,sBAAsB,OAAkB,MAAiB;AACrD,aAAO,SAAS,OAAO,IAAI;AAAA,IAC/B;AAAA,EACJ;AACJ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hast-util-dl-list",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Handlers only for converting mdast definition list nodes into hast elements (<dl>, <dt>, <dd>) for remark-rehype.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Yohei Kanamura",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/kanemu/unified-dl-list",
|
|
11
|
+
"directory": "packages/hast-util-dl-list"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/kanemu/unified-dl-list/tree/main/packages/hast-util-dl-list",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/kanemu/unified-dl-list/issues"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/**",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"hastscript": "^9.0.1",
|
|
32
|
+
"mdast-util-to-hast": "^13.2.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/mdast": "^4.0.4",
|
|
36
|
+
"@types/hast": "^3.0.4",
|
|
37
|
+
"hast-util-to-html": "^9.0.5",
|
|
38
|
+
"mdast-util-dl-list": "^0.1.0",
|
|
39
|
+
"mdast-util-from-markdown": "^2.0.2",
|
|
40
|
+
"micromark-extension-dl-list": "^0.1.0",
|
|
41
|
+
"rimraf": "^6.1.2",
|
|
42
|
+
"tsup": "^8.5.1",
|
|
43
|
+
"typescript": "^5.4.0"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"unified",
|
|
47
|
+
"remark",
|
|
48
|
+
"rehype",
|
|
49
|
+
"hast",
|
|
50
|
+
"mdast",
|
|
51
|
+
"remark-rehype",
|
|
52
|
+
"hast-util",
|
|
53
|
+
"markdown",
|
|
54
|
+
"definition-list",
|
|
55
|
+
"dl",
|
|
56
|
+
"dt",
|
|
57
|
+
"dd"
|
|
58
|
+
],
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup",
|
|
61
|
+
"clean": "rimraf dist",
|
|
62
|
+
"test": "pnpm build && node --test ./test/*.test.js",
|
|
63
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
64
|
+
}
|
|
65
|
+
}
|