commonmark
Advanced tools
Comparing version 0.22.1 to 0.23.0
@@ -0,1 +1,21 @@ | ||
[0.23.0] | ||
* [API change] Rename nodes: "Html" -> "HtmlInline" (#63). | ||
* [API change] Add `CustomBlock`, `CustomInline`. | ||
* [API change] Rename "HorizontalRule" -> "ThematicBreak". | ||
* [API change] Rename "Header" -> "Heading" (spec change). | ||
* Don't allow whitespace between link text and link label | ||
of a reference link (spec change.) | ||
* Fixed calculation of list offsets (#59). | ||
* Allow tab after bullet list marker (#59). | ||
* `advanceOffset` - copy the code from `libcmark`. | ||
* Fixed a list/tab/padding corner case (#59). | ||
* Escape HTML contents in xml output, as the DTD requires PCDATA. | ||
* xml renderer - added xmlns attribute (jgm/CommonMark#87). | ||
* Test on node.js 5.x and 4.x (Nik Nyby). Remove testing on iojs. | ||
* Initialize `_listData` to `{}` when creating `Node` (#74). | ||
* Added version check for uglify; updated dist files (#69). | ||
* Fix typo in breakOutOfLists description (Nik Nyby). | ||
* Updated benchmarks in README.md. | ||
[0.22.1] | ||
@@ -2,0 +22,0 @@ |
@@ -10,2 +10,3 @@ "use strict"; | ||
var C_TAB = 9; | ||
var C_NEWLINE = 10; | ||
@@ -39,3 +40,3 @@ var C_GREATERTHAN = 62; | ||
var reHrule = /^(?:(?:\* *){3,}|(?:_ *){3,}|(?:- *){3,}) *$/; | ||
var reThematicBreak = /^(?:(?:\* *){3,}|(?:_ *){3,}|(?:- *){3,}) *$/; | ||
@@ -46,7 +47,7 @@ var reMaybeSpecial = /^[#`~*+_=<>0-9-]/; | ||
var reBulletListMarker = /^[*+-]( +|$)/; | ||
var reBulletListMarker = /^[*+-]/; | ||
var reOrderedListMarker = /^(\d{1,9})([.)])( +|$)/; | ||
var reOrderedListMarker = /^(\d{1,9})([.)])/; | ||
var reATXHeaderMarker = /^#{1,6}(?: +|$)/; | ||
var reATXHeadingMarker = /^#{1,6}(?: +|$)/; | ||
@@ -57,3 +58,3 @@ var reCodeFence = /^`{3,}(?!.*`)|^~{3,}(?!.*~)/; | ||
var reSetextHeaderLine = /^(?:=+|-+) *$/; | ||
var reSetextHeadingLine = /^(?:=+|-+) *$/; | ||
@@ -99,3 +100,3 @@ var reLineEnding = /\r\n|\n|\r/; | ||
// all the lists. (This is used to implement the "two blank lines | ||
// break of of all lists" feature.) | ||
// break out of all lists" feature.) | ||
var breakOutOfLists = function(block) { | ||
@@ -145,6 +146,9 @@ var b = block; | ||
// start, delimiter, bullet character, padding) or null. | ||
var parseListMarker = function(ln, offset, indent) { | ||
var rest = ln.slice(offset); | ||
var parseListMarker = function(parser) { | ||
var rest = parser.currentLine.slice(parser.nextNonspace); | ||
var match; | ||
var spaces_after_marker; | ||
var nextc; | ||
var markerStartCol; | ||
var spacesStartCol; | ||
var spacesStartOffset; | ||
var data = { type: null, | ||
@@ -156,5 +160,4 @@ tight: true, // lists are tight by default | ||
padding: null, | ||
markerOffset: indent }; | ||
markerOffset: parser.indent }; | ||
if ((match = rest.match(reBulletListMarker))) { | ||
spaces_after_marker = match[1].length; | ||
data.type = 'Bullet'; | ||
@@ -164,3 +167,2 @@ data.bulletChar = match[0][0]; | ||
} else if ((match = rest.match(reOrderedListMarker))) { | ||
spaces_after_marker = match[3].length; | ||
data.type = 'Ordered'; | ||
@@ -172,9 +174,32 @@ data.start = parseInt(match[1]); | ||
} | ||
var blank_item = match[0].length === rest.length; | ||
// make sure we have spaces after | ||
nextc = peek(parser.currentLine, parser.nextNonspace + match[0].length); | ||
if (!(nextc === -1 || nextc === C_TAB || nextc === C_SPACE)) { | ||
return null; | ||
} | ||
// we've got a match! advance offset and calculate padding | ||
parser.advanceNextNonspace(); // to start of marker | ||
markerStartCol = parser.column; | ||
parser.advanceOffset(match[0].length, true); // to end of marker | ||
spacesStartCol = parser.column; | ||
spacesStartOffset = parser.offset; | ||
do { | ||
parser.advanceOffset(1, true); | ||
nextc = peek(parser.currentLine, parser.offset); | ||
} while (parser.column - spacesStartCol < 5 && | ||
(nextc === C_SPACE || nextc === C_TAB)); | ||
var blank_item = peek(parser.currentLine, parser.offset) === -1; | ||
var spaces_after_marker = parser.column - spacesStartCol; | ||
if (spaces_after_marker >= 5 || | ||
spaces_after_marker < 1 || | ||
blank_item) { | ||
data.padding = match[0].length - spaces_after_marker + 1; | ||
data.padding = match[0].length + 1; | ||
parser.column = spacesStartCol; | ||
parser.offset = spacesStartOffset; | ||
if (peek(parser.currentLine, parser.offset) === C_SPACE) { | ||
parser.advanceOffset(1, true); | ||
} | ||
} else { | ||
data.padding = match[0].length; | ||
data.padding = match[0].length + spaces_after_marker; | ||
} | ||
@@ -282,5 +307,5 @@ return data; | ||
}, | ||
Header: { | ||
Heading: { | ||
continue: function() { | ||
// a header can never container > 1 line, so fail to match: | ||
// a heading can never container > 1 line, so fail to match: | ||
return 1; | ||
@@ -292,5 +317,5 @@ }, | ||
}, | ||
HorizontalRule: { | ||
ThematicBreak: { | ||
continue: function() { | ||
// an hrule can never container > 1 line, so fail to match: | ||
// a thematic break can never container > 1 line, so fail to match: | ||
return 1; | ||
@@ -411,11 +436,11 @@ }, | ||
// ATX header | ||
// ATX heading | ||
function(parser) { | ||
var match; | ||
if (!parser.indented && | ||
(match = parser.currentLine.slice(parser.nextNonspace).match(reATXHeaderMarker))) { | ||
(match = parser.currentLine.slice(parser.nextNonspace).match(reATXHeadingMarker))) { | ||
parser.advanceNextNonspace(); | ||
parser.advanceOffset(match[0].length, false); | ||
parser.closeUnmatchedBlocks(); | ||
var container = parser.addChild('Header', parser.nextNonspace); | ||
var container = parser.addChild('Heading', parser.nextNonspace); | ||
container.level = match[0].trim().length; // number of #s | ||
@@ -478,3 +503,3 @@ // remove trailing ###s: | ||
// Setext header | ||
// Setext heading | ||
function(parser, container) { | ||
@@ -486,10 +511,10 @@ var match; | ||
container._string_content.length - 1) && | ||
((match = parser.currentLine.slice(parser.nextNonspace).match(reSetextHeaderLine)))) { | ||
((match = parser.currentLine.slice(parser.nextNonspace).match(reSetextHeadingLine)))) { | ||
parser.closeUnmatchedBlocks(); | ||
var header = new Node('Header', container.sourcepos); | ||
header.level = match[0][0] === '=' ? 1 : 2; | ||
header._string_content = container._string_content; | ||
container.insertAfter(header); | ||
var heading = new Node('Heading', container.sourcepos); | ||
heading.level = match[0][0] === '=' ? 1 : 2; | ||
heading._string_content = container._string_content; | ||
container.insertAfter(heading); | ||
container.unlink(); | ||
parser.tip = header; | ||
parser.tip = heading; | ||
parser.advanceOffset(parser.currentLine.length - parser.offset, false); | ||
@@ -502,8 +527,8 @@ return 2; | ||
// hrule | ||
// thematic break | ||
function(parser) { | ||
if (!parser.indented && | ||
reHrule.test(parser.currentLine.slice(parser.nextNonspace))) { | ||
reThematicBreak.test(parser.currentLine.slice(parser.nextNonspace))) { | ||
parser.closeUnmatchedBlocks(); | ||
parser.addChild('HorizontalRule', parser.nextNonspace); | ||
parser.addChild('ThematicBreak', parser.nextNonspace); | ||
parser.advanceOffset(parser.currentLine.length - parser.offset, false); | ||
@@ -519,12 +544,6 @@ return 2; | ||
var data; | ||
var i; | ||
if ((data = parseListMarker(parser.currentLine, | ||
parser.nextNonspace, parser.indent)) && | ||
(!parser.indented || container.type === 'List')) { | ||
if ((!parser.indented || container.type === 'List') | ||
&& (data = parseListMarker(parser))) { | ||
parser.closeUnmatchedBlocks(); | ||
parser.advanceNextNonspace(); | ||
// recalculate data.padding, taking into account tabs: | ||
i = parser.column; | ||
parser.advanceOffset(data.padding, false); | ||
data.padding = parser.column - i; | ||
@@ -565,15 +584,19 @@ // add the list if needed | ||
var advanceOffset = function(count, columns) { | ||
var i = 0; | ||
var cols = 0; | ||
var currentLine = this.currentLine; | ||
while (columns ? (cols < count) : (i < count)) { | ||
if (currentLine[this.offset + i] === '\t') { | ||
cols += (4 - ((this.column + cols) % 4)); | ||
var charsToTab; | ||
var c; | ||
while (count > 0 && (c = currentLine[this.offset])) { | ||
if (c === '\t') { | ||
charsToTab = 4 - (this.column % 4); | ||
this.column += charsToTab; | ||
this.offset += 1; | ||
count -= (columns ? charsToTab : 1); | ||
} else { | ||
cols += 1; | ||
this.offset += 1; | ||
this.column += 1; // assume ascii; block starts are ascii | ||
count -= 1; | ||
} | ||
i++; | ||
} | ||
this.offset += i; | ||
this.column += cols; | ||
}; | ||
@@ -620,2 +643,3 @@ | ||
this.offset = 0; | ||
this.column = 0; | ||
this.lineNumber += 1; | ||
@@ -786,3 +810,3 @@ | ||
t = node.type; | ||
if (!event.entering && (t === 'Paragraph' || t === 'Header')) { | ||
if (!event.entering && (t === 'Paragraph' || t === 'Heading')) { | ||
this.inlineParser.parse(node); | ||
@@ -789,0 +813,0 @@ } |
@@ -100,3 +100,3 @@ "use strict"; | ||
case 'Html': | ||
case 'HtmlInline': | ||
if (options.safe) { | ||
@@ -109,2 +109,10 @@ out('<!-- raw HTML omitted -->'); | ||
case 'CustomInline': | ||
if (entering && node.onEnter) { | ||
out(node.onEnter); | ||
} else if (!entering && node.onExit) { | ||
out(node.onExit); | ||
} | ||
break; | ||
case 'Link': | ||
@@ -209,3 +217,3 @@ if (entering) { | ||
case 'Header': | ||
case 'Heading': | ||
tagname = 'h' + node.level; | ||
@@ -243,4 +251,14 @@ if (entering) { | ||
case 'HorizontalRule': | ||
case 'CustomBlock': | ||
cr(); | ||
if (entering && node.onEnter) { | ||
out(node.onEnter); | ||
} else if (!entering && node.onExit) { | ||
out(node.onExit); | ||
} | ||
cr(); | ||
break; | ||
case 'ThematicBreak': | ||
cr(); | ||
out(tag('hr', attrs, true)); | ||
@@ -247,0 +265,0 @@ cr(); |
@@ -213,3 +213,3 @@ "use strict"; | ||
} else { | ||
var node = new Node('Html'); | ||
var node = new Node('HtmlInline'); | ||
node._literal = m; | ||
@@ -627,3 +627,2 @@ block.appendChild(node); | ||
var savepos = this.pos; | ||
this.spnl(); | ||
var beforelabel = this.pos; | ||
@@ -630,0 +629,0 @@ var n = this.parseLinkLabel(); |
@@ -10,3 +10,3 @@ "use strict"; | ||
case 'Paragraph': | ||
case 'Header': | ||
case 'Heading': | ||
case 'Emph': | ||
@@ -16,2 +16,4 @@ case 'Strong': | ||
case 'Image': | ||
case 'CustomInline': | ||
case 'CustomBlock': | ||
return true; | ||
@@ -82,3 +84,3 @@ default: | ||
this._literal = null; | ||
this._listData = null; | ||
this._listData = {}; | ||
this._info = null; | ||
@@ -92,2 +94,4 @@ this._destination = null; | ||
this._level = null; | ||
this._onEnter = null; | ||
this._onExit = null; | ||
}; | ||
@@ -174,2 +178,12 @@ | ||
Object.defineProperty(proto, 'onEnter', { | ||
get: function() { return this._onEnter; }, | ||
set: function(s) { this._onEnter = s; } | ||
}); | ||
Object.defineProperty(proto, 'onExit', { | ||
get: function() { return this._onExit; }, | ||
set: function(s) { this._onExit = s; } | ||
}); | ||
Node.prototype.appendChild = function(child) { | ||
@@ -176,0 +190,0 @@ child.unlink(); |
@@ -41,3 +41,2 @@ "use strict"; | ||
var indent = ' '; | ||
var unescapedContents; | ||
var container; | ||
@@ -79,5 +78,4 @@ var selfClosing; | ||
container = node.isContainer; | ||
selfClosing = nodetype === 'HorizontalRule' || nodetype === 'Hardbreak' || | ||
selfClosing = nodetype === 'ThematicBreak' || nodetype === 'Hardbreak' || | ||
nodetype === 'Softbreak'; | ||
unescapedContents = nodetype === 'Html' || nodetype === 'HtmlInline'; | ||
tagname = toTagName(nodetype); | ||
@@ -90,2 +88,5 @@ | ||
switch (nodetype) { | ||
case 'Document': | ||
attrs.push(['xmlns', 'http://commonmark.org/xml/1.0']); | ||
break; | ||
case 'List': | ||
@@ -117,3 +118,3 @@ if (node.listType !== null) { | ||
break; | ||
case 'Header': | ||
case 'Heading': | ||
attrs.push(['level', String(node.level)]); | ||
@@ -126,2 +127,7 @@ break; | ||
break; | ||
case 'CustomInline': | ||
case 'CustomBlock': | ||
attrs.push(['on_enter', node.onEnter]); | ||
attrs.push(['on_exit', node.onExit]); | ||
break; | ||
default: | ||
@@ -146,3 +152,3 @@ break; | ||
if (lit) { | ||
out(unescapedContents ? lit : esc(lit)); | ||
out(esc(lit)); | ||
} | ||
@@ -149,0 +155,0 @@ out(tag('/' + tagname)); |
{ "name": "commonmark", | ||
"description": "a strongly specified, highly compatible variant of Markdown", | ||
"version": "0.22.1", | ||
"version": "0.23.0", | ||
"homepage": "http://commonmark.org", | ||
@@ -5,0 +5,0 @@ "keywords": |
102
README.md
@@ -130,4 +130,4 @@ commonmark.js | ||
`Html`, `Link`, `Image`, `Code`, `Document`, `Paragraph`, | ||
`BlockQuote`, `Item`, `List`, `Header`, `CodeBlock`, | ||
`HtmlBlock` `HorizontalRule`. | ||
`BlockQuote`, `Item`, `List`, `Heading`, `CodeBlock`, | ||
`HtmlBlock` `ThematicBreak`. | ||
- `firstChild` (read-only): a Node or null. | ||
@@ -146,3 +146,3 @@ - `lastChild` (read-only): a Node or null. | ||
- `info`: fenced code block info string (String) or null. | ||
- `level`: header level (Number). | ||
- `level`: heading level (Number). | ||
- `listType`: a String, either `Bullet` or `Ordered`. | ||
@@ -152,2 +152,4 @@ - `listTight`: `true` if list is tight. | ||
- `listDelimiter`: a String, either `)` or `.` for an ordered list. | ||
- `onEnter`, `onExit`: Strings, used only for `CustomBlock` or | ||
`CustomInline`. | ||
@@ -258,60 +260,60 @@ Nodes have the following public methods: | ||
against showdown (which is usually the slowest implementation). | ||
Versions: commonmark.js 0.21.0, markdown-it 4.3.0, | ||
showdown 1.2.0, marked 0.3.3, with node 0.10.25. | ||
Versions: showdown 1.3.0, marked 0.3.5, commonmark.js 0.22.1, | ||
markdown-it 5.0.2, node 5.3.0. Hardware: 1.6GHz Intel Core i5, Mac OSX. | ||
| Sample |showdown |commonmark|marked |markdown-it| | ||
|--------------------------|---------:|---------:|---------:|----------:| | ||
|[block-bq-flat.md] | 1| 4.2| 4.9| 4.9| | ||
|[block-bq-nested.md] | 1| 10.0| 7.6| 11.1| | ||
|[block-code.md] | 1| 3.8| 10.0| 14.5| | ||
|[block-fences.md] | 1| 6.0| 16.5| 14.3| | ||
|[block-heading.md] | 1| 3.9| 4.6| 5.5| | ||
|[block-hr.md] | 1| 2.6| 3.0| 3.8| | ||
|[block-html.md] | 1| 1.7| 0.8| 3.9| | ||
|[block-lheading.md] | 1| 3.6| 4.6| 3.1| | ||
|[block-list-flat.md] | 1| 4.3| 4.6| 6.5| | ||
|[block-list-nested.md] | 1| 7.1| 6.1| 13.2| | ||
|[block-ref-flat.md] | 1| 0.6| 0.4| 0.5| | ||
|[block-ref-nested.md] | 1| 0.5| 0.5| 0.7| | ||
|[inline-autolink.md] | 1| 2.0| 3.4| 2.5| | ||
|[inline-backticks.md] | 1| 5.6| 4.6| 7.9| | ||
|[inline-em-flat.md] | 1| 1.0| 1.0| 1.5| | ||
|[inline-em-nested.md] | 1| 1.2| 1.2| 1.4| | ||
|[inline-em-worst.md] | 1| 1.5| 1.3| 0.9| | ||
|[inline-entity.md] | 1| 1.0| 3.7| 2.5| | ||
|[inline-escape.md] | 1| 2.0| 1.3| 4.3| | ||
|[inline-html.md] | 1| 2.0| 3.7| 3.0| | ||
|[inline-links-flat.md] | 1| 2.4| 2.5| 2.4| | ||
|[inline-links-nested.md] | 1| 1.8| 0.5| 0.3| | ||
|[inline-newlines.md] | 1| 1.8| 1.8| 2.4| | ||
|[lorem1.md] | 1| 6.3| 3.4| 3.6| | ||
|[rawtabs.md] | 1| 4.3| 4.2| 4.9| | ||
|[README.md] | 1| 3.6| 3.3| 4.1| | ||
|[README.md] | 1| 3.6| 3.1| 3.9| | ||
|[block-bq-flat.md] | 1| 4.8| 4.9| 4.9| | ||
|[block-bq-nested.md] | 1| 11.9| 6.8| 10.7| | ||
|[block-code.md] | 1| 4.7| 12.1| 23.0| | ||
|[block-fences.md] | 1| 6.2| 21.2| 19.1| | ||
|[block-heading.md] | 1| 5.0| 4.8| 6.5| | ||
|[block-hr.md] | 1| 3.5| 3.3| 3.5| | ||
|[block-html.md] | 1| 2.1| 0.9| 3.8| | ||
|[block-lheading.md] | 1| 5.1| 4.9| 3.9| | ||
|[block-list-flat.md] | 1| 4.7| 4.4| 7.4| | ||
|[block-list-nested.md] | 1| 9.5| 7.8| 17.6| | ||
|[block-ref-flat.md] | 1| 0.8| 0.5| 0.6| | ||
|[block-ref-nested.md] | 1| 0.7| 0.6| 0.9| | ||
|[inline-autolink.md] | 1| 2.3| 3.4| 2.5| | ||
|[inline-backticks.md] | 1| 7.6| 5.3| 8.2| | ||
|[inline-em-flat.md] | 1| 1.5| 1.1| 1.6| | ||
|[inline-em-nested.md] | 1| 1.8| 1.3| 1.7| | ||
|[inline-em-worst.md] | 1| 2.4| 1.5| 2.5| | ||
|[inline-entity.md] | 1| 2.0| 3.8| 2.7| | ||
|[inline-escape.md] | 1| 2.2| 1.4| 5.0| | ||
|[inline-html.md] | 1| 2.9| 3.7| 3.3| | ||
|[inline-links-flat.md] | 1| 2.7| 2.7| 2.2| | ||
|[inline-links-nested.md] | 1| 1.4| 0.5| 0.5| | ||
|[inline-newlines.md] | 1| 2.3| 2.0| 3.5| | ||
|[lorem1.md] | 1| 6.0| 2.9| 3.3| | ||
|[rawtabs.md] | 1| 4.6| 3.9| 6.7| | ||
[block-lheading.md]: bench/samples/block-lheading.md | ||
[block-heading.md]: bench/samples/block-heading.md | ||
[block-html.md]: bench/samples/block-html.md | ||
[inline-links-nested.md]: bench/samples/inline-links-nested.md | ||
[inline-em-flat.md]: bench/samples/inline-em-flat.md | ||
[inline-autolink.md]: bench/samples/inline-autolink.md | ||
[inline-html.md]: bench/samples/inline-html.md | ||
[lorem1.md]: bench/samples/lorem1.md | ||
[block-list-flat.md]: bench/samples/block-list-flat.md | ||
[block-hr.md]: bench/samples/block-hr.md | ||
[block-fences.md]: bench/samples/block-fences.md | ||
[block-ref-flat.md]: bench/samples/block-ref-flat.md | ||
[block-bq-flat.md]: bench/samples/block-bq-flat.md | ||
[rawtabs.md]: bench/samples/rawtabs.md | ||
[inline-escape.md]: bench/samples/inline-escape.md | ||
[rawtabs.md]: bench/samples/rawtabs.md | ||
[inline-em-worst.md]: bench/samples/inline-em-worst.md | ||
[block-list-nested.md]: bench/samples/block-list-nested.md | ||
[block-bq-nested.md]: bench/samples/block-bq-nested.md | ||
[block-bq-flat.md]: bench/samples/block-bq-flat.md | ||
[inline-newlines.md]: bench/samples/inline-newlines.md | ||
[block-ref-nested.md]: bench/samples/block-ref-nested.md | ||
[block-bq-nested.md]: bench/samples/block-bq-nested.md | ||
[inline-entity.md]: bench/samples/inline-entity.md | ||
[block-fences.md]: bench/samples/block-fences.md | ||
[lorem1.md]: bench/samples/lorem1.md | ||
[README.md]: bench/samples/README.md | ||
[block-html.md]: bench/samples/block-html.md | ||
[inline-newlines.md]: bench/samples/inline-newlines.md | ||
[inline-links-flat.md]: bench/samples/inline-links-flat.md | ||
[inline-em-flat.md]: bench/samples/inline-em-flat.md | ||
[block-heading.md]: bench/samples/block-heading.md | ||
[inline-em-nested.md]: bench/samples/inline-em-nested.md | ||
[inline-entity.md]: bench/samples/inline-entity.md | ||
[block-list-flat.md]: bench/samples/block-list-flat.md | ||
[block-hr.md]: bench/samples/block-hr.md | ||
[block-lheading.md]: bench/samples/block-lheading.md | ||
[block-code.md]: bench/samples/block-code.md | ||
[inline-backticks.md]: bench/samples/inline-backticks.md | ||
[block-code.md]: bench/samples/block-code.md | ||
[inline-autolink.md]: bench/samples/inline-autolink.md | ||
[inline-links-nested.md]: bench/samples/inline-links-nested.md | ||
[inline-em-worst.md]: bench/samples/inline-em-worst.md | ||
[inline-em-nested.md]: bench/samples/inline-em-nested.md | ||
[block-ref-flat.md]: bench/samples/block-ref-flat.md | ||
@@ -318,0 +320,0 @@ To generate this table, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
417079
6027
330
0