1- 'use strict'
2-
3- var repeat = require ( 'repeat-string' )
4- var convert = require ( 'hast-util-is-element/convert' )
5- var findAfter = require ( 'unist-util-find-after' )
6-
7- module . exports = toText
1+ import repeat from 'repeat-string'
2+ import { convertElement } from 'hast-util-is-element'
3+ import { findAfter } from 'unist-util-find-after'
84
95var searchLineFeeds = / \n / g
106var searchTabOrSpaces = / [ \t ] + / g
117
12- var br = convert ( 'br' )
13- var p = convert ( 'p' )
14- var cell = convert ( [ 'th' , 'td' ] )
15- var row = convert ( 'tr' )
8+ var br = convertElement ( 'br' )
9+ var p = convertElement ( 'p' )
10+ var cell = convertElement ( [ 'th' , 'td' ] )
11+ var row = convertElement ( 'tr' )
1612
1713// Note that we don’t need to include void elements here as they don’t have text.
1814// See: <https://github.com/wooorm/html-void-elements>
19- var notRendered = convert ( [
15+ var notRendered = convertElement ( [
2016 // List from: <https://html.spec.whatwg.org/#hidden-elements>
2117 'datalist' ,
2218 'head' ,
@@ -35,7 +31,7 @@ var notRendered = convert([
3531] )
3632
3733// See: <https://html.spec.whatwg.org/#the-css-user-agent-style-sheet-and-presentational-hints>
38- var blockOrCaption = convert ( [
34+ var blockOrCaption = convertElement ( [
3935 'address' , // Flow content
4036 'article' , // Sections and headings
4137 'aside' , // Sections and headings
@@ -81,10 +77,10 @@ var blockOrCaption = convert([
8177// <https://html.spec.whatwg.org/#the-innertext-idl-attribute>
8278// Note that we act as if `node` is being rendered, and as if we’re a
8379// CSS-supporting user agent.
84- function toText ( node ) {
80+ export function toText ( node ) {
8581 var children = node . children || [ ]
8682 var block = blockOrCaption ( node )
87- var whiteSpace = inferWhiteSpace ( node , { } )
83+ var whitespace = inferWhitespace ( node , { } )
8884 var index = - 1
8985 var results
9086 var result
@@ -101,7 +97,7 @@ function toText(node) {
10197 // ignored.
10298 if ( node . type === 'text' || node . type === 'comment' ) {
10399 return collectText ( node , {
104- whiteSpace : whiteSpace ,
100+ whitespace ,
105101 breakBefore : true ,
106102 breakAfter : true
107103 } )
@@ -129,7 +125,7 @@ function toText(node) {
129125 // 3.2. For each item item in current, append item to results.
130126 results = results . concat (
131127 innerTextCollection ( children [ index ] , index , node , {
132- whiteSpace : whiteSpace ,
128+ whitespace ,
133129 breakBefore : index ? null : block ,
134130 breakAfter :
135131 index < children . length - 1 ? br ( children [ index + 1 ] ) : block
@@ -171,7 +167,7 @@ function innerTextCollection(node, index, parent, options) {
171167
172168 if ( node . type === 'text' ) {
173169 return [
174- options . whiteSpace === 'normal'
170+ options . whitespace === 'normal'
175171 ? collectText ( node , options )
176172 : collectPreText ( node , options )
177173 ]
@@ -183,7 +179,7 @@ function innerTextCollection(node, index, parent, options) {
183179// Collect an element.
184180function collectElement ( node , _ , parent , options ) {
185181 // First we infer the `white-space` property.
186- var whiteSpace = inferWhiteSpace ( node , options )
182+ var whitespace = inferWhitespace ( node , options )
187183 var children = node . children || [ ]
188184 var index = - 1
189185 var items = [ ]
@@ -249,7 +245,7 @@ function collectElement(node, _, parent, options) {
249245 while ( ++ index < children . length ) {
250246 items = items . concat (
251247 innerTextCollection ( children [ index ] , index , node , {
252- whiteSpace : whiteSpace ,
248+ whitespace ,
253249 breakBefore : index ? null : prefix ,
254250 breakAfter :
255251 index < children . length - 1 ? br ( children [ index + 1 ] ) : suffix
@@ -313,7 +309,7 @@ function collectText(node, options) {
313309 // they were not there.
314310 value
315311 . slice ( start , end )
316- . replace ( / [ \u061c \u200e \u200f \u202a - \u202e \u2066 - \u2069 ] / g, '' ) ,
312+ . replace ( / [ \u061C \u200E \u200F \u202A - \u202E \u2066 - \u2069 ] / g, '' ) ,
317313 options . breakBefore ,
318314 options . breakAfter
319315 )
@@ -411,9 +407,9 @@ function trimAndcollapseSpacesAndTabs(value, breakBefore, breakAfter) {
411407}
412408
413409// We don’t support void elements here (so `nobr wbr` -> `normal` is ignored).
414- function inferWhiteSpace ( node , options ) {
410+ function inferWhitespace ( node , options ) {
415411 var props = node . properties || { }
416- var inherit = options . whiteSpace || 'normal'
412+ var inherit = options . whitespace || 'normal'
417413
418414 switch ( node . tagName ) {
419415 case 'listing' :
0 commit comments