oast-to-hast 4.3.2 → 4.4.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.
@@ -7,9 +7,10 @@ export function list(state: import("../state.js").State, node: import("orga").Li
7
7
  /**
8
8
  * @param {import('../state.js').State} state
9
9
  * @param {import('orga').ListItem} node
10
- * @returns {import('hast').Element}
10
+ * @param {import('orga').Parent | undefined} parent
11
+ * @returns {import('hast').ElementContent | import('hast').ElementContent[]}
11
12
  */
12
- export function item(state: import("../state.js").State, node: import("orga").ListItem): import("hast").Element;
13
+ export function item(state: import("../state.js").State, node: import("orga").ListItem, parent: import("orga").Parent | undefined): import("hast").ElementContent | import("hast").ElementContent[];
13
14
  /**
14
15
  * @param {import('../state.js').State} state
15
16
  * @param {import('orga').ListItemCheckbox} node
@@ -1 +1 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["list.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,4BAJW,OAAO,aAAa,EAAE,KAAK,QAC3B,OAAO,MAAM,EAAE,IAAI,GACjB,OAAO,MAAM,EAAE,OAAO,CAgBlC;AAED;;;;GAIG;AACH,4BAJW,OAAO,aAAa,EAAE,KAAK,QAC3B,OAAO,MAAM,EAAE,QAAQ,GACrB,OAAO,MAAM,EAAE,OAAO,CAmClC;AAED;;;;GAIG;AACH,gCAJW,OAAO,aAAa,EAAE,KAAK,QAC3B,OAAO,MAAM,EAAE,gBAAgB,GAC7B,OAAO,MAAM,EAAE,OAAO,CAalC"}
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["list.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,4BAJW,OAAO,aAAa,EAAE,KAAK,QAC3B,OAAO,MAAM,EAAE,IAAI,GACjB,OAAO,MAAM,EAAE,OAAO,CAgBlC;AAED;;;;;GAKG;AACH,4BALW,OAAO,aAAa,EAAE,KAAK,QAC3B,OAAO,MAAM,EAAE,QAAQ,UACvB,OAAO,MAAM,EAAE,MAAM,GAAG,SAAS,GAC/B,OAAO,MAAM,EAAE,cAAc,GAAG,OAAO,MAAM,EAAE,cAAc,EAAE,CAkD3E;AAED;;;;GAIG;AACH,gCAJW,OAAO,aAAa,EAAE,KAAK,QAC3B,OAAO,MAAM,EAAE,gBAAgB,GAC7B,OAAO,MAAM,EAAE,OAAO,CAalC"}
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export function list(state, node) {
7
7
  let tagName = node.ordered ? 'ol' : 'ul'
8
- if (node.children.every((i) => i.type === 'list.item' && i.tag)) {
8
+ if (node.children.every((i) => i.type !== 'list.item' || i.tag)) {
9
9
  tagName = 'dl'
10
10
  }
11
11
 
@@ -22,35 +22,51 @@ export function list(state, node) {
22
22
  /**
23
23
  * @param {import('../state.js').State} state
24
24
  * @param {import('orga').ListItem} node
25
- * @returns {import('hast').Element}
25
+ * @param {import('orga').Parent | undefined} parent
26
+ * @returns {import('hast').ElementContent | import('hast').ElementContent[]}
26
27
  */
27
- export function item(state, node) {
28
+ export function item(state, node, parent) {
28
29
  if (node.tag) {
30
+ /** @type {import('hast').Element[]} */
31
+ const dtdd = [
32
+ {
33
+ type: 'element',
34
+ tagName: 'dt',
35
+ properties: {},
36
+ children: [{ type: 'text', value: node.tag }]
37
+ },
38
+ {
39
+ type: 'element',
40
+ tagName: 'dd',
41
+ properties: {},
42
+ children: state.all(node)
43
+ }
44
+ ]
45
+
46
+ const allTagged =
47
+ parent?.children?.every((i) => i.type !== 'list.item' || i.tag)
48
+
49
+ if (allTagged) {
50
+ // Pure definition list: return [<dt>, <dd>] to be flattened into <dl>
51
+ return dtdd
52
+ }
53
+
54
+ // Definition item inside a mixed list: wrap in <li><dl>…</dl></li>
29
55
  return state.patch(node, {
30
56
  type: 'element',
31
- tagName: 'div',
57
+ tagName: 'li',
32
58
  properties: {},
33
59
  children: [
34
60
  {
35
61
  type: 'element',
36
- tagName: 'dt',
62
+ tagName: 'dl',
37
63
  properties: {},
38
- children: [
39
- {
40
- type: 'text',
41
- value: node.tag
42
- }
43
- ]
44
- },
45
- {
46
- type: 'element',
47
- tagName: 'dd',
48
- properties: {},
49
- children: state.all(node)
64
+ children: dtdd
50
65
  }
51
66
  ]
52
67
  })
53
68
  }
69
+
54
70
  return state.patch(node, {
55
71
  type: 'element',
56
72
  tagName: 'li',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oast-to-hast",
3
- "version": "4.3.2",
3
+ "version": "4.4.0",
4
4
  "description": "Transform OAST to HAST",
5
5
  "files": [
6
6
  "lib",
@@ -18,7 +18,7 @@
18
18
  "mime": "^3.0.0",
19
19
  "parse5": "^7.1.2",
20
20
  "unist-util-position": "^5.0.0",
21
- "orga": "^4.5.1"
21
+ "orga": "^4.6.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/hast": "^3.0.4",