Skip to content

Commit 1946cf3

Browse files
committed
Update @types/mdast, utilities, etc
1 parent 53bbbb4 commit 1946cf3

File tree

5 files changed

+48
-50
lines changed

5 files changed

+48
-50
lines changed

index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,19 @@ export default function remarkHtml(settings = {}) {
3737
clean = true
3838
}
3939

40-
Object.assign(this, {Compiler: compiler})
40+
Object.assign(this, {compiler})
4141

4242
/**
43-
* @type {import('unified').CompilerFunction<Root, string>}
43+
* @type {import('unified').Compiler<Root, string>}
4444
*/
4545
function compiler(node, file) {
4646
const hast = toHast(node, {
4747
allowDangerousHtml: !clean,
4848
handlers: options.handlers
4949
})
50-
// @ts-expect-error: assume root.
50+
// @ts-expect-error: to do: no longer boolean.
5151
const cleanHast = clean ? sanitize(hast, options.sanitize) : hast
5252
const result = toHtml(
53-
// @ts-expect-error: assume root.
5453
cleanHast,
5554
Object.assign({}, options, {allowDangerousHtml: !clean})
5655
)

package.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,34 @@
3737
"index.js"
3838
],
3939
"dependencies": {
40-
"@types/mdast": "^3.0.0",
41-
"hast-util-sanitize": "^4.0.0",
42-
"hast-util-to-html": "^8.0.0",
43-
"mdast-util-to-hast": "^12.0.0",
44-
"unified": "^10.0.0"
40+
"@types/mdast": "^4.0.0",
41+
"hast-util-sanitize": "^5.0.0",
42+
"hast-util-to-html": "^9.0.0",
43+
"mdast-util-to-hast": "^13.0.0",
44+
"unified": "^11.0.0"
4545
},
4646
"devDependencies": {
47+
"@types/hast": "^3.0.0",
4748
"@types/tape": "^5.0.0",
4849
"c8": "^8.0.0",
4950
"commonmark.json": "^0.30.0",
5051
"is-hidden": "^2.0.0",
5152
"prettier": "^3.0.0",
52-
"rehype-parse": "^8.0.0",
53-
"rehype-stringify": "^9.0.0",
54-
"remark": "^14.0.0",
53+
"rehype-parse": "^9.0.0",
54+
"rehype-stringify": "^10.0.0",
55+
"remark": "^15.0.0",
5556
"remark-cli": "^11.0.0",
56-
"remark-frontmatter": "^4.0.0",
57-
"remark-gfm": "^3.0.0",
58-
"remark-github": "^11.0.0",
57+
"remark-frontmatter": "^5.0.0",
58+
"remark-gfm": "^4.0.0",
59+
"remark-github": "^12.0.0",
5960
"remark-preset-wooorm": "^9.0.0",
6061
"remark-slug": "^7.0.0",
61-
"remark-toc": "^8.0.0",
62+
"remark-toc": "^9.0.0",
6263
"tape": "^5.0.0",
63-
"to-vfile": "^7.0.0",
64+
"to-vfile": "^8.0.0",
6465
"type-coverage": "^2.0.0",
6566
"typescript": "^5.0.0",
67+
"vfile": "^6.0.0",
6668
"xo": "^0.56.0"
6769
},
6870
"scripts": {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sanitize": false,
3-
"entities": {
3+
"characterReferences": {
44
"useNamedReferences": true
55
}
66
}

test/index.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @typedef {import('mdast').Root} Root
33
* @typedef {import('mdast').Paragraph} Paragraph
4+
* @typedef {import('hast').Element} Element
45
* @typedef {import('vfile').VFile} VFile
56
* @typedef {import('../index.js').Options} Options
67
*/
@@ -11,7 +12,6 @@ import test from 'tape'
1112
import {isHidden} from 'is-hidden'
1213
import {commonmark} from 'commonmark.json'
1314
import {toVFile} from 'to-vfile'
14-
import {all} from 'mdast-util-to-hast'
1515
import {unified} from 'unified'
1616
import {remark} from 'remark'
1717
import remarkParse from 'remark-parse'
@@ -29,28 +29,17 @@ test('remarkHtml', (t) => {
2929
remark().use(remarkHtml).freeze()
3030
}, 'should not throw if not passed options')
3131

32-
t.throws(
33-
() => {
34-
remark()
35-
.use(remarkHtml)
36-
// @ts-expect-error: not a node.
37-
.stringify({type: 'root', children: [{value: 'baz'}]})
38-
},
39-
/Expected node, got `\[object Object]`/,
40-
'should throw when not given a node'
41-
)
42-
43-
let processorDangerous = remark().use(remarkHtml, {sanitize: false})
32+
const processorDangerous1 = remark().use(remarkHtml, {sanitize: false})
4433

4534
t.equal(
4635
// @ts-expect-error: unknown node.
47-
processorDangerous.stringify({type: 'alpha'}),
36+
processorDangerous1.stringify({type: 'alpha'}),
4837
'<div></div>',
4938
'should stringify unknown nodes'
5039
)
5140

5241
t.equal(
53-
processorDangerous.stringify({
42+
processorDangerous1.stringify({
5443
// @ts-expect-error: unknown node.
5544
type: 'alpha',
5645
children: [{type: 'strong', children: [{type: 'text', value: 'bravo'}]}]
@@ -60,7 +49,7 @@ test('remarkHtml', (t) => {
6049
)
6150

6251
t.equal(
63-
processorDangerous.stringify({
52+
processorDangerous1.stringify({
6453
// @ts-expect-error: unknown node.
6554
type: 'alpha',
6655
children: [{type: 'text', value: 'bravo'}],
@@ -74,29 +63,37 @@ test('remarkHtml', (t) => {
7463
'should stringify unknown nodes'
7564
)
7665

77-
processorDangerous = remark().use(remarkHtml, {
66+
const processorDangerous2 = remark().use(remarkHtml, {
7867
sanitize: false,
7968
handlers: {
8069
/** @param {Paragraph} node */
81-
paragraph(h, node) {
70+
paragraph(state, node) {
8271
const head = node.children[0]
8372

8473
if (head.type === 'text') {
8574
head.value = 'changed'
8675
}
8776

88-
return h(node, 'p', all(h, node))
77+
/** @type {Element} */
78+
const result = {
79+
type: 'element',
80+
tagName: 'p',
81+
properties: {},
82+
children: state.all(node)
83+
}
84+
state.patch(node, result)
85+
return state.applyData(node, result)
8986
}
9087
}
9188
})
9289

9390
t.equal(
94-
processorDangerous.processSync('paragraph text').toString(),
91+
processorDangerous2.processSync('paragraph text').toString(),
9592
'<p>changed</p>\n',
9693
'should allow overriding handlers'
9794
)
9895

99-
processorDangerous = remark()
96+
const processorDangerous3 = remark()
10097
.use(
10198
/** @type {import('unified').Plugin<void[], Root>} */
10299
() => (ast) => {
@@ -109,14 +106,14 @@ test('remarkHtml', (t) => {
109106
.use(remarkHtml, {sanitize: false})
110107

111108
t.equal(
112-
processorDangerous
109+
processorDangerous3
113110
.processSync('![hello](example.jpg "overwritten")')
114111
.toString(),
115112
'<p><img src="example.jpg" alt="hello" title="overwrite"></p>\n',
116113
'should patch and merge attributes'
117114
)
118115

119-
processorDangerous = remark()
116+
const processorDangerous4 = remark()
120117
.use(
121118
/** @type {import('unified').Plugin<void[], Root>} */
122119
() => (ast) => {
@@ -127,12 +124,12 @@ test('remarkHtml', (t) => {
127124
.use(remarkHtml, {sanitize: false})
128125

129126
t.equal(
130-
processorDangerous.processSync('**Bold!**').toString(),
127+
processorDangerous4.processSync('**Bold!**').toString(),
131128
'<p><b>Bold!</b></p>\n',
132129
'should overwrite a tag-name'
133130
)
134131

135-
processorDangerous = remark()
132+
const processorDangerous5 = remark()
136133
.use(
137134
/** @type {import('unified').Plugin<void[], Root>} */
138135
() => (ast) => {
@@ -154,12 +151,12 @@ test('remarkHtml', (t) => {
154151
.use(remarkHtml, {sanitize: false})
155152

156153
t.equal(
157-
processorDangerous.processSync('`var`').toString(),
154+
processorDangerous5.processSync('`var`').toString(),
158155
'<p><code><span class="token">var</span></code></p>\n',
159156
'should overwrite content'
160157
)
161158

162-
processorDangerous = remark()
159+
const processorDangerous6 = remark()
163160
.use(
164161
/** @type {import('unified').Plugin<void[], Root>} */
165162
() => (ast) => {
@@ -181,12 +178,12 @@ test('remarkHtml', (t) => {
181178
.use(remarkHtml, {sanitize: true})
182179

183180
t.equal(
184-
processorDangerous.processSync('`var`').toString(),
181+
processorDangerous6.processSync('`var`').toString(),
185182
'<p><code>var</code></p>\n',
186183
'should not overwrite content in `sanitize` mode'
187184
)
188185

189-
processorDangerous = remark()
186+
const processorDangerous7 = remark()
190187
.use(
191188
/** @type {import('unified').Plugin<void[], Root>} */
192189
() => (ast) => {
@@ -198,7 +195,7 @@ test('remarkHtml', (t) => {
198195
.use(remarkHtml, {sanitize: false})
199196

200197
t.equal(
201-
processorDangerous.processSync('```js\nvar\n```\n').toString(),
198+
processorDangerous7.processSync('```js\nvar\n```\n').toString(),
202199
'<pre><code class="foo">var\n</code></pre>\n',
203200
'should overwrite classes on code'
204201
)

test/integrations/footnotes/output.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
99
<ol>
1010
<li id="user-content-fn-1">
11-
<p>Here is the footnote. <a href="#user-content-fnref-1" data-footnote-backref class="data-footnote-backref" aria-label="Back to content"></a></p>
11+
<p>Here is the footnote. <a href="#user-content-fnref-1" data-footnote-backref="" aria-label="Back to reference 1" class="data-footnote-backref"></a></p>
1212
</li>
1313
<li id="user-content-fn-longnote">
1414
<p>Here’s one with multiple blocks.</p>
@@ -18,7 +18,7 @@
1818
</code></pre>
1919
<p>The whole paragraph can be indented, or just the first
2020
line. In this way, multi-paragraph footnotes work like
21-
multi-paragraph list items. <a href="#user-content-fnref-longnote" data-footnote-backref class="data-footnote-backref" aria-label="Back to content"></a></p>
21+
multi-paragraph list items. <a href="#user-content-fnref-longnote" data-footnote-backref="" aria-label="Back to reference 2" class="data-footnote-backref"></a></p>
2222
</li>
2323
</ol>
2424
</section>

0 commit comments

Comments
 (0)