parse5-plain-text-conversion-stream 5.1.1 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/index.d.ts +27 -0
- package/dist/index.js +38 -0
- package/package.json +12 -7
- package/lib/index.js +0 -21
package/README.md
CHANGED
|
@@ -15,9 +15,8 @@
|
|
|
15
15
|
</div>
|
|
16
16
|
<br>
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
<p align="center">
|
|
20
|
-
📖 <a href="https://
|
|
19
|
+
📖 <a href="https://parse5.js.org/modules/parse5_plain_text_conversion_stream.html"><b>Documentation</b></a> 📖
|
|
21
20
|
</p>
|
|
22
21
|
|
|
23
22
|
---
|
|
@@ -31,5 +30,5 @@
|
|
|
31
30
|
</p>
|
|
32
31
|
|
|
33
32
|
<p align="center">
|
|
34
|
-
<a href="https://github.com/inikulin/parse5/
|
|
33
|
+
<a href="https://github.com/inikulin/parse5/releases">Changelog</a>
|
|
35
34
|
</p>
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ParserOptions, type TreeAdapterTypeMap } from 'parse5';
|
|
2
|
+
import { ParserStream } from 'parse5-parser-stream';
|
|
3
|
+
/**
|
|
4
|
+
* Converts plain text files into HTML document as required by [HTML specification](https://html.spec.whatwg.org/#read-text).
|
|
5
|
+
* A [writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* const PlainTextConversionStream = require('parse5-plain-text-conversion-stream');
|
|
11
|
+
* const fs = require('fs');
|
|
12
|
+
* const { finished } = require('node:stream');
|
|
13
|
+
*
|
|
14
|
+
* const file = fs.createReadStream('war_and_peace.txt');
|
|
15
|
+
* const converter = new PlainTextConversionStream();
|
|
16
|
+
*
|
|
17
|
+
* finished(converter, () => {
|
|
18
|
+
* console.log(converter.document.childNodes[1].childNodes[0].tagName); //> 'head'
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* file.pipe(converter);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class PlainTextConversionStream<T extends TreeAdapterTypeMap> extends ParserStream<T> {
|
|
25
|
+
constructor(options?: ParserOptions<T>);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { html } from 'parse5';
|
|
2
|
+
import { ParserStream } from 'parse5-parser-stream';
|
|
3
|
+
const { TAG_ID: $, TAG_NAMES: TN } = html;
|
|
4
|
+
/**
|
|
5
|
+
* Converts plain text files into HTML document as required by [HTML specification](https://html.spec.whatwg.org/#read-text).
|
|
6
|
+
* A [writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```js
|
|
11
|
+
* const PlainTextConversionStream = require('parse5-plain-text-conversion-stream');
|
|
12
|
+
* const fs = require('fs');
|
|
13
|
+
* const { finished } = require('node:stream');
|
|
14
|
+
*
|
|
15
|
+
* const file = fs.createReadStream('war_and_peace.txt');
|
|
16
|
+
* const converter = new PlainTextConversionStream();
|
|
17
|
+
*
|
|
18
|
+
* finished(converter, () => {
|
|
19
|
+
* console.log(converter.document.childNodes[1].childNodes[0].tagName); //> 'head'
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* file.pipe(converter);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export class PlainTextConversionStream extends ParserStream {
|
|
26
|
+
constructor(options) {
|
|
27
|
+
super(options);
|
|
28
|
+
// NOTE: see https://html.spec.whatwg.org/#read-text
|
|
29
|
+
this.parser._insertFakeElement(TN.HTML, $.HTML);
|
|
30
|
+
this.parser._insertFakeElement(TN.HEAD, $.HEAD);
|
|
31
|
+
this.parser.openElements.pop();
|
|
32
|
+
this.parser._insertFakeElement(TN.BODY, $.BODY);
|
|
33
|
+
this.parser._insertFakeElement(TN.PRE, $.PRE);
|
|
34
|
+
this.parser.treeAdapter.insertText(this.parser.openElements.current, '\n');
|
|
35
|
+
this.parser.switchToPlaintextParsing();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parse5-plain-text-conversion-stream",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"description": "Stream that converts plain text files into HTML document.",
|
|
4
|
-
"version": "
|
|
5
|
+
"version": "7.0.0",
|
|
5
6
|
"author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)",
|
|
6
7
|
"contributors": "https://github.com/inikulin/parse5/graphs/contributors",
|
|
7
8
|
"homepage": "https://github.com/inikulin/parse5",
|
|
9
|
+
"funding": "https://github.com/inikulin/parse5?sponsor=1",
|
|
8
10
|
"keywords": [
|
|
9
11
|
"parse5",
|
|
10
12
|
"parser",
|
|
@@ -15,17 +17,20 @@
|
|
|
15
17
|
"plain text"
|
|
16
18
|
],
|
|
17
19
|
"license": "MIT",
|
|
18
|
-
"main": "
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"module": "dist/index.js",
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"exports": "./dist/index.js",
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"parse5": "^
|
|
21
|
-
"parse5-parser-stream": "^
|
|
25
|
+
"parse5": "^7.0.0",
|
|
26
|
+
"parse5-parser-stream": "^7.0.0"
|
|
22
27
|
},
|
|
23
28
|
"repository": {
|
|
24
29
|
"type": "git",
|
|
25
30
|
"url": "git://github.com/inikulin/parse5.git"
|
|
26
31
|
},
|
|
27
32
|
"files": [
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
"dist",
|
|
34
|
+
"!*.map"
|
|
35
|
+
]
|
|
31
36
|
}
|
package/lib/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ParserStream = require('parse5-parser-stream');
|
|
4
|
-
const $ = require('parse5/lib/common/html').TAG_NAMES;
|
|
5
|
-
|
|
6
|
-
class PlainTextConversionStream extends ParserStream {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
super(options);
|
|
9
|
-
|
|
10
|
-
// NOTE: see https://html.spec.whatwg.org/#read-text
|
|
11
|
-
this.parser._insertFakeElement($.HTML);
|
|
12
|
-
this.parser._insertFakeElement($.HEAD);
|
|
13
|
-
this.parser.openElements.pop();
|
|
14
|
-
this.parser._insertFakeElement($.BODY);
|
|
15
|
-
this.parser._insertFakeElement($.PRE);
|
|
16
|
-
this.parser.treeAdapter.insertText(this.parser.openElements.current, '\n');
|
|
17
|
-
this.parser.switchToPlaintextParsing();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = PlainTextConversionStream;
|