Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into reorganize-grammars
Browse files Browse the repository at this point in the history
  • Loading branch information
Feder1co5oave committed Jan 4, 2019
2 parents 6d0f2ae + 88a8561 commit d1559b1
Show file tree
Hide file tree
Showing 21 changed files with 173 additions and 48 deletions.
10 changes: 9 additions & 1 deletion bin/marked
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,22 @@ function camelize(text) {
});
}

function handleError(err) {
if (err.code === 'ENOENT') {
console.error(`marked: output to ${err.path}: No such directory`);
return process.exit(1);
}
throw err;
}

/**
* Expose / Entry Point
*/

if (!module.parent) {
process.title = 'marked';
main(process.argv.slice(), function(err, code) {
if (err) throw err;
if (err) return handleError(err);
return process.exit(code || 0);
});
} else {
Expand Down
15 changes: 13 additions & 2 deletions docs/AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ Marked takes an encompassing approach to its community. As such, you can think o
<div>Contributor</div>
<small>Regent of the Regex; Master of Marked</small>
</td>
</tr>
<tr>
<td align="center" valign="top">
<a href="https://github.com/karenyavine">
<img width="100" height="100" src="https://github.com/karenyavine.png?s=150">
Expand All @@ -100,6 +98,8 @@ Marked takes an encompassing approach to its community. As such, you can think o
<div>Contributor</div>
<small>Snyk's Security Saint</small>
</td>
</tr>
<tr>
<td align="center" valign="top">
<a href="https://github.com/KostyaTretyak">
<img width="100" height="100" src="https://github.com/KostyaTretyak.png?s=150">
Expand All @@ -118,6 +118,17 @@ Marked takes an encompassing approach to its community. As such, you can think o
<div>Contributor</div>
<small>Defibrillator</small>
</td>
<td align="center" width="20%" valign="top">
<a href="https://github.com/mccraveiro">
<img width="100" height="100" src="https://github.com/mccraveiro.png?s=150">
</a>
<br>
<a href="https://github.com/mccraveiro">Mateus Craveiro</a>
<div>Contributor</div>
<small>Defibrillator</small>
</td>
<td align="center" width="20%" valign="top">
</td>
</tr>
</tbody>
</table>
Expand Down
66 changes: 55 additions & 11 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var block = {
heading: /^ *(#{1,6}) +([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
nptable: noop,
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
html: '^ {0,3}(?:' // optional indentation
+ '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
+ '|comment[^\\n]*(\\n+|$)' // (2)
Expand All @@ -46,8 +46,8 @@ block.def = edit(block.def)
.replace('title', block._title)
.getRegex();

block.bullet = /(?:[*+-]|\d+\.)/;
block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
block.bullet = /(?:[*+-]|\d{1,9}\.)/;
block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
block.item = edit(block.item, 'gm')
.replace(/bull/g, block.bullet)
.getRegex();
Expand Down Expand Up @@ -349,7 +349,7 @@ Lexer.prototype.token = function(src, top) {
// Remove the list item's bullet
// so it is seen as the next token.
space = item.length;
item = item.replace(/^ *([*+-]|\d+\.) +/, '');
item = item.replace(/^ *([*+-]|\d+\.) */, '');

// Outdent whatever the
// list item contains. Hacky.
Expand All @@ -362,9 +362,10 @@ Lexer.prototype.token = function(src, top) {

// Determine whether the next list item belongs here.
// Backpedal if it does not belong in this list.
if (this.options.smartLists && i !== l - 1) {
if (i !== l - 1) {
b = block.bullet.exec(cap[i + 1])[0];
if (bull !== b && !(bull.length > 1 && b.length > 1)) {
if (bull.length > 1 ? b.length === 1
: (b.length > 1 || (this.options.smartLists && b !== bull))) {
src = cap.slice(i + 1).join('\n') + src;
i = l - 1;
}
Expand Down Expand Up @@ -547,7 +548,7 @@ var inline = {
link: /^!?\[(label)\]\(href(?:\s+(title))?\s*\)/,
reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
strong: /^__([^\s])__(?!_)|^\*\*([^\s])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
em: /^_([^\s_])_(?!_)|^\*([^\s*"<\[])\*(?!\*)|^_([^\s][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s"<\[][\s\S]*?[^\s*])\*(?!\*)|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
br: /^( {2,}|\\)\n(?!\s*$)/,
Expand Down Expand Up @@ -697,7 +698,7 @@ InlineLexer.prototype.output = function(src) {
// escape
if (cap = this.rules.escape.exec(src)) {
src = src.substring(cap[0].length);
out += cap[1];
out += escape(cap[1]);
continue;
}

Expand Down Expand Up @@ -959,13 +960,13 @@ Renderer.prototype.html = function(html) {
return html;
};

Renderer.prototype.heading = function(text, level, raw) {
Renderer.prototype.heading = function(text, level, raw, slugger) {
if (this.options.headerIds) {
return '<h'
+ level
+ ' id="'
+ this.options.headerPrefix
+ raw.toLowerCase().replace(/[^\w]+/g, '-')
+ slugger.slug(raw)
+ '">'
+ text
+ '</h'
Expand Down Expand Up @@ -1114,6 +1115,7 @@ function Parser(options) {
this.options.renderer = this.options.renderer || new Renderer();
this.renderer = this.options.renderer;
this.renderer.options = this.options;
this.slugger = new Slugger();
}

/**
Expand Down Expand Up @@ -1192,7 +1194,8 @@ Parser.prototype.tok = function() {
return this.renderer.heading(
this.inline.output(this.token.text),
this.token.depth,
unescape(this.inlineText.output(this.token.text)));
unescape(this.inlineText.output(this.token.text)),
this.slugger);
}
case 'code': {
return this.renderer.code(this.token.text,
Expand Down Expand Up @@ -1278,9 +1281,48 @@ Parser.prototype.tok = function() {
case 'text': {
return this.renderer.paragraph(this.parseText());
}
default: {
var errMsg = 'Token with "' + this.token.type + '" type was not found.';
if (this.options.silent) {
console.log(errMsg);
} else {
throw new Error(errMsg);
}
}
}
};

/**
* Slugger generates header id
*/

function Slugger () {
this.seen = {};
}

/**
* Convert string to unique id
*/

Slugger.prototype.slug = function (value) {
var slug = value
.toLowerCase()
.trim()
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
.replace(/\s/g, '-');

if (this.seen.hasOwnProperty(slug)) {
var originalSlug = slug;
do {
this.seen[originalSlug]++;
slug = originalSlug + '-' + this.seen[originalSlug];
} while (this.seen.hasOwnProperty(slug));
}
this.seen[slug] = 0;

return slug;
};

/**
* Helpers
*/
Expand Down Expand Up @@ -1615,6 +1657,8 @@ marked.lexer = Lexer.lex;
marked.InlineLexer = InlineLexer;
marked.inlineLexer = InlineLexer.output;

marked.Slugger = Slugger;

marked.parse = marked;

if (typeof module !== 'undefined' && typeof exports === 'object') {
Expand Down
2 changes: 1 addition & 1 deletion man/marked.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ CONFIGURATION


BUGS
Please report any bugs to https://github.com/chjj/marked.
Please report any bugs to https://github.com/markedjs/marked.


LICENSE
Expand Down
2 changes: 1 addition & 1 deletion marked.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "marked",
"description": "A markdown parser built for speed",
"author": "Christopher Jeffrey",
"version": "0.5.2",
"version": "0.6.0",
"main": "./lib/marked.js",
"bin": "./bin/marked",
"man": "./man/marked.1",
Expand Down
9 changes: 9 additions & 0 deletions test/new/adjacent_lists.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ul>
<li>This should be</li>
<li>An unordered list</li>
</ul>

<ol>
<li>This should be</li>
<li>An unordered list</li>
</ol>
5 changes: 5 additions & 0 deletions test/new/adjacent_lists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* This should be
* An unordered list

1. This should be
2. An unordered list
8 changes: 4 additions & 4 deletions test/new/cm_blockquotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h3 id="example-192">Example 192</h3>
<p>The spaces after the <code>&gt;</code> characters can be omitted:</p>

<blockquote>
<h1 id="foo">Foo</h1>
<h1 id="bar">Bar</h1>
<p>bar
baz</p>
</blockquote>
Expand All @@ -21,7 +21,7 @@ <h3 id="example-193">Example 193</h3>
<p>The <code>&gt;</code> characters can be indented 1-3 spaces:</p>

<blockquote>
<h1 id="foo">Foo</h1>
<h1 id="baz">Baz</h1>
<p>bar
baz</p>
</blockquote>
Expand All @@ -30,7 +30,7 @@ <h3 id="example-194">Example 194</h3>

<p>Four spaces gives us a code block:</p>

<pre><code>&gt; # Foo
<pre><code>&gt; # Qux
&gt; bar
&gt; baz</code></pre>

Expand All @@ -39,7 +39,7 @@ <h3 id="example-195">Example 195</h3>
<p>The Laziness clause allows us to omit the <code>&gt;</code> before paragraph continuation text:</p>

<blockquote>
<h1 id="foo">Foo</h1>
<h1 id="quux">Quux</h1>
<p>bar
baz</p>
</blockquote>
Expand Down
8 changes: 4 additions & 4 deletions test/new/cm_blockquotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@

The spaces after the `>` characters can be omitted:

># Foo
># Bar
>bar
> baz
### Example 193

The `>` characters can be indented 1-3 spaces:

> # Foo
> # Baz
> bar
> baz
### Example 194

Four spaces gives us a code block:

> # Foo
> # Qux
> bar
> baz

### Example 195

The Laziness clause allows us to omit the `>` before paragraph continuation text:

> # Foo
> # Quux
> bar
baz

Expand Down
2 changes: 1 addition & 1 deletion test/new/escaped_angles.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>></p>
<p>&gt;</p>
1 change: 0 additions & 1 deletion test/new/gfm_del.html

This file was deleted.

1 change: 0 additions & 1 deletion test/new/gfm_del.md

This file was deleted.

2 changes: 1 addition & 1 deletion test/new/pedantic_heading_interrupts_paragraph.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<h1 id="how-are-you">how are you</h1>

<p>paragraph before head with equals</p>
<h1 id="how-are-you">how are you</h1>
<h1 id="how-are-you-again">how are you again</h1>
2 changes: 1 addition & 1 deletion test/new/pedantic_heading_interrupts_paragraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ paragraph before head with hash
#how are you

paragraph before head with equals
how are you
how are you again
===========
3 changes: 3 additions & 0 deletions test/new/toplevel_paragraphs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
gfm: true
---
hello world
text after spaces
text after spaces
Expand Down
2 changes: 1 addition & 1 deletion test/original/backslash_escapes.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<p>Right paren: )</p>

<p>Greater-than: ></p>
<p>Greater-than: &gt;</p>

<p>Hash: #</p>

Expand Down
Loading

0 comments on commit d1559b1

Please sign in to comment.