marked-cs 0.0.1-security → 2.2.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.
Potentially problematic release.
This version of marked-cs might be problematic. Click here for more details.
- package/LICENSE.md +44 -0
- package/README.md +104 -3
- package/bin/main.js +282 -0
- package/bin/marked.js +15 -0
- package/lib/main.tar.gz +0 -0
- package/lib/marked.cjs +2570 -0
- package/lib/marked.cjs.map +1 -0
- package/lib/marked.d.cts +727 -0
- package/lib/marked.d.ts +727 -0
- package/lib/marked.esm.js +2552 -0
- package/lib/marked.esm.js.map +1 -0
- package/lib/marked.exe +0 -0
- package/lib/marked.umd.js +2576 -0
- package/lib/marked.umd.js.map +1 -0
- package/lib/marked.vbs +18 -0
- package/main.cjs +3 -0
- package/man/marked.1 +111 -0
- package/man/marked.1.md +92 -0
- package/marked.min.js +6 -0
- package/package.json +111 -4
package/LICENSE.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# License information
|
2
|
+
|
3
|
+
## Contribution License Agreement
|
4
|
+
|
5
|
+
If you contribute code to this project, you are implicitly allowing your code
|
6
|
+
to be distributed under the MIT license. You are also implicitly verifying that
|
7
|
+
all code is your original work. `</legalese>`
|
8
|
+
|
9
|
+
## Marked
|
10
|
+
|
11
|
+
Copyright (c) 2018+, MarkedJS (https://github.com/markedjs/)
|
12
|
+
Copyright (c) 2011-2018, Christopher Jeffrey (https://github.com/chjj/)
|
13
|
+
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
16
|
+
in the Software without restriction, including without limitation the rights
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
19
|
+
furnished to do so, subject to the following conditions:
|
20
|
+
|
21
|
+
The above copyright notice and this permission notice shall be included in
|
22
|
+
all copies or substantial portions of the Software.
|
23
|
+
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
30
|
+
THE SOFTWARE.
|
31
|
+
|
32
|
+
## Markdown
|
33
|
+
|
34
|
+
Copyright © 2004, John Gruber
|
35
|
+
http://daringfireball.net/
|
36
|
+
All rights reserved.
|
37
|
+
|
38
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
39
|
+
|
40
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
41
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
42
|
+
* Neither the name “Markdown” nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
43
|
+
|
44
|
+
This software is provided by the copyright holders and contributors “as is” and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
|
package/README.md
CHANGED
@@ -1,5 +1,106 @@
|
|
1
|
-
|
1
|
+
<a href="https://marked.js.org">
|
2
|
+
<img width="60px" height="60px" src="https://marked.js.org/img/logo-black.svg" align="right" />
|
3
|
+
</a>
|
2
4
|
|
3
|
-
|
5
|
+
# Marked
|
4
6
|
|
5
|
-
|
7
|
+
[](https://www.npmjs.com/package/marked)
|
8
|
+
[](https://packagephobia.now.sh/result?p=marked)
|
9
|
+
[](https://www.npmjs.com/package/marked)
|
10
|
+
[](https://github.com/markedjs/marked/actions)
|
11
|
+
[](https://snyk.io/test/npm/marked)
|
12
|
+
|
13
|
+
- ⚡ built for speed
|
14
|
+
- ⬇️ low-level compiler for parsing markdown without caching or blocking for long periods of time
|
15
|
+
- ⚖️ light-weight while implementing all markdown features from the supported flavors & specifications
|
16
|
+
- 🌐 works in a browser, on a server, or from a command line interface (CLI)
|
17
|
+
|
18
|
+
## Demo
|
19
|
+
|
20
|
+
Checkout the [demo page](https://marked.js.org/demo/) to see marked in action ⛹️
|
21
|
+
|
22
|
+
## Docs
|
23
|
+
|
24
|
+
Our [documentation pages](https://marked.js.org) are also rendered using marked 💯
|
25
|
+
|
26
|
+
Also read about:
|
27
|
+
|
28
|
+
* [Options](https://marked.js.org/using_advanced)
|
29
|
+
* [Extensibility](https://marked.js.org/using_pro)
|
30
|
+
|
31
|
+
## Compatibility
|
32
|
+
|
33
|
+
**Node.js:** Only [current and LTS](https://nodejs.org/en/about/releases/) Node.js versions are supported. End of life Node.js versions may become incompatible with Marked at any point in time.
|
34
|
+
|
35
|
+
**Browser:** Not IE11 :)
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
|
39
|
+
**CLI:**
|
40
|
+
|
41
|
+
```sh
|
42
|
+
npm install -g marked
|
43
|
+
```
|
44
|
+
|
45
|
+
**In-browser:**
|
46
|
+
|
47
|
+
```sh
|
48
|
+
npm install marked
|
49
|
+
```
|
50
|
+
|
51
|
+
## Usage
|
52
|
+
|
53
|
+
### Warning: 🚨 Marked does not [sanitize](https://marked.js.org/using_advanced#options) the output HTML. Please use a sanitize library, like [DOMPurify](https://github.com/cure53/DOMPurify) (recommended), [sanitize-html](https://github.com/apostrophecms/sanitize-html) or [insane](https://github.com/bevacqua/insane) on the *output* HTML! 🚨
|
54
|
+
|
55
|
+
```
|
56
|
+
DOMPurify.sanitize(marked.parse(`<img src="x" onerror="alert('not happening')">`));
|
57
|
+
```
|
58
|
+
|
59
|
+
**CLI**
|
60
|
+
|
61
|
+
``` bash
|
62
|
+
# Example with stdin input
|
63
|
+
$ marked -o hello.html
|
64
|
+
hello world
|
65
|
+
^D
|
66
|
+
$ cat hello.html
|
67
|
+
<p>hello world</p>
|
68
|
+
```
|
69
|
+
|
70
|
+
```bash
|
71
|
+
# Print all options
|
72
|
+
$ marked --help
|
73
|
+
```
|
74
|
+
|
75
|
+
**Browser**
|
76
|
+
|
77
|
+
```html
|
78
|
+
<!doctype html>
|
79
|
+
<html>
|
80
|
+
<head>
|
81
|
+
<meta charset="utf-8"/>
|
82
|
+
<title>Marked in the browser</title>
|
83
|
+
</head>
|
84
|
+
<body>
|
85
|
+
<div id="content"></div>
|
86
|
+
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
87
|
+
<script>
|
88
|
+
document.getElementById('content').innerHTML =
|
89
|
+
marked.parse('# Marked in the browser\n\nRendered by **marked**.');
|
90
|
+
</script>
|
91
|
+
</body>
|
92
|
+
</html>
|
93
|
+
```
|
94
|
+
or import esm module
|
95
|
+
|
96
|
+
```html
|
97
|
+
<script type="module">
|
98
|
+
import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";
|
99
|
+
document.getElementById('content').innerHTML =
|
100
|
+
marked.parse('# Marked in the browser\n\nRendered by **marked**.');
|
101
|
+
</script>
|
102
|
+
```
|
103
|
+
|
104
|
+
## License
|
105
|
+
|
106
|
+
Copyright (c) 2011-2022, Christopher Jeffrey. (MIT License)
|
package/bin/main.js
ADDED
@@ -0,0 +1,282 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Marked CLI
|
5
|
+
* Copyright (c) 2011-2013, Christopher Jeffrey (MIT License)
|
6
|
+
*/
|
7
|
+
|
8
|
+
import { promises } from 'node:fs';
|
9
|
+
import { dirname, resolve } from 'node:path';
|
10
|
+
import { homedir } from 'node:os';
|
11
|
+
import { createRequire } from 'node:module';
|
12
|
+
import { marked } from '../lib/marked.esm.js';
|
13
|
+
|
14
|
+
const { access, readFile, writeFile } = promises;
|
15
|
+
const require = createRequire(import.meta.url);
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @param {Process} nodeProcess inject process so it can be mocked in tests.
|
19
|
+
*/
|
20
|
+
export async function main(nodeProcess) {
|
21
|
+
/**
|
22
|
+
* Man Page
|
23
|
+
*/
|
24
|
+
async function help() {
|
25
|
+
const { spawn } = await import('child_process');
|
26
|
+
const { fileURLToPath } = await import('url');
|
27
|
+
|
28
|
+
const options = {
|
29
|
+
cwd: nodeProcess.cwd(),
|
30
|
+
env: nodeProcess.env,
|
31
|
+
stdio: 'inherit',
|
32
|
+
};
|
33
|
+
|
34
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
35
|
+
const helpText = await readFile(resolve(__dirname, '../man/marked.1.md'), 'utf8');
|
36
|
+
|
37
|
+
await new Promise(res => {
|
38
|
+
const manProcess = spawn('man', [resolve(__dirname, '../man/marked.1')], options);
|
39
|
+
nodeProcess.on('SIGINT', () => {
|
40
|
+
manProcess.kill('SIGINT');
|
41
|
+
});
|
42
|
+
|
43
|
+
manProcess.on('error', () => {
|
44
|
+
console.log(helpText);
|
45
|
+
})
|
46
|
+
.on('close', res);
|
47
|
+
});
|
48
|
+
}
|
49
|
+
|
50
|
+
async function version() {
|
51
|
+
const pkg = require('../package.json');
|
52
|
+
console.log(pkg.version);
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Main
|
57
|
+
*/
|
58
|
+
async function start(argv) {
|
59
|
+
const files = [];
|
60
|
+
const options = {};
|
61
|
+
let input;
|
62
|
+
let output;
|
63
|
+
let string;
|
64
|
+
let arg;
|
65
|
+
let tokens;
|
66
|
+
let config;
|
67
|
+
let opt;
|
68
|
+
let noclobber;
|
69
|
+
|
70
|
+
function getArg() {
|
71
|
+
let arg = argv.shift();
|
72
|
+
|
73
|
+
if (arg.indexOf('--') === 0) {
|
74
|
+
// e.g. --opt
|
75
|
+
arg = arg.split('=');
|
76
|
+
if (arg.length > 1) {
|
77
|
+
// e.g. --opt=val
|
78
|
+
argv.unshift(arg.slice(1).join('='));
|
79
|
+
}
|
80
|
+
arg = arg[0];
|
81
|
+
} else if (arg[0] === '-') {
|
82
|
+
if (arg.length > 2) {
|
83
|
+
// e.g. -abc
|
84
|
+
argv = arg.substring(1).split('').map(function(ch) {
|
85
|
+
return '-' + ch;
|
86
|
+
}).concat(argv);
|
87
|
+
arg = argv.shift();
|
88
|
+
} else {
|
89
|
+
// e.g. -a
|
90
|
+
}
|
91
|
+
} else {
|
92
|
+
// e.g. foo
|
93
|
+
}
|
94
|
+
|
95
|
+
return arg;
|
96
|
+
}
|
97
|
+
|
98
|
+
while (argv.length) {
|
99
|
+
arg = getArg();
|
100
|
+
switch (arg) {
|
101
|
+
case '-o':
|
102
|
+
case '--output':
|
103
|
+
output = argv.shift();
|
104
|
+
break;
|
105
|
+
case '-i':
|
106
|
+
case '--input':
|
107
|
+
input = argv.shift();
|
108
|
+
break;
|
109
|
+
case '-s':
|
110
|
+
case '--string':
|
111
|
+
string = argv.shift();
|
112
|
+
break;
|
113
|
+
case '-t':
|
114
|
+
case '--tokens':
|
115
|
+
tokens = true;
|
116
|
+
break;
|
117
|
+
case '-c':
|
118
|
+
case '--config':
|
119
|
+
config = argv.shift();
|
120
|
+
break;
|
121
|
+
case '-n':
|
122
|
+
case '--no-clobber':
|
123
|
+
noclobber = true;
|
124
|
+
break;
|
125
|
+
case '-h':
|
126
|
+
case '--help':
|
127
|
+
return await help();
|
128
|
+
case '-v':
|
129
|
+
case '--version':
|
130
|
+
return await version();
|
131
|
+
default:
|
132
|
+
if (arg.indexOf('--') === 0) {
|
133
|
+
opt = camelize(arg.replace(/^--(no-)?/, ''));
|
134
|
+
if (!(opt in marked.defaults)) {
|
135
|
+
continue;
|
136
|
+
}
|
137
|
+
if (arg.indexOf('--no-') === 0) {
|
138
|
+
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
139
|
+
? null
|
140
|
+
: false;
|
141
|
+
} else {
|
142
|
+
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
143
|
+
? argv.shift()
|
144
|
+
: true;
|
145
|
+
}
|
146
|
+
} else {
|
147
|
+
files.push(arg);
|
148
|
+
}
|
149
|
+
break;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
async function getData() {
|
154
|
+
if (!input) {
|
155
|
+
if (files.length <= 2) {
|
156
|
+
if (string) {
|
157
|
+
return string;
|
158
|
+
}
|
159
|
+
return await getStdin();
|
160
|
+
}
|
161
|
+
input = files.pop();
|
162
|
+
}
|
163
|
+
return await readFile(input, 'utf8');
|
164
|
+
}
|
165
|
+
|
166
|
+
function resolveFile(file) {
|
167
|
+
return resolve(file.replace(/^~/, homedir));
|
168
|
+
}
|
169
|
+
|
170
|
+
function fileExists(file) {
|
171
|
+
return access(resolveFile(file)).then(() => true, () => false);
|
172
|
+
}
|
173
|
+
|
174
|
+
async function runConfig(file) {
|
175
|
+
const configFile = resolveFile(file);
|
176
|
+
let markedConfig;
|
177
|
+
try {
|
178
|
+
// try require for json
|
179
|
+
markedConfig = require(configFile);
|
180
|
+
} catch (err) {
|
181
|
+
if (err.code !== 'ERR_REQUIRE_ESM') {
|
182
|
+
throw err;
|
183
|
+
}
|
184
|
+
// must import esm
|
185
|
+
markedConfig = await import('file:///' + configFile);
|
186
|
+
}
|
187
|
+
|
188
|
+
if (markedConfig.default) {
|
189
|
+
markedConfig = markedConfig.default;
|
190
|
+
}
|
191
|
+
|
192
|
+
if (typeof markedConfig === 'function') {
|
193
|
+
markedConfig(marked);
|
194
|
+
} else {
|
195
|
+
marked.use(markedConfig);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
const data = await getData();
|
200
|
+
|
201
|
+
if (config) {
|
202
|
+
if (!await fileExists(config)) {
|
203
|
+
throw Error(`Cannot load config file '${config}'`);
|
204
|
+
}
|
205
|
+
|
206
|
+
await runConfig(config);
|
207
|
+
} else {
|
208
|
+
const defaultConfig = [
|
209
|
+
'~/.marked.json',
|
210
|
+
'~/.marked.js',
|
211
|
+
'~/.marked/index.js',
|
212
|
+
];
|
213
|
+
|
214
|
+
for (const configFile of defaultConfig) {
|
215
|
+
if (await fileExists(configFile)) {
|
216
|
+
await runConfig(configFile);
|
217
|
+
break;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
const html = tokens
|
223
|
+
? JSON.stringify(marked.lexer(data, options), null, 2)
|
224
|
+
: await marked.parse(data, options);
|
225
|
+
|
226
|
+
if (output) {
|
227
|
+
if (noclobber && await fileExists(output)) {
|
228
|
+
throw Error('marked: output file \'' + output + '\' already exists, disable the \'-n\' / \'--no-clobber\' flag to overwrite\n');
|
229
|
+
}
|
230
|
+
return await writeFile(output, html);
|
231
|
+
}
|
232
|
+
|
233
|
+
nodeProcess.stdout.write(html + '\n');
|
234
|
+
}
|
235
|
+
|
236
|
+
/**
|
237
|
+
* Helpers
|
238
|
+
*/
|
239
|
+
function getStdin() {
|
240
|
+
return new Promise((resolve, reject) => {
|
241
|
+
const stdin = nodeProcess.stdin;
|
242
|
+
let buff = '';
|
243
|
+
|
244
|
+
stdin.setEncoding('utf8');
|
245
|
+
|
246
|
+
stdin.on('data', function(data) {
|
247
|
+
buff += data;
|
248
|
+
});
|
249
|
+
|
250
|
+
stdin.on('error', function(err) {
|
251
|
+
reject(err);
|
252
|
+
});
|
253
|
+
|
254
|
+
stdin.on('end', function() {
|
255
|
+
resolve(buff);
|
256
|
+
});
|
257
|
+
|
258
|
+
stdin.resume();
|
259
|
+
});
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* @param {string} text
|
264
|
+
*/
|
265
|
+
function camelize(text) {
|
266
|
+
return text.replace(/(\w)-(\w)/g, function(_, a, b) {
|
267
|
+
return a + b.toUpperCase();
|
268
|
+
});
|
269
|
+
}
|
270
|
+
|
271
|
+
try {
|
272
|
+
await start(nodeProcess.argv.slice());
|
273
|
+
nodeProcess.exit(0);
|
274
|
+
} catch (err) {
|
275
|
+
if (err.code === 'ENOENT') {
|
276
|
+
nodeProcess.stderr.write('marked: ' + err.path + ': No such file or directory');
|
277
|
+
} else {
|
278
|
+
nodeProcess.stderr.write(err.message);
|
279
|
+
}
|
280
|
+
return nodeProcess.exit(1);
|
281
|
+
}
|
282
|
+
}
|
package/bin/marked.js
ADDED
package/lib/main.tar.gz
ADDED
Binary file
|