-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremark.mts
46 lines (41 loc) · 1.04 KB
/
remark.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @file dprint - remark
* @module dprint/remark
*/
import { ok } from 'devlop'
import { Transform } from 'node:stream'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import { unified } from 'unified'
import { VFile } from 'vfile'
import remarkPreset from '../.remarkrc.mjs'
process.stdin.pipe(new Transform({
/**
* Formats a file using `remark`.
*
* @see https://github.com/remarkjs/remark
*
* @async
*
* @param {Buffer} buffer
* Data buffer
* @return {Promise<string>}
* Formatted file content
*/
async transform(buffer: Buffer): Promise<string> {
/**
* Virtual file.
*
* @const {VFile} file
*/
const file: VFile = new VFile(buffer.toString())
file.path = process.argv.slice(2)[0]!
await unified()
.use(remarkParse)
.use(remarkPreset)
.use(remarkStringify)
.process(file)
ok(typeof file.value === 'string', 'expected `file.value` to be a string')
return process.stdout.write(file.value), file.value
}
}))