Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

marked

Package Overview
Dependencies
Maintainers
1
Versions
181
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marked - npm Package Compare versions

Comparing version 0.2.9 to 0.2.10

component.json

70

lib/marked.js

@@ -20,3 +20,3 @@ /**

nptable: noop,
lheading: /^([^\n]+)\n *(=|-){3,} *\n*/,
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/,

@@ -79,3 +79,5 @@ list: /^( *)(bull) [\s\S]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,

block.gfm.paragraph = replace(block.paragraph)
('(?!', '(?!' + block.gfm.fences.source.replace('\\1', '\\2') + '|')
('(?!', '(?!'
+ block.gfm.fences.source.replace('\\1', '\\2') + '|'
+ block.list.source.replace('\\1', '\\3') + '|')
();

@@ -313,3 +315,3 @@

if (this.options.smartLists && i !== l - 1) {
b = block.bullet.exec(cap[i+1])[0];
b = block.bullet.exec(cap[i + 1])[0];
if (bull !== b && !(bull.length > 1 && b.length > 1)) {

@@ -326,3 +328,3 @@ src = cap.slice(i + 1).join('\n') + src;

if (i !== l - 1) {
next = item[item.length-1] === '\n';
next = item.charAt(item.length - 1) === '\n';
if (!loose) loose = next;

@@ -359,3 +361,3 @@ }

: 'html',
pre: cap[1] === 'pre' || cap[1] === 'script',
pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
text: cap[0]

@@ -415,3 +417,3 @@ });

type: 'paragraph',
text: cap[1][cap[1].length-1] === '\n'
text: cap[1].charAt(cap[1].length - 1) === '\n'
? cap[1].slice(0, -1)

@@ -463,4 +465,4 @@ : cap[1]

