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
}

lib/handlers/text.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.
@@ -16,7 +14,7 @@ import {wrapText} from '../util/wrap-text.js'
1614
*/
1715
export function text(state, node) {
1816
/** @type {MdastText} */
19-
const result = {type: 'text', value: wrapText(state, node.value)}
17+
const result = {type: 'text', value: node.value}
2018
state.patch(node, result)
2119
return result
2220
}

lib/handlers/textarea.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 textarea(state, node) {
1918
/** @type {Text} */
20-
const result = {type: 'text', value: wrapText(state, toText(node))}
19+
const result = {type: 'text', value: toText(node)}
2120
state.patch(node, result)
2221
return result
2322
}

lib/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export function toMdast(tree, options) {
4646
: handlers,
4747
baseFound: false,
4848
inTable: false,
49-
wrapText: true,
5049
frozenBaseUrl: undefined,
5150
qNesting: 0
5251
}

lib/one.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515

1616
import {all} from './all.js'
17-
import {wrapText} from './util/wrap-text.js'
1817

1918
export const own = {}.hasOwnProperty
2019

@@ -62,7 +61,7 @@ export function one(state, node, parent) {
6261
function unknown(state, node) {
6362
if ('value' in node && typeof node.value === 'string') {
6463
/** @type {MdastContent} */
65-
const result = {type: 'text', value: wrapText(state, node.value)}
64+
const result = {type: 'text', value: node.value}
6665
state.patch(node, result)
6766
return result
6867
}

lib/types.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363
* Whether a `<base>` element was seen.
6464
* @property {string | undefined} frozenBaseUrl
6565
* `href` of `<base>`, if any.
66-
* @property {boolean} wrapText
67-
* To do: remove.
6866
* @property {boolean} inTable
6967
* Whether we’re in a table.
7068
* @property {number} qNesting

lib/util/find-selected-options.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515

1616
import {toText} from 'hast-util-to-text'
17-
import {wrapText} from './wrap-text.js'
1817

1918
/**
2019
* @param {State} state
@@ -52,7 +51,7 @@ export function findSelectedOptions(state, node, properties) {
5251
while (++index < max) {
5352
const option = list[index]
5453
const props = option.properties || {}
55-
const content = wrapText(state, toText(option))
54+
const content = toText(option)
5655
const label = content || String(props.label || '')
5756
const value = String(props.value || '') || content
5857
values.push([value, label === value ? undefined : label])

lib/util/wrap-text.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/fixtures/br/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
alpha\
22
bravo
33

4-
charlie
5-
delta
4+
```
5+
charlie
6+
delta
7+
```
68

79
echo
810

test/fixtures/figure-figcaption/index.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ Fig1. - A view of the pulpit rock in Norway.
44

55
Get browser details using navigator
66

7-
function example() {
8-
var txt;
9-
txt = "Browser CodeName: " + navigator.appCodeName;
10-
txt+= "Browser Name: " + navigator.appName;
11-
txt+= "Browser Version: " + navigator.appVersion ;
12-
txt+= "Cookies Enabled: " + navigator.cookieEnabled;
13-
txt+= "Platform: " + navigator.platform;
14-
txt+= "User-agent header: " + navigator.userAgent;
15-
}
7+
```
8+
function example() {
9+
var txt;
10+
txt = "Browser CodeName: " + navigator.appCodeName;
11+
txt+= "Browser Name: " + navigator.appName;
12+
txt+= "Browser Version: " + navigator.appVersion ;
13+
txt+= "Cookies Enabled: " + navigator.cookieEnabled;
14+
txt+= "Platform: " + navigator.platform;
15+
txt+= "User-agent header: " + navigator.userAgent;
16+
}
17+
```
1618

1719
Edsger Dijkstra:
1820

test/fixtures/listing/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ alpha();
66
bravo();
77
```
88

9-
109
```
1110
charlie delta(); echo
1211
```
@@ -20,11 +19,10 @@ hotel(); india
2019
```
2120

2221
```
23-
2422
```
2523

2624
```
27-
juliett·
25+
juliett
2826
kilo();
2927
lima
3028
```

0 commit comments

Comments
 (0)