3
3
[ ![ Build] [ build-badge ]] [ build ]
4
4
[ ![ Coverage] [ coverage-badge ]] [ coverage ]
5
5
[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
+ [ ![ Size] [ size-badge ]] [ size ]
7
+ [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8
+ [ ![ Backers] [ backers-badge ]] [ collective ]
6
9
[ ![ Chat] [ chat-badge ]] [ chat ]
7
10
8
- Set the plain-text value of a [ hast] [ ] node.
11
+ [ ** hast** ] [ hast ] utility to get the plain-text value of a [ * node* ] [ node ] .
12
+
9
13
This is like the DOMs ` Node#innerText ` setter.
10
- The given node is returned.
11
14
12
15
You’d typically want to use [ ` hast-util-from-string ` ] [ from-string ]
13
16
(` textContent ` ), but ` hast-util-from-text ` (` innerText ` ) adds ` <br> ` elements
14
17
instead of line breaks.
15
18
16
- ## Installation
19
+ ## Install
17
20
18
21
[ npm] [ ] :
19
22
20
- ``` bash
23
+ ``` sh
21
24
npm install hast-util-from-text
22
25
```
23
26
24
27
## Usage
25
28
26
- ``` javascript
29
+ ``` js
27
30
var h = require (' hastscript' )
28
31
var fromText = require (' hast-util-from-text' )
29
32
@@ -53,28 +56,33 @@ fromText(h('p'), 'Delta\nEcho')
53
56
54
57
### ` fromText(node[, value]) `
55
58
56
- If ` node ` is a literal (has a ` value ` property), set that to the given ` value `
57
- or an empty string.
58
- If ` node ` is a parent node (has ` children ` ), its children are replaced with new
59
- children: text nodes for every run of text and ` <br> ` elements for every line
60
- break (` \n ` , ` \r ` , or ` \r\n ` ).
61
- If no ` value ` is given (empty string ` '' ` , ` null ` , or ` undefined ` ), all
62
- children are removed.
59
+ If the given ` node ` is a [ * literal* ] [ literal ] , set that to the given ` value ` or
60
+ an empty string.
61
+ If the given ` node ` is a [ * parent* ] [ parent ] , its [ * children* ] [ child ] are
62
+ replaced with new children: [ * texts* ] [ text ] for every run of text and ` <br> `
63
+ [ * elements* ] [ element ] for every line break (a line feed, ` \n ` ; a carriage
64
+ return, ` \r ` ; or a carriage return + line feed, ` \r\n ` ).
65
+ If no ` value ` is given (empty string ` '' ` , ` null ` , or ` undefined ` ), the
66
+ literal’s value is set to an empty string or the parent’s children are removed.
63
67
64
68
## Related
65
69
66
- * [ ` hast-util-from-string ` ] ( https://github.com/rehypejs/rehype-minify/ tree/master/packages/ hast-util-from-string )
67
- — Set the plain-text value (` textContent ` )
70
+ * [ ` hast-util-to-text ` ] ( https://github.com/syntax- tree/hast-util-to-text )
71
+ — Get the plain-text value (` innerText ` )
68
72
* [ ` hast-util-to-string ` ] ( https://github.com/rehypejs/rehype-minify/tree/master/packages/hast-util-to-string )
69
73
— Get the plain-text value (` textContent ` )
74
+ * [ ` hast-util-from-string ` ] [ from-string ]
75
+ — Set the plain-text value (` textContent ` )
70
76
71
77
## Contribute
72
78
73
- See [ ` contributing.md ` in ` syntax-tree/hast ` ] [ contributing ] for ways to get
79
+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
74
80
started.
81
+ See [ ` support.md ` ] [ support ] for ways to get help.
75
82
76
- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
77
- repository, organisation, or community you agree to abide by its terms.
83
+ This project has a [ Code of Conduct] [ coc ] .
84
+ By interacting with this repository, organisation, or community you agree to
85
+ abide by its terms.
78
86
79
87
## License
80
88
@@ -94,20 +102,44 @@ repository, organisation, or community you agree to abide by its terms.
94
102
95
103
[ downloads ] : https://www.npmjs.com/package/hast-util-from-text
96
104
105
+ [ size-badge ] : https://img.shields.io/bundlephobia/minzip/hast-util-from-text.svg
106
+
107
+ [ size ] : https://bundlephobia.com/result?p=hast-util-from-text
108
+
109
+ [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
110
+
111
+ [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
112
+
113
+ [ collective ] : https://opencollective.com/unified
114
+
97
115
[ chat-badge ] : https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
98
116
99
- [ chat ] : https://spectrum.chat/unified/rehype
117
+ [ chat ] : https://spectrum.chat/unified/syntax-tree
100
118
101
119
[ npm ] : https://docs.npmjs.com/cli/install
102
120
103
121
[ license ] : license
104
122
105
123
[ author ] : https://wooorm.com
106
124
107
- [ hast ] : https://github.com/syntax-tree/hast
125
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
108
126
109
- [ contributing ] : https://github.com/syntax-tree/hast /blob/master/contributing .md
127
+ [ support ] : https://github.com/syntax-tree/.github /blob/master/support .md
110
128
111
- [ coc ] : https://github.com/syntax-tree/hast /blob/master/code-of-conduct.md
129
+ [ coc ] : https://github.com/syntax-tree/.github /blob/master/code-of-conduct.md
112
130
113
131
[ from-string ] : https://github.com/rehypejs/rehype-minify/tree/master/packages/hast-util-from-string
132
+
133
+ [ literal ] : https://github.com/syntax-tree/unist#literal
134
+
135
+ [ parent ] : https://github.com/syntax-tree/unist#parent
136
+
137
+ [ child ] : https://github.com/syntax-tree/unist#child
138
+
139
+ [ hast ] : https://github.com/syntax-tree/hast
140
+
141
+ [ node ] : https://github.com/syntax-tree/hast#nodes
142
+
143
+ [ text ] : https://github.com/syntax-tree/hast#text
144
+
145
+ [ element ] : https://github.com/syntax-tree/hast#element
0 commit comments