inline._inside = /(?:\[[^\]]*\]|[^\]]|\](?=[^\[]*\]))*/;
inline._href = /\s*<?([^\s]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;

@@ -577,3 +579,3 @@ inline.link = replace(inline.link)

if (cap[2] === '@') {
text = cap[1][6] === ':'
text = cap[1].charAt(6) === ':'
? this.mangle(cap[1].substring(7))

@@ -633,3 +635,3 @@ : this.mangle(cap[1]);

if (!link || !link.href) {
out += cap[0][0];
out += cap[0].charAt(0);
src = cap[0].substring(1) + src;

@@ -706,3 +708,3 @@ continue;

InlineLexer.prototype.outputLink = function(cap, link) {
if (cap[0][0] !== '!') {
if (cap[0].charAt(0) !== '!') {
return '<a href="'

@@ -741,5 +743,13 @@ + escape(link.href)

return text
// em-dashes
.replace(/--/g, '\u2014')
.replace(/'([^']*)'/g, '\u2018$1\u2019')
.replace(/"([^"]*)"/g, '\u201C$1\u201D')
// opening singles
.replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
// closing singles & apostrophes
.replace(/'/g, '\u2019')
// opening doubles
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
// closing doubles
.replace(/"/g, '\u201d')
// ellipses
.replace(/\.{3}/g, '\u2026');

@@ -817,3 +827,3 @@ };

Parser.prototype.peek = function() {
return this.tokens[this.tokens.length-1] || 0;
return this.tokens[this.tokens.length - 1] || 0;
};

@@ -850,3 +860,5 @@

+ this.token.depth
+ '>'
+ ' id="'
+ this.token.text.toLowerCase().replace(/[^\w]+/g, '-')
+ '">'
+ this.inline.output(this.token.text)

@@ -893,5 +905,7 @@ + '</h'

heading = this.inline.output(this.token.header[i]);
body += this.token.align[i]
? '<th align="' + this.token.align[i] + '">' + heading + '</th>\n'
: '<th>' + heading + '</th>\n';
body += '<th';
if (this.token.align[i]) {
body += ' style="text-align:' + this.token.align[i] + '"';
}
body += '>' + heading + '</th>\n';
}

@@ -907,5 +921,7 @@ body += '</tr>\n</thead>\n';

cell = this.inline.output(row[j]);
body += this.token.align[j]
? '<td align="' + this.token.align[j] + '">' + cell + '</td>\n'
: '<td>' + cell + '</td>\n';
body += '<td';
if (this.token.align[j]) {
body += ' style="text-align:' + this.token.align[j] + '"';
}
body += '>' + cell + '</td>\n';
}

@@ -1045,3 +1061,3 @@ body += '</tr>\n';

if (opt) opt = merge({}, marked.defaults, opt);
opt = merge({}, marked.defaults, opt || {});

@@ -1061,9 +1077,5 @@ var highlight = opt.highlight

var done = function(hi) {
var done = function() {
var out, err;
if (hi !== true) {
delete opt.highlight;
}
try {

@@ -1083,5 +1095,7 @@ out = Parser.parse(tokens, opt);

if (!highlight || highlight.length < 3) {
return done(true);
return done();
}
delete opt.highlight;
if (!pending) return done();

@@ -1088,0 +1102,0 @@

2

package.json

@@ -5,3 +5,3 @@ {

"author": "Christopher Jeffrey",
"version": "0.2.9",
"version": "0.2.10",
"main": "./lib/marked.js",

@@ -8,0 +8,0 @@ "bin": "./bin/marked",

# marked
A full-featured markdown parser and compiler, written in javascript.
Built for speed.
> A full-featured markdown parser and compiler, written in javascript. Built
> for speed.
[![NPM version](https://badge.fury.io/js/marked.png)][badge]
## Install
``` bash
npm install marked --save
```
## Usage
Minimal usage:
```js
console.log(marked('I am using __markdown__.'));
// Outputs: <p>I am using <i>markdown</i>.</p>
```
Example using all options:
```js
// Set default options except highlight which has no default
marked.setOptions({
gfm: true,
highlight: function (code, lang, callback) {
pygmentize({ lang: lang, format: 'html' }, code, function (err, result) {
if (err) return callback(err);
callback(null, result.toString());
});
},
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false,
langPrefix: 'lang-'
});
// Using async version of marked
marked('I am using __markdown__.', function (err, content) {
if (err) throw err;
console.log(content);
});
```
## marked(markdownString, [options], [callback])
### markdownString
Type: `String`
String of markdown source to be compiled.
### options
Type: `Object`
Hash of options. Can also be set using the `marked.setOptions` method as seen
above.
### callback
Type: `Function`
Function called when the `markdownString` has been fully parsed when using
async highlighting. If the `options` argument is omitted, this can be used as
the second argument as seen above:
## Options
### gfm
Type: `Boolean`
Default: `true`
Enable [GitHub flavored markdown][gfm].
### highlight
Type: `Function`
A function to highlight code blocks. The function takes three arguments: code,
lang, and callback. The above example uses async highlighting with
[node-pygementize-bundled][pygmentize], and here is a synchronous example using
[highlight.js][highlight] which doesn't require the callback argument:
```js
marked.setOptions({
highlight: function (code, lang) {
return hljs.highlightAuto(lang, code).value;
}
});
```
#### highlight arguments
`code`
Type: `String`
The section of code to pass to the highlighter.
`lang`
Type: `String`
The programming language specified in the code block.
`callback`
Type: `String`
The callback function to call when using an async highlighter.
### tables
Type: `Boolean`
Default: `true`
Enable GFM [tables][tables].
This option requires the `gfm` option to be true.
### breaks
Type: `Boolean`
Default: `false`
Enable GFM [line breaks][breaks].
This option requires the `gfm` option to be true.
### pedantic
Type: `Boolean`
Default: `false`
Conform to obscure parts of `markdown.pl` as much as possible. Don't fix any of
the original markdown bugs or poor behavior.
### sanitize
Type: `Boolean`
Default: `false`
Sanitize the output. Ignore any HTML that has been input.
### smartLists
Type: `Boolean`
Default: `true`
Use smarter list behavior than the original markdown. May eventually be
default with the old behavior moved into `pedantic`.
### smartypants
Type: `Boolean`
Default: `false`
Use "smart" typograhic punctuation for things like quotes and dashes.
### langPrefix
Type: `String`
Default: `lang-`
Set the prefix for code block classes.
## Access to lexer and parser
You also have direct access to the lexer and parser if you so desire.
``` js
var tokens = marked.lexer(text, options);
console.log(marked.parser(tokens));
```
``` js
var lexer = new marked.Lexer(options);
var tokens = lexer.lex(text);
console.log(tokens);
console.log(lexer.rules);
```
## CLI
``` bash
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
```
## Benchmarks

@@ -50,8 +243,2 @@

## Install
``` bash
$ npm install marked
```
## Another Javascript Markdown Parser

@@ -74,58 +261,5 @@

Along with implementing every markdown feature, marked also implements
[GFM features](http://github.github.com/github-flavored-markdown/).
Along with implementing every markdown feature, marked also implements [GFM
features][gfmf].
## Options
marked has a few different switches which change behavior.
- __pedantic__: Conform to obscure parts of `markdown.pl` as much as possible.
Don't fix any of the original markdown bugs or poor behavior.
- __gfm__: Enable github flavored markdown (enabled by default).
- __sanitize__: Sanitize the output. Ignore any HTML that has been input.
- __highlight__: A callback to highlight code blocks.
- __tables__: Enable GFM tables. This is enabled by default. (Requires the
`gfm` option in order to be enabled).
- __breaks__: Enable GFM line breaks. Disabled by default.
- __smartLists__: Use smarter list behavior than the original markdown.
Disabled by default. May eventually be default with the old behavior
moved into `pedantic`.
- __langPrefix__: Set the prefix for code block classes. Defaults to `lang-`.
## Usage
``` js
// Set default options
marked.setOptions({
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
langPrefix: 'language-',
highlight: function(code, lang) {
if (lang === 'js') {
return highlighter.javascript(code);
}
return code;
}
});
console.log(marked('i am using __markdown__.'));
```
You also have direct access to the lexer and parser if you so desire.
``` js
var tokens = marked.lexer(text, options);
console.log(marked.parser(tokens));
```
``` js
var lexer = new marked.Lexer(options);
var tokens = lexer.lex(text);
console.log(tokens);
console.log(lexer.rules);
```
``` bash

@@ -141,12 +275,35 @@ $ node

## CLI
## Running Tests & Contributing
If you want to submit a pull request, make sure your changes pass the test
suite. If you're adding a new feature, be sure to add your own test.
The marked test suite is set up slightly strangely: `test/new` is for all tests
that are not part of the original markdown.pl test suite (this is where your
test should go if you make one). `test/original` is only for the original
markdown.pl tests. `test/tests` houses both types of tests after they have been
combined and moved/generated by running `node test --fix` or `marked --test
--fix`.
In other words, if you have a test to add, add it to `test/new/` and then
regenerate the tests with `node test --fix`. Commit the result. If your test
uses a certain feature, for example, maybe it assumes GFM is *not* enabled, you
can add `.nogfm` to the filename. So, `my-test.text` becomes
`my-test.nogfm.text`. You can do this with any marked option. Say you want
line breaks and smartypants enabled, your filename should be:
`my-test.breaks.smartypants.text`.
To run the tests:
``` bash
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
cd marked/
node test
```
### Contribution and License Agreement
If you contribute code to marked, you are implicitly allowing your code to be
distributed under the MIT license. You are also implicitly verifying that all
code is your original work. `</legalese>`
## License

@@ -157,1 +314,9 @@

See LICENSE for more info.
[gfm]: https://help.github.com/articles/github-flavored-markdown
[gfmf]: http://github.github.com/github-flavored-markdown/
[pygmentize]: https://github.com/rvagg/node-pygmentize-bundled
[highlight]: https://github.com/isagalaev/highlight.js
[badge]: http://badge.fury.io/js/marked
[tables]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables
[breaks]: https://help.github.com/articles/github-flavored-markdown#newlines
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc