remarkable
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -0,1 +1,11 @@ | ||
1.4.2 / 2014-11-29 | ||
------------------ | ||
- Added footnotes support. | ||
- Added definitions lists support. | ||
- Added `fence_custom` renderer extension to easy override | ||
named fenced blocks (useful for diagrams and so on). | ||
- Exposed `./common/utils` to simplify custom renderers. | ||
1.4.1 / 2014-11-13 | ||
@@ -2,0 +12,0 @@ ------------------ |
@@ -10,2 +10,8 @@ // Utilities | ||
var _hasOwnProperty = Object.prototype.hasOwnProperty; | ||
function has(object, key) { | ||
return object ? _hasOwnProperty.call(object, key) : false; | ||
} | ||
// Merge objects | ||
@@ -31,2 +37,3 @@ // | ||
//////////////////////////////////////////////////////////////////////////////// | ||
@@ -40,2 +47,4 @@ var UNESCAPE_MD_RE = /\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
function isValidEntityCode(c) { | ||
@@ -77,3 +86,3 @@ /*eslint no-bitwise:0*/ | ||
if (entities.hasOwnProperty(name)) { | ||
if (has(entities, name)) { | ||
return entities[name]; | ||
@@ -98,8 +107,33 @@ } else if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { | ||
//////////////////////////////////////////////////////////////////////////////// | ||
exports.assign = assign; | ||
exports.isString = isString; | ||
exports.unescapeMd = unescapeMd; | ||
var HTML_ESCAPE_TEST_RE = /[&<>"]/; | ||
var HTML_ESCAPE_REPLACE_RE = /[&<>"]/g; | ||
var HTML_REPLACEMENTS = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"' | ||
}; | ||
function replaceUnsafeChar(ch) { | ||
return HTML_REPLACEMENTS[ch]; | ||
} | ||
function escapeHtml(str) { | ||
if (HTML_ESCAPE_TEST_RE.test(str)) { | ||
return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar); | ||
} | ||
return str; | ||
} | ||
//////////////////////////////////////////////////////////////////////////////// | ||
exports.assign = assign; | ||
exports.isString = isString; | ||
exports.has = has; | ||
exports.unescapeMd = unescapeMd; | ||
exports.isValidEntityCode = isValidEntityCode; | ||
exports.fromCodePoint = fromCodePoint; | ||
exports.replaceEntities = replaceEntities; | ||
exports.fromCodePoint = fromCodePoint; | ||
exports.replaceEntities = replaceEntities; | ||
exports.escapeHtml = escapeHtml; |
@@ -42,3 +42,4 @@ // Remarkable default options | ||
'references', | ||
'abbr2' | ||
'abbr2', | ||
'footnote_tail' | ||
] | ||
@@ -70,2 +71,3 @@ }, | ||
'escape', | ||
'footnote_ref', | ||
'htmltag', | ||
@@ -72,0 +74,0 @@ 'links', |
@@ -138,1 +138,4 @@ // Main perser class | ||
module.exports = Remarkable; | ||
// Expose helpers, useful for custom renderer functions | ||
module.exports.utils = require('./common/utils'); |
@@ -17,2 +17,3 @@ // Block parser | ||
[ 'list', require('./rules_block/list'), [ 'paragraph', 'blockquote' ] ], | ||
[ 'footnote', require('./rules_block/footnote'), [ 'paragraph' ] ], | ||
[ 'heading', require('./rules_block/heading'), [ 'paragraph', 'blockquote' ] ], | ||
@@ -22,2 +23,3 @@ [ 'lheading', require('./rules_block/lheading') ], | ||
[ 'table', require('./rules_block/table'), [ 'paragraph' ] ], | ||
[ 'deflist', require('./rules_block/deflist'), [ 'paragraph' ] ], | ||
[ 'paragraph', require('./rules_block/paragraph') ] | ||
@@ -24,0 +26,0 @@ ]; |
@@ -10,10 +10,11 @@ // Class of top level (`core`) rules | ||
var _rules = [ | ||
[ 'block', require('./rules_core/block') ], | ||
[ 'abbr', require('./rules_core/abbr') ], | ||
[ 'references', require('./rules_core/references') ], | ||
[ 'inline', require('./rules_core/inline') ], | ||
[ 'abbr2', require('./rules_core/abbr2') ], | ||
[ 'replacements', require('./rules_core/replacements') ], | ||
[ 'smartquotes', require('./rules_core/smartquotes') ], | ||
[ 'linkify', require('./rules_core/linkify') ] | ||
[ 'block', require('./rules_core/block') ], | ||
[ 'abbr', require('./rules_core/abbr') ], | ||
[ 'references', require('./rules_core/references') ], | ||
[ 'inline', require('./rules_core/inline') ], | ||
[ 'footnote_tail', require('./rules_core/footnote_tail') ], | ||
[ 'abbr2', require('./rules_core/abbr2') ], | ||
[ 'replacements', require('./rules_core/replacements') ], | ||
[ 'smartquotes', require('./rules_core/smartquotes') ], | ||
[ 'linkify', require('./rules_core/linkify') ] | ||
]; | ||
@@ -20,0 +21,0 @@ |
@@ -14,16 +14,18 @@ // Inline parser | ||
var _rules = [ | ||
[ 'text', require('./rules_inline/text') ], | ||
[ 'newline', require('./rules_inline/newline') ], | ||
[ 'escape', require('./rules_inline/escape') ], | ||
[ 'backticks', require('./rules_inline/backticks') ], | ||
[ 'del', require('./rules_inline/del') ], | ||
[ 'ins', require('./rules_inline/ins') ], | ||
[ 'mark', require('./rules_inline/mark') ], | ||
[ 'emphasis', require('./rules_inline/emphasis') ], | ||
[ 'sub', require('./rules_inline/sub') ], | ||
[ 'sup', require('./rules_inline/sup') ], | ||
[ 'links', require('./rules_inline/links') ], | ||
[ 'autolink', require('./rules_inline/autolink') ], | ||
[ 'htmltag', require('./rules_inline/htmltag') ], | ||
[ 'entity', require('./rules_inline/entity') ] | ||
[ 'text', require('./rules_inline/text') ], | ||
[ 'newline', require('./rules_inline/newline') ], | ||
[ 'escape', require('./rules_inline/escape') ], | ||
[ 'backticks', require('./rules_inline/backticks') ], | ||
[ 'del', require('./rules_inline/del') ], | ||
[ 'ins', require('./rules_inline/ins') ], | ||
[ 'mark', require('./rules_inline/mark') ], | ||
[ 'emphasis', require('./rules_inline/emphasis') ], | ||
[ 'sub', require('./rules_inline/sub') ], | ||
[ 'sup', require('./rules_inline/sup') ], | ||
[ 'links', require('./rules_inline/links') ], | ||
[ 'footnote_inline', require('./rules_inline/footnote_inline') ], | ||
[ 'footnote_ref', require('./rules_inline/footnote_ref') ], | ||
[ 'autolink', require('./rules_inline/autolink') ], | ||
[ 'htmltag', require('./rules_inline/htmltag') ], | ||
[ 'entity', require('./rules_inline/entity') ] | ||
]; | ||
@@ -30,0 +32,0 @@ |
@@ -5,4 +5,6 @@ 'use strict'; | ||
var assign = require('./common/utils').assign; | ||
var has = require('./common/utils').has; | ||
var unescapeMd = require('./common/utils').unescapeMd; | ||
var replaceEntities = require('./common/utils').replaceEntities; | ||
var escapeHtml = require('./common/utils').escapeHtml; | ||
@@ -13,22 +15,2 @@ | ||
var HTML_ESCAPE_TEST_RE = /[&<>"]/; | ||
var HTML_ESCAPE_REPLACE_RE = /[&<>"]/g; | ||
var HTML_REPLACEMENTS = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"' | ||
}; | ||
function replaceUnsafeChar(ch) { | ||
return HTML_REPLACEMENTS[ch]; | ||
} | ||
function escapeHtml(str) { | ||
if (HTML_ESCAPE_TEST_RE.test(str)) { | ||
return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar); | ||
} | ||
return str; | ||
} | ||
function nextToken(tokens, idx) { | ||
@@ -79,12 +61,25 @@ if (++idx >= tokens.length - 2) { return idx; } | ||
rules.fence = function (tokens, idx, options /*, env */) { | ||
rules.fence = function (tokens, idx, options, env, self) { | ||
var token = tokens[idx]; | ||
var langClass = ''; | ||
var langPrefix = options.langPrefix; | ||
var params, langName = ''; | ||
var langName = '', fenceName; | ||
var highlighted; | ||
if (token.params) { | ||
params = token.params.split(/ +/g); | ||
langName = escapeHtml(replaceEntities(unescapeMd(params[0]))); | ||
// | ||
// ```foo bar | ||
// | ||
// Try custom renderer "foo" first. That will simplify overwrite | ||
// for diagrams, latex, and any other fenced block with custom look | ||
// | ||
fenceName = token.params.split(/\s+/g)[0]; | ||
if (has(self.rules.fence_custom, fenceName)) { | ||
return self.rules.fence_custom[fenceName](tokens, idx, options, env, self); | ||
} | ||
langName = escapeHtml(replaceEntities(unescapeMd(fenceName))); | ||
langClass = ' class="' + langPrefix + langName + '"'; | ||
@@ -105,2 +100,3 @@ } | ||
rules.fence_custom = {}; | ||
@@ -289,2 +285,55 @@ rules.heading_open = function (tokens, idx /*, options, env */) { | ||
rules.footnote_ref = function (tokens, idx) { | ||
var n = Number(tokens[idx].id + 1).toString(); | ||
var id = 'fnref' + n; | ||
if (tokens[idx].subId > 0) { | ||
id += ':' + tokens[idx].subId; | ||
} | ||
return '<sup class="footnote-ref"><a href="#fn' + n + '" id="' + id + '">[' + n + ']</a></sup>'; | ||
}; | ||
rules.footnote_block_open = function (tokens, idx, options) { | ||
return (options.xhtmlOut ? '<hr class="footnotes-sep" />\n' : '<hr class="footnotes-sep">\n') + | ||
'<section class="footnotes">\n' + | ||
'<ol class="footnotes-list">\n'; | ||
}; | ||
rules.footnote_block_close = function () { | ||
return '</ol>\n</section>\n'; | ||
}; | ||
rules.footnote_open = function (tokens, idx) { | ||
var id = Number(tokens[idx].id + 1).toString(); | ||
return '<li id="fn' + id + '" class="footnote-item">'; | ||
}; | ||
rules.footnote_close = function () { | ||
return '</li>\n'; | ||
}; | ||
rules.footnote_anchor = function (tokens, idx) { | ||
var n = Number(tokens[idx].id + 1).toString(); | ||
var id = 'fnref' + n; | ||
if (tokens[idx].subId > 0) { | ||
id += ':' + tokens[idx].subId; | ||
} | ||
return ' <a href="#' + id + '" class="footnote-backref">↩</a>'; | ||
}; | ||
rules.dl_open = function() { | ||
return '<dl>\n'; | ||
}; | ||
rules.dt_open = function() { | ||
return '<dt>'; | ||
}; | ||
rules.dd_open = function() { | ||
return '<dd>'; | ||
}; | ||
rules.dl_close = function() { | ||
return '</dl>\n'; | ||
}; | ||
rules.dt_close = function() { | ||
return '</dt>\n'; | ||
}; | ||
rules.dd_close = function() { | ||
return '</dd>\n'; | ||
}; | ||
// Renderer class | ||
@@ -294,2 +343,4 @@ function Renderer() { | ||
this.rules = assign({}, rules); | ||
// exported helper, for custom rules only | ||
this.getBreak = getBreak; | ||
} | ||
@@ -303,3 +354,3 @@ | ||
for (var i = 0, len = tokens.length; i < len; i++) { | ||
result += _rules[tokens[i].type](tokens, i, options, env); | ||
result += _rules[tokens[i].type](tokens, i, options, env, this); | ||
} | ||
@@ -320,3 +371,3 @@ | ||
} else { | ||
result += _rules[tokens[i].type](tokens, i, options, env); | ||
result += _rules[tokens[i].type](tokens, i, options, env, this); | ||
} | ||
@@ -323,0 +374,0 @@ } |
@@ -35,2 +35,3 @@ // Parser state class | ||
this.parentType = 'root'; // if `list`, block parser stops on two newlines | ||
this.ddIndent = -1; // indent of the current dd block (-1 if there isn't any) | ||
@@ -37,0 +38,0 @@ this.level = 0; |
@@ -6,2 +6,3 @@ // Process html entity - {, ¯, ", ... | ||
var entities = require('../common/entities'); | ||
var has = require('../common/utils').has; | ||
var isValidEntityCode = require('../common/utils').isValidEntityCode; | ||
@@ -36,3 +37,3 @@ var fromCodePoint = require('../common/utils').fromCodePoint; | ||
if (match) { | ||
if (entities.hasOwnProperty(match[1])) { | ||
if (has(entities, match[1])) { | ||
if (!silent) { state.pending += entities[match[1]]; } | ||
@@ -39,0 +40,0 @@ state.pos += match[0].length; |
{ | ||
"name": "remarkable", | ||
"version": "1.4.1", | ||
"description": "Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one.", | ||
"version": "1.4.2", | ||
"description": "Markdown parser, done right.", | ||
"keywords": [ | ||
"markdown", | ||
"md", | ||
"commonmark", | ||
"parser" | ||
"parser", | ||
"commonmark" | ||
], | ||
@@ -26,4 +25,3 @@ "homepage": "https://github.com/jonschlinkert/remarkable", | ||
"argparse": "~ 0.1.15", | ||
"autolinker": "~ 0.12.3", | ||
"coveralls": "^2.11.2" | ||
"autolinker": "~ 0.15.0" | ||
}, | ||
@@ -35,2 +33,4 @@ "devDependencies": { | ||
"browserify": "*", | ||
"commonmark": "0.12.0", | ||
"coveralls": "^2.11.2", | ||
"eslint": "0.9.1", | ||
@@ -40,2 +40,3 @@ "eslint-plugin-nodeca": "^1.0.0", | ||
"jade": "^1.6.0", | ||
"marked": "0.3.2", | ||
"stylus": "^0.49.1", | ||
@@ -42,0 +43,0 @@ "mocha": "*", |
@@ -175,2 +175,3 @@ # remarkable | ||
- [abbreviations](https://michelf.ca/projects/php-markdown/extra/#abbr) | ||
- [footnotes](http://johnmacfarlane.net/pandoc/README.html#footnotes) | ||
- __\<ins>__ - `++inserted text++` (experimental) | ||
@@ -197,2 +198,21 @@ - __\<mark>__ - `==marked text==` (experimental) | ||
}); | ||
// | ||
// Manually enable rules, disabled by default: | ||
// | ||
var md = new Remarkable(); | ||
md.block.ruler.core([ | ||
'abbr' | ||
]); | ||
md.block.ruler.enable([ | ||
'footnote', | ||
'deflist' | ||
]); | ||
md.block.ruler.enable([ | ||
'footnote_inline', | ||
'ins', | ||
'mark', | ||
'sub', | ||
'sup' | ||
]); | ||
``` | ||
@@ -199,0 +219,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
544690
2
68
14662
327
14
+ Addedautolinker@0.15.3(transitive)
- Removedcoveralls@^2.11.2
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedargparse@1.0.10(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@0.2.01.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedautolinker@0.12.5(transitive)
- Removedaws-sign2@0.6.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedboom@2.10.1(transitive)
- Removedcaseless@0.11.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removedcoveralls@2.13.3(transitive)
- Removedcryptiles@2.0.5(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedesprima@2.7.3(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.1.4(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removedgenerate-object-property@1.2.0(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-validator@2.0.6(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhawk@3.1.3(transitive)
- Removedhoek@2.16.3(transitive)
- Removedhttp-signature@1.1.1(transitive)
- Removedis-my-ip-valid@1.0.1(transitive)
- Removedis-my-json-valid@2.20.6(transitive)
- Removedis-property@1.0.2(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjs-yaml@3.6.1(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsonpointer@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlcov-parse@0.0.10(transitive)
- Removedlog-driver@1.2.5(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedminimist@1.2.0(transitive)
- Removedoauth-sign@0.8.2(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedpunycode@1.4.1(transitive)
- Removedqs@6.3.3(transitive)
- Removedrequest@2.79.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsntp@1.0.9(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstringstream@0.0.6(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtough-cookie@2.3.4(transitive)
- Removedtunnel-agent@0.4.3(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedxtend@4.0.2(transitive)
Updatedautolinker@~ 0.15.0