Skip to content

Commit 30914d4

Browse files
committed
Remove line breaks in attrs
1 parent bf42858 commit 30914d4

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

README.md

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
### Forked only to change regex that parses attributes to allow the `_` attribute key used by Hyperscript. Literally ONE character changed.
1+
### Forked only to changes regex that parses attributes to allow the `_` attribute key used by Hyperscript. Also allowing for attribute values with line breaks.
22

33
# Fast HTML Parser [![NPM version](https://badge.fury.io/js/node-html-parser.png)](http://badge.fury.io/js/node-html-parser) [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Ftaoqf%2Fnode-html-parser%2Fbadge%3Fref%3Dmain&style=flat)](https://actions-badge.atrox.dev/taoqf/node-html-parser/goto?ref=main)
44

55
Fast HTML Parser is a _very fast_ HTML parser. Which will generate a simplified
66
DOM tree, with element query support.
77

88
Per the design, it intends to parse massive HTML files in lowest price, thus the
9-
performance is the top priority. For this reason, some malformatted HTML may not
9+
performance is the top priority. For this reason, some malformatted HTML may not
1010
be able to parse correctly, but most usual errors are covered (eg. HTML4 style
1111
no closing `<li>`, `<td>` etc).
1212

1313
## Install
1414

15-
1615
```shell
1716
npm install --save node-html-parser
1817
```
@@ -62,7 +61,7 @@ console.log(root.querySelector('#list'));
6261
console.log(root.toString());
6362
// <ul id="list"><li>Hello World</li></ul>
6463
root.set_content('<li>Hello World</li>');
65-
root.toString(); // <li>Hello World</li>
64+
root.toString(); // <li>Hello World</li>
6665
```
6766

6867
```js
@@ -77,21 +76,21 @@ var root = HTMLParser.parse('<ul id="list"><li>Hello World</li></ul>');
7776

7877
Parse the data provided, and return the root of the generated DOM.
7978

80-
- **data**, data to parse
81-
- **options**, parse options
82-
83-
```js
84-
{
85-
lowerCaseTagName: false, // convert tag name to lower case (hurts performance heavily)
86-
comment: false, // retrieve comments (hurts performance slightly)
87-
blockTextElements: {
88-
script: true, // keep text content when parsing
89-
noscript: true, // keep text content when parsing
90-
style: true, // keep text content when parsing
91-
pre: true // keep text content when parsing
79+
- **data**, data to parse
80+
- **options**, parse options
81+
82+
```js
83+
{
84+
lowerCaseTagName: false, // convert tag name to lower case (hurts performance heavily)
85+
comment: false, // retrieve comments (hurts performance slightly)
86+
blockTextElements: {
87+
script: true, // keep text content when parsing
88+
noscript: true, // keep text content when parsing
89+
style: true, // keep text content when parsing
90+
pre: true // keep text content when parsing
91+
}
9292
}
93-
}
94-
```
93+
```
9594

9695
### valid(data[, options])
9796

@@ -121,7 +120,7 @@ Query CSS Selector to find matching node.
121120

122121
Get all elements with the specified tagName.
123122

124-
Note: Use * for all elements.
123+
Note: Use \* for all elements.
125124

126125
### HTMLElement#closest(selector)
127126

src/nodes/html.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ export default class HTMLElement extends Node {
157157
if (attr == null) {
158158
return 'null';
159159
}
160-
161-
return JSON.stringify(attr.replace(/"/g, '&quot;'));
160+
return JSON.stringify(attr.replace(/"/g, '&quot;').replace(/\s\s+/g, ' '));
162161
}
163162

164163
/**

0 commit comments

Comments
 (0)