Skip to content

Commit c2fab89

Browse files
committed
Remove wrapText
This was originally added for GH-58, but `mdast-util-to-markdown` (`remark-stringify`) now solves this, much better.
1 parent 380b71b commit c2fab89

File tree

26 files changed

+89
-121
lines changed

26 files changed

+89
-121
lines changed

lib/handlers/br.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* @typedef {import('hast').Element} Element
33
* @typedef {import('mdast').Break} Break
4-
* @typedef {import('mdast').Text} Text
54
* @typedef {import('../types.js').State} State
65
*/
76

@@ -10,12 +9,12 @@
109
* State.
1110
* @param {Element} node
1211
* hast element to transform.
13-
* @returns {Break | Text}
12+
* @returns {Break}
1413
* mdast node.
1514
*/
1615
export function br(state, node) {
17-
/** @type {Break | Text} */
18-
const result = state.wrapText ? {type: 'break'} : {type: 'text', value: ' '}
16+
/** @type {Break} */
17+
const result = {type: 'break'}
1918
state.patch(node, result)
2019
return result
2120
}

lib/handlers/code.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import {toText} from 'hast-util-to-text'
88
import {trimTrailingLines} from 'trim-trailing-lines'
9-
import {wrapText} from '../util/wrap-text.js'
109

1110
const prefix = 'language-'
1211

@@ -59,7 +58,7 @@ export function code(state, node) {
5958
type: 'code',
6059
lang: lang || null,
6160
meta: null,
62-
value: trimTrailingLines(wrapText(state, toText(node)))
61+
value: trimTrailingLines(toText(node))
6362
}
6463
state.patch(node, result)
6564
return result

lib/handlers/comment.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @typedef {import('../types.js').State} State
55
*/
66

7-
import {wrapText} from '../util/wrap-text.js'
8-
97
/**
108
* @param {State} state
119
* State.
@@ -18,7 +16,7 @@ export function comment(state, node) {
1816
/** @type {HTML} */
1917
const result = {
2018
type: 'html',
21-
value: '<!--' + wrapText(state, node.value) + '-->'
19+
value: '<!--' + node.value + '-->'
2220
}
2321
state.patch(node, result)
2422
return result

lib/handlers/heading.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,14 @@ import {all} from '../all.js'
1717
export function heading(state, node) {
1818
/* c8 ignore next */
1919
const depth = Number(node.tagName.charAt(1)) || 1
20-
const wrap = state.wrapText
21-
22-
// To do: next major.
23-
// To do: `mdast-util-to-markdown` should support breaks currently.
24-
state.wrapText = false
25-
const children = all(state, node)
26-
state.wrapText = wrap
2720

2821
/** @type {Heading} */
2922
const result = {
3023
type: 'heading',
3124
// @ts-expect-error: fine.
3225
depth,
3326
// @ts-expect-error: assume valid children.
34-
children
27+
children: all(state, node)
3528
}
3629
state.patch(node, result)
3730
return result

lib/handlers/iframe.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import {resolve} from '../util/resolve.js'
8-
import {wrapText} from '../util/wrap-text.js'
98

109
/**
1110
* @param {State} state
@@ -30,7 +29,7 @@ export function iframe(state, node) {
3029
type: 'link',
3130
title: null,
3231
url: resolve(state, src),
33-
children: [{type: 'text', value: wrapText(state, title)}]
32+
children: [{type: 'text', value: title}]
3433
}
3534
state.patch(node, result)
3635
return result

lib/handlers/inline-code.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import {toText} from 'hast-util-to-text'
8-
import {wrapText} from '../util/wrap-text.js'
98

109
/**
1110
* @param {State} state
@@ -17,7 +16,7 @@ import {wrapText} from '../util/wrap-text.js'
1716
*/
1817
export function inlineCode(state, node) {
1918
/** @type {InlineCode} */
20-
const result = {type: 'inlineCode', value: wrapText(state, toText(node))}
19+
const result = {type: 'inlineCode', value: toText(node)}
2120
state.patch(node, result)
2221
return result
2322
}

lib/handlers/input.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import {findSelectedOptions} from '../util/find-selected-options.js'
1111
import {resolve} from '../util/resolve.js'
12-
import {wrapText} from '../util/wrap-text.js'
1312

1413
const defaultChecked = '[x]'
1514
const defaultUnchecked = '[ ]'
@@ -39,12 +38,9 @@ export function input(state, node) {
3938
/** @type {Text} */
4039
const result = {
4140
type: 'text',
42-
value: wrapText(
43-
state,
44-
properties.checked
45-
? state.options.checked || defaultChecked
46-
: state.options.unchecked || defaultUnchecked
47-
)
41+
value: properties.checked
42+
? state.options.checked || defaultChecked
43+
: state.options.unchecked || defaultUnchecked
4844
}
4945
state.patch(node, result)
5046
return result
@@ -58,8 +54,8 @@ export function input(state, node) {
5854
const result = {
5955
type: 'image',
6056
url: resolve(state, String(properties.src || '') || null),
61-
title: wrapText(state, String(properties.title || '')) || null,
62-
alt: wrapText(state, String(alt))
57+
title: String(properties.title || '') || null,
58+
alt: String(alt)
6359
}
6460
state.patch(node, result)
6561
return result
@@ -111,13 +107,8 @@ export function input(state, node) {
111107
const result = {
112108
type: 'link',
113109
title: null,
114-
url: wrapText(
115-
state,
116-
properties.type === 'email' ? 'mailto:' + value : value
117-
),
118-
children: [
119-
{type: 'text', value: wrapText(state, values[index][1] || value)}
120-
]
110+
url: properties.type === 'email' ? 'mailto:' + value : value,
111+
children: [{type: 'text', value: values[index][1] || value}]
121112
}
122113

123114
results.push(result)
@@ -143,7 +134,7 @@ export function input(state, node) {
143134
}
144135

145136
/** @type {Text} */
146-
const result = {type: 'text', value: wrapText(state, texts.join(', '))}
137+
const result = {type: 'text', value: texts.join(', ')}
147138
state.patch(node, result)
148139
return result
149140
}

lib/handlers/select.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import {findSelectedOptions} from '../util/find-selected-options.js'
8-
import {wrapText} from '../util/wrap-text.js'
98

109
/**
1110
* @param {State} state
@@ -28,7 +27,7 @@ export function select(state, node) {
2827

2928
if (results.length > 0) {
3029
/** @type {Text} */
31-
const result = {type: 'text', value: wrapText(state, results.join(', '))}
30+
const result = {type: 'text', value: results.join(', ')}
3231
state.patch(node, result)
3332
return result
3433
}

lib/handlers/table-cell.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ import {all} from '../all.js'
1515
* mdast node.
1616
*/
1717
export function tableCell(state, node) {
18-
const wrap = state.wrapText
19-
state.wrapText = false
2018
const children = all(state, node)
21-
state.wrapText = wrap
2219

2320
/** @type {TableCell} */
2421
const result = {

lib/handlers/table.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import {toText} from 'hast-util-to-text'
2121
import {visit, SKIP} from 'unist-util-visit'
22-
import {wrapText} from '../util/wrap-text.js'
2322
import {all} from '../all.js'
2423

2524
/**
@@ -35,7 +34,7 @@ export function table(state, node) {
3534
// Ignore nested tables.
3635
if (state.inTable) {
3736
/** @type {Text} */
38-
const result = {type: 'text', value: wrapText(state, toText(node))}
37+
const result = {type: 'text', value: toText(node)}
3938
state.patch(node, result)
4039
return result
4140
}

0 commit comments

Comments
 (0)