oast-to-hast 4.4.0 → 4.4.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,4BAJW,OAAO,aAAa,EAAE,KAAK,QAC3B,OAAO,MAAM,EAAE,IAAI,GACjB,OAAO,
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,4BAJW,OAAO,aAAa,EAAE,KAAK,QAC3B,OAAO,MAAM,EAAE,IAAI,GACjB,OAAO,CAyGnB;6BAjH2B,MAAM"}
|
package/lib/handlers/link.js
CHANGED
|
@@ -57,6 +57,52 @@ export function link(state, node) {
|
|
|
57
57
|
|
|
58
58
|
return state.patch(node, image)
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
if (type && type.startsWith('video')) {
|
|
62
|
+
/** @type {Element} */
|
|
63
|
+
const video = {
|
|
64
|
+
type: 'element',
|
|
65
|
+
tagName: 'video',
|
|
66
|
+
properties: {
|
|
67
|
+
src: node.path.value,
|
|
68
|
+
controls: true
|
|
69
|
+
},
|
|
70
|
+
children: []
|
|
71
|
+
}
|
|
72
|
+
/** @type {Element|null} */
|
|
73
|
+
let cap = null
|
|
74
|
+
const c = node.attributes['caption']
|
|
75
|
+
if (c) {
|
|
76
|
+
cap = {
|
|
77
|
+
type: 'element',
|
|
78
|
+
tagName: 'figcaption',
|
|
79
|
+
properties: {},
|
|
80
|
+
children: [
|
|
81
|
+
{
|
|
82
|
+
type: 'text',
|
|
83
|
+
value: `${c}`
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
} else if (node.children.length > 0) {
|
|
88
|
+
cap = {
|
|
89
|
+
type: 'element',
|
|
90
|
+
tagName: 'figcaption',
|
|
91
|
+
properties: {},
|
|
92
|
+
children: state.all(node)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (cap) {
|
|
96
|
+
return state.patch(node, {
|
|
97
|
+
type: 'element',
|
|
98
|
+
tagName: 'figure',
|
|
99
|
+
properties: {},
|
|
100
|
+
children: [video, cap]
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return state.patch(node, video)
|
|
105
|
+
}
|
|
60
106
|
return state.patch(node, {
|
|
61
107
|
type: 'element',
|
|
62
108
|
tagName: 'a',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["paragraph.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["paragraph.js"],"names":[],"mappings":"AAcA;;;;GAIG;AACH,iCAJW,OAAO,aAAa,EAAE,KAAK,QAC3B,OAAO,MAAM,EAAE,SAAS,GACtB,OAAO,MAAM,EAAE,OAAO,CA+BlC"}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block-level HTML elements that are not allowed as descendants of <p>.
|
|
3
|
+
* When a paragraph contains any of these, we must avoid wrapping in <p>.
|
|
4
|
+
*
|
|
5
|
+
* @see https://html.spec.whatwg.org/multipage/grouping-content.html#the-p-element
|
|
6
|
+
*/
|
|
7
|
+
const BLOCK_TAGS = new Set([
|
|
8
|
+
'address', 'article', 'aside', 'blockquote', 'details', 'dialog',
|
|
9
|
+
'dd', 'div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure',
|
|
10
|
+
'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
|
11
|
+
'header', 'hgroup', 'hr', 'li', 'main', 'nav', 'ol', 'p',
|
|
12
|
+
'pre', 'section', 'summary', 'table', 'ul',
|
|
13
|
+
])
|
|
14
|
+
|
|
1
15
|
/**
|
|
2
16
|
* @param {import('../state.js').State} state
|
|
3
17
|
* @param {import('orga').Paragraph} node
|
|
@@ -5,11 +19,31 @@
|
|
|
5
19
|
*/
|
|
6
20
|
export function paragraph(state, node) {
|
|
7
21
|
const properties = state.getAttrHtml(node)
|
|
22
|
+
const children = state.all(node)
|
|
23
|
+
|
|
24
|
+
// If any child is a block-level element (e.g. a <figure> from a media link
|
|
25
|
+
// with caption), wrapping in <p> produces invalid HTML and causes hydration
|
|
26
|
+
// errors in React. Unwrap single block children; use <div> for mixed content.
|
|
27
|
+
const hasBlock = children.some(
|
|
28
|
+
(child) => child.type === 'element' && BLOCK_TAGS.has(/** @type {import('hast').Element} */ (child).tagName)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
if (hasBlock) {
|
|
32
|
+
if (children.length === 1) {
|
|
33
|
+
return /** @type {import('hast').Element} */ (children[0])
|
|
34
|
+
}
|
|
35
|
+
return state.patch(node, {
|
|
36
|
+
type: 'element',
|
|
37
|
+
tagName: 'div',
|
|
38
|
+
properties: properties ?? {},
|
|
39
|
+
children,
|
|
40
|
+
})
|
|
41
|
+
}
|
|
8
42
|
|
|
9
43
|
return state.patch(node, {
|
|
10
44
|
type: 'element',
|
|
11
45
|
tagName: 'p',
|
|
12
46
|
properties: properties ?? {},
|
|
13
|
-
children
|
|
47
|
+
children,
|
|
14
48
|
})
|
|
15
49
|
}
|