remarkable
Advanced tools
Comparing version 1.2.2 to 1.3.0
@@ -0,1 +1,8 @@ | ||
1.3.0 / 2014-10-29 | ||
------------------ | ||
- Fixed problem with minified & mangled browser version. | ||
- Changed ruler API. | ||
1.2.2 / 2014-10-29 | ||
@@ -2,0 +9,0 @@ ------------------ |
@@ -11,3 +11,3 @@ // Class of link replacement rules | ||
var _rules = [ | ||
require('./rules_text/linkify') | ||
[ 'linkify', require('./rules_text/linkify') ] | ||
]; | ||
@@ -24,3 +24,3 @@ | ||
for (var i = 0; i < _rules.length; i++) { | ||
this.ruler.after(_rules[i]); | ||
this.ruler.push(_rules[i][0], _rules[i][1]); | ||
} | ||
@@ -27,0 +27,0 @@ } |
@@ -11,17 +11,16 @@ // Block parser | ||
var _rules = []; | ||
var _rules = [ | ||
[ 'code', require('./rules_block/code') ], | ||
[ 'fences', require('./rules_block/fences'), [ 'paragraph', 'blockquote', 'list' ] ], | ||
[ 'blockquote', require('./rules_block/blockquote'), [ 'paragraph', 'blockquote', 'list' ] ], | ||
[ 'hr', require('./rules_block/hr'), [ 'paragraph', 'blockquote', 'list' ] ], | ||
[ 'list', require('./rules_block/list'), [ 'paragraph', 'blockquote' ] ], | ||
[ 'heading', require('./rules_block/heading'), [ 'paragraph', 'blockquote' ] ], | ||
[ 'lheading', require('./rules_block/lheading') ], | ||
[ 'htmlblock', require('./rules_block/htmlblock'), [ 'paragraph', 'blockquote' ] ], | ||
[ 'table', require('./rules_block/table'), [ 'paragraph' ] ], | ||
[ 'paragraph', require('./rules_block/paragraph') ] | ||
]; | ||
// `list` should be after `hr`, but before `heading` | ||
_rules.push([ require('./rules_block/code') ]); | ||
_rules.push([ require('./rules_block/fences'), 'paragraph', 'blockquote', 'list' ]); | ||
_rules.push([ require('./rules_block/blockquote'), 'paragraph', 'blockquote', 'list' ]); | ||
_rules.push([ require('./rules_block/hr'), 'paragraph', 'blockquote', 'list' ]); | ||
_rules.push([ require('./rules_block/list'), 'paragraph', 'blockquote' ]); | ||
_rules.push([ require('./rules_block/heading'), 'paragraph', 'blockquote' ]); | ||
_rules.push([ require('./rules_block/lheading') ]); | ||
_rules.push([ require('./rules_block/htmlblock'), 'paragraph', 'blockquote' ]); | ||
_rules.push([ require('./rules_block/table'), 'paragraph' ]); | ||
_rules.push([ require('./rules_block/paragraph') ]); | ||
// Block Parser class | ||
@@ -38,3 +37,3 @@ // | ||
for (var i = 0; i < _rules.length; i++) { | ||
this.ruler.after(_rules[i][0], _rules[i].slice(1)); | ||
this.ruler.push(_rules[i][0], _rules[i][1], { alt: (_rules[i][2] || []).slice() }); | ||
} | ||
@@ -41,0 +40,0 @@ } |
@@ -12,20 +12,20 @@ // Inline parser | ||
var _rules = []; | ||
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') ] | ||
]; | ||
_rules.push(require('./rules_inline/text')); | ||
_rules.push(require('./rules_inline/newline')); | ||
_rules.push(require('./rules_inline/escape')); | ||
_rules.push(require('./rules_inline/backticks')); | ||
_rules.push(require('./rules_inline/del')); | ||
_rules.push(require('./rules_inline/ins')); | ||
_rules.push(require('./rules_inline/mark')); | ||
_rules.push(require('./rules_inline/emphasis')); | ||
_rules.push(require('./rules_inline/sub')); | ||
_rules.push(require('./rules_inline/sup')); | ||
_rules.push(require('./rules_inline/links')); | ||
_rules.push(require('./rules_inline/autolink')); | ||
_rules.push(require('./rules_inline/htmltag')); | ||
_rules.push(require('./rules_inline/entity')); | ||
var BAD_PROTOCOLS = [ 'vbscript', 'javascript', 'file' ]; | ||
@@ -64,3 +64,3 @@ | ||
for (var i = 0; i < _rules.length; i++) { | ||
this.ruler.after(_rules[i]); | ||
this.ruler.push(_rules[i][0], _rules[i][1]); | ||
} | ||
@@ -67,0 +67,0 @@ } |
111
lib/ruler.js
@@ -11,17 +11,3 @@ // Ruler is helper class to build responsibility chains from parse rules. | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// helpers | ||
function _class(obj) { return Object.prototype.toString.call(obj); } | ||
function isFunction(obj) { return _class(obj) === '[object Function]'; } | ||
function functionName(fn) { | ||
var ret = fn.toString(); | ||
ret = ret.substr('function '.length); | ||
ret = ret.substr(0, ret.indexOf('(')); | ||
return ret; | ||
} | ||
//////////////////////////////////////////////////////////////////////////////// | ||
function Ruler(compileFn) { | ||
@@ -55,20 +41,12 @@ this.compile = compileFn; // callback to call after each change | ||
// Replace/delete parser function | ||
// Replace rule function | ||
// | ||
Ruler.prototype.at = function (name, fn, altNames) { | ||
Ruler.prototype.at = function (name, fn, options) { | ||
var index = this.find(name); | ||
var opt = options || {}; | ||
if (index === -1) { | ||
throw new Error('Parser rule not found: ' + name); | ||
} | ||
if (index === -1) { throw new Error('Parser rule not found: ' + name); } | ||
if (isFunction(fn)) { | ||
this.rules[index].fn = fn; | ||
if (altNames) { | ||
this.rules[index].alt = altNames; | ||
} | ||
} else { | ||
this.rules = this.rules.slice(0, index).concat(this.rules.slice(index + 1)); | ||
} | ||
this.rules[index].fn = fn; | ||
this.rules[index].alt = opt.alt || []; | ||
this.compile(); | ||
@@ -78,31 +56,17 @@ }; | ||
// Add function to parser chain before one with given name. | ||
// Or add to start, if name not defined | ||
// Add rule to chain before one with given name. | ||
// | ||
Ruler.prototype.before = function (name, fn, altNames) { | ||
var index, rule; | ||
Ruler.prototype.before = function (beforeName, ruleName, fn, options) { | ||
var index = this.find(beforeName); | ||
var opt = options || {}; | ||
if (isFunction(name)) { | ||
altNames = fn; | ||
fn = name; | ||
name = ''; | ||
} | ||
if (index === -1) { throw new Error('Parser rule not found: ' + beforeName); } | ||
rule = { | ||
name: functionName(fn), | ||
this.rules.splice(index, 0, { | ||
name: ruleName, | ||
enabled: true, | ||
fn: fn, | ||
alt: altNames || [] | ||
}; | ||
alt: opt.alt || [] | ||
}); | ||
if (!name) { | ||
this.rules.unshift(rule); | ||
} else { | ||
index = this.find(name); | ||
if (index === -1) { | ||
throw new Error('Parser rule not found: ' + name); | ||
} | ||
this.rules.splice(index, 0, rule); | ||
} | ||
this.compile(); | ||
@@ -112,31 +76,32 @@ }; | ||
// Add function to parser chain after one with given name. | ||
// Or add to end, if name not defined | ||
// Add rule to chain after one with given name. | ||
// | ||
Ruler.prototype.after = function (name, fn, altNames) { | ||
var index, rule; | ||
Ruler.prototype.after = function (afterName, ruleName, fn, options) { | ||
var index = this.find(afterName); | ||
var opt = options || {}; | ||
if (isFunction(name)) { | ||
altNames = fn; | ||
fn = name; | ||
name = ''; | ||
} | ||
if (index === -1) { throw new Error('Parser rule not found: ' + afterName); } | ||
rule = { | ||
name: functionName(fn), | ||
this.rules.splice(index + 1, 0, { | ||
name: ruleName, | ||
enabled: true, | ||
fn: fn, | ||
alt: altNames || [] | ||
}; | ||
alt: opt.alt || [] | ||
}); | ||
if (!name) { | ||
this.rules.push(rule); | ||
} else { | ||
index = this.find(name); | ||
if (index === -1) { | ||
throw new Error('Parser rule not found: ' + name); | ||
} | ||
this.rules.splice(index + 1, 0, rule); | ||
} | ||
this.compile(); | ||
}; | ||
// Add rule to the end of chain. | ||
// | ||
Ruler.prototype.push = function (ruleName, fn, options) { | ||
var opt = options || {}; | ||
this.rules.push({ | ||
name: ruleName, | ||
enabled: true, | ||
fn: fn, | ||
alt: opt.alt || [] | ||
}); | ||
this.compile(); | ||
@@ -143,0 +108,0 @@ }; |
@@ -15,4 +15,4 @@ // Class of typographic replacement rules | ||
var _rules = [ | ||
require('./rules_text/replace'), | ||
require('./rules_text/smartquotes') | ||
[ 'replace', require('./rules_text/replace') ], | ||
[ 'smartquotes', require('./rules_text/smartquotes') ] | ||
]; | ||
@@ -29,3 +29,3 @@ | ||
for (var i = 0; i < _rules.length; i++) { | ||
this.ruler.after(_rules[i]); | ||
this.ruler.push(_rules[i][0], _rules[i][1]); | ||
} | ||
@@ -32,0 +32,0 @@ } |
{ | ||
"name": "remarkable", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
471243
13016