marked 3.0.8 → 4.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 +1 -1
- package/bin/{marked → marked.js} +59 -66
- package/lib/marked.cjs +2913 -0
- package/lib/marked.esm.js +187 -282
- package/lib/marked.js +135 -189
- package/man/marked.1 +5 -24
- package/man/marked.1.txt +21 -31
- package/marked.min.js +1 -1
- package/package.json +24 -16
- package/src/Lexer.js +6 -6
- package/src/Parser.js +8 -8
- package/src/Renderer.js +5 -5
- package/src/Slugger.js +2 -2
- package/src/TextRenderer.js +2 -2
- package/src/Tokenizer.js +5 -5
- package/src/defaults.js +5 -9
- package/src/helpers.js +12 -27
- package/src/marked.js +26 -12
- package/src/rules.js +4 -9
- package/src/esm-entry.js +0 -18
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ $ cat hello.html
|
|
|
69
69
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
|
70
70
|
<script>
|
|
71
71
|
document.getElementById('content').innerHTML =
|
|
72
|
-
marked('# Marked in the browser\n\nRendered by **marked**.');
|
|
72
|
+
marked.parse('# Marked in the browser\n\nRendered by **marked**.');
|
|
73
73
|
</script>
|
|
74
74
|
</body>
|
|
75
75
|
</html>
|
package/bin/{marked → marked.js}
RENAMED
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
* Copyright (c) 2011-2013, Christopher Jeffrey (MIT License)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { promises } from 'fs';
|
|
9
|
+
import { marked } from '../lib/marked.esm.js';
|
|
10
|
+
|
|
11
|
+
const { readFile, writeFile } = promises;
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Man Page
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
|
-
function help() {
|
|
17
|
-
const spawn =
|
|
17
|
+
async function help() {
|
|
18
|
+
const { spawn } = await import('child_process');
|
|
18
19
|
|
|
19
20
|
const options = {
|
|
20
21
|
cwd: process.cwd(),
|
|
@@ -23,16 +24,18 @@ function help() {
|
|
|
23
24
|
stdio: 'inherit'
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const { dirname, resolve } = await import('path');
|
|
28
|
+
const { fileURLToPath } = await import('url');
|
|
29
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
spawn('man', [resolve(__dirname, '../man/marked.1')], options)
|
|
31
|
+
.on('error', async() => {
|
|
32
|
+
console.log(await readFile(resolve(__dirname, '../man/marked.1.txt'), 'utf8'));
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
function version() {
|
|
36
|
+
async function version() {
|
|
37
|
+
const { createRequire } = await import('module');
|
|
38
|
+
const require = createRequire(import.meta.url);
|
|
36
39
|
const pkg = require('../package.json');
|
|
37
40
|
console.log(pkg.version);
|
|
38
41
|
}
|
|
@@ -41,15 +44,15 @@ function version() {
|
|
|
41
44
|
* Main
|
|
42
45
|
*/
|
|
43
46
|
|
|
44
|
-
function main(argv
|
|
45
|
-
const files = []
|
|
46
|
-
|
|
47
|
-
let input
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
async function main(argv) {
|
|
48
|
+
const files = [];
|
|
49
|
+
const options = {};
|
|
50
|
+
let input;
|
|
51
|
+
let output;
|
|
52
|
+
let string;
|
|
53
|
+
let arg;
|
|
54
|
+
let tokens;
|
|
55
|
+
let opt;
|
|
53
56
|
|
|
54
57
|
function getarg() {
|
|
55
58
|
let arg = argv.shift();
|
|
@@ -82,8 +85,6 @@ function main(argv, callback) {
|
|
|
82
85
|
while (argv.length) {
|
|
83
86
|
arg = getarg();
|
|
84
87
|
switch (arg) {
|
|
85
|
-
case '--test':
|
|
86
|
-
return require('../test').main(process.argv.slice());
|
|
87
88
|
case '-o':
|
|
88
89
|
case '--output':
|
|
89
90
|
output = argv.shift();
|
|
@@ -102,10 +103,10 @@ function main(argv, callback) {
|
|
|
102
103
|
break;
|
|
103
104
|
case '-h':
|
|
104
105
|
case '--help':
|
|
105
|
-
return help();
|
|
106
|
+
return await help();
|
|
106
107
|
case '-v':
|
|
107
108
|
case '--version':
|
|
108
|
-
return version();
|
|
109
|
+
return await version();
|
|
109
110
|
default:
|
|
110
111
|
if (arg.indexOf('--') === 0) {
|
|
111
112
|
opt = camelize(arg.replace(/^--(no-)?/, ''));
|
|
@@ -128,62 +129,57 @@ function main(argv, callback) {
|
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
function getData(
|
|
132
|
+
async function getData() {
|
|
132
133
|
if (!input) {
|
|
133
134
|
if (files.length <= 2) {
|
|
134
135
|
if (string) {
|
|
135
|
-
return
|
|
136
|
+
return string;
|
|
136
137
|
}
|
|
137
|
-
return getStdin(
|
|
138
|
+
return await getStdin();
|
|
138
139
|
}
|
|
139
140
|
input = files.pop();
|
|
140
141
|
}
|
|
141
|
-
return
|
|
142
|
+
return await readFile(input, 'utf8');
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
|
|
145
|
-
if (err) return callback(err);
|
|
145
|
+
const data = await getData();
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
const html = tokens
|
|
148
|
+
? JSON.stringify(marked.lexer(data, options), null, 2)
|
|
149
|
+
: marked(data, options);
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
151
|
+
if (output) {
|
|
152
|
+
return await writeFile(output, data);
|
|
153
|
+
}
|
|
155
154
|
|
|
156
|
-
|
|
157
|
-
});
|
|
155
|
+
process.stdout.write(html + '\n');
|
|
158
156
|
}
|
|
159
157
|
|
|
160
158
|
/**
|
|
161
159
|
* Helpers
|
|
162
160
|
*/
|
|
163
161
|
|
|
164
|
-
function getStdin(
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
function getStdin() {
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
const stdin = process.stdin;
|
|
165
|
+
let buff = '';
|
|
167
166
|
|
|
168
|
-
|
|
167
|
+
stdin.setEncoding('utf8');
|
|
169
168
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
stdin.on('data', function(data) {
|
|
170
|
+
buff += data;
|
|
171
|
+
});
|
|
173
172
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
stdin.on('error', function(err) {
|
|
174
|
+
reject(err);
|
|
175
|
+
});
|
|
177
176
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
stdin.on('end', function() {
|
|
178
|
+
resolve(buff);
|
|
179
|
+
});
|
|
181
180
|
|
|
182
|
-
try {
|
|
183
181
|
stdin.resume();
|
|
184
|
-
}
|
|
185
|
-
callback(e);
|
|
186
|
-
}
|
|
182
|
+
});
|
|
187
183
|
}
|
|
188
184
|
|
|
189
185
|
function camelize(text) {
|
|
@@ -204,12 +200,9 @@ function handleError(err) {
|
|
|
204
200
|
* Expose / Entry Point
|
|
205
201
|
*/
|
|
206
202
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
} else {
|
|
214
|
-
module.exports = main;
|
|
215
|
-
}
|
|
203
|
+
process.title = 'marked';
|
|
204
|
+
main(process.argv.slice()).then(code => {
|
|
205
|
+
process.exit(code || 0);
|
|
206
|
+
}).catch(err => {
|
|
207
|
+
handleError(err);
|
|
208
|
+
});
|