X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2FMarkdown.js;h=dff793e77c014064ba5b1bedb1765ca7a573c2ca;hb=75cbc4ce04c9c01ac47671cb01320ce699128d00;hp=abf748e9c95799a615ded598521a29f8b2ec68c2;hpb=f105a7a2f070c2051bd41b5e54389ca5239df6aa;p=roojs1 diff --git a/Roo/Markdown.js b/Roo/Markdown.js index abf748e9c9..dff793e77c 100644 --- a/Roo/Markdown.js +++ b/Roo/Markdown.js @@ -32,7 +32,9 @@ Roo.Markdown.toHtml = function(text) { smartLists: true, smartypants: false }); - + // A FEW HACKS!!? + + text = text.replace(/\\\n/g,' '); return Roo.Markdown.marked(text); }; // @@ -43,10 +45,86 @@ Roo.Markdown.toHtml = function(text) { // (function() { + /** + * eval:var:escape + * eval:var:unescape + * eval:var:replace + */ + + /** + * Helpers + */ + + var escape = function (html, encode) { + return html + .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); + } + + var unescape = function (html) { + // explicitly match decimal, hex, and named HTML entities + return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) { + n = n.toLowerCase(); + if (n === 'colon') { return ':'; } + if (n.charAt(0) === '#') { + return n.charAt(1) === 'x' + ? String.fromCharCode(parseInt(n.substring(2), 16)) + : String.fromCharCode(+n.substring(1)); + } + return ''; + }); + } + + var replace = function (regex, opt) { + regex = regex.source; + opt = opt || ''; + return function self(name, val) { + if (!name) { return new RegExp(regex, opt); } + val = val.source || val; + val = val.replace(/(^|[^\[])\^/g, '$1'); + regex = regex.replace(name, val); + return self; + }; + } + + + /** + * eval:var:noop + */ + var noop = function () {} + noop.exec = noop; + + /** + * eval:var:merge + */ + var merge = function (obj) { + var i = 1 + , target + , key; + + for (; i < arguments.length; i++) { + target = arguments[i]; + for (key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + obj[key] = target[key]; + } + } + } + + return obj; + } + + /** * Block-Level Grammar */ + + + var block = { newline: /^\n+/, code: /^( {4}[^\n]+\n*)+/, @@ -136,7 +214,7 @@ Roo.Markdown.toHtml = function(text) { * Block Lexer */ - function Lexer(options) { + var Lexer = function (options) { this.tokens = []; this.tokens.links = {}; this.options = options || marked.defaults; @@ -554,7 +632,7 @@ Roo.Markdown.toHtml = function(text) { * Inline Lexer & Compiler */ - function InlineLexer(links, options) { + var InlineLexer = function (links, options) { this.options = options || marked.defaults; this.links = links; this.rules = inline.normal; @@ -794,7 +872,11 @@ Roo.Markdown.toHtml = function(text) { * Renderer */ - function Renderer(options) { + /** + * eval:var:Renderer + */ + + var Renderer = function (options) { this.options = options || {}; } @@ -863,7 +945,7 @@ Roo.Markdown.toHtml = function(text) { }; Renderer.prototype.table = function(header, body) { - return '\n' + return '
\n' + '\n' + header + '\n' @@ -943,8 +1025,11 @@ Roo.Markdown.toHtml = function(text) { /** * Parsing & Compiling */ + /** + * eval:var:Parser + */ - function Parser(options) { + var Parser= function (options) { this.tokens = []; this.token = null; this.options = options || marked.defaults; @@ -1119,72 +1204,15 @@ Roo.Markdown.toHtml = function(text) { } } }; - - /** - * Helpers - */ - - function escape(html, encode) { - return html - .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); - } - - function unescape(html) { - // explicitly match decimal, hex, and named HTML entities - return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) { - n = n.toLowerCase(); - if (n === 'colon') { return ':'; } - if (n.charAt(0) === '#') { - return n.charAt(1) === 'x' - ? String.fromCharCode(parseInt(n.substring(2), 16)) - : String.fromCharCode(+n.substring(1)); - } - return ''; - }); - } - - function replace(regex, opt) { - regex = regex.source; - opt = opt || ''; - return function self(name, val) { - if (!name) return new RegExp(regex, opt); - val = val.source || val; - val = val.replace(/(^|[^\[])\^/g, '$1'); - regex = regex.replace(name, val); - return self; - }; - } - - function noop() {} - noop.exec = noop; - - function merge(obj) { - var i = 1 - , target - , key; - - for (; i < arguments.length; i++) { - target = arguments[i]; - for (key in target) { - if (Object.prototype.hasOwnProperty.call(target, key)) { - obj[key] = target[key]; - } - } - } - - return obj; - } - + /** * Marked */ - - function marked(src, opt, callback) { + /** + * eval:var:marked + */ + var marked = function (src, opt, callback) { if (callback || typeof opt === 'function') { if (!callback) { callback = opt; @@ -1205,7 +1233,9 @@ Roo.Markdown.toHtml = function(text) { } pending = tokens.length; - + /** + * eval:var:done + */ var done = function(err) { if (err) { opt.highlight = highlight; @@ -1233,7 +1263,7 @@ Roo.Markdown.toHtml = function(text) { delete opt.highlight; - if (!pending) return done(); + if (!pending) { return done(); } for (; i < tokens.length; i++) { (function(token) { @@ -1241,7 +1271,7 @@ Roo.Markdown.toHtml = function(text) { return --pending || done(); } return highlight(token.text, token.lang, function(err, code) { - if (err) return done(err); + if (err) { return done(err); } if (code == null || code === token.text) { return --pending || done(); } @@ -1255,7 +1285,7 @@ Roo.Markdown.toHtml = function(text) { return; } try { - if (opt) opt = merge({}, marked.defaults, opt); + if (opt) { opt = merge({}, marked.defaults, opt); } return Parser.parse(Lexer.lex(src, opt), opt); } catch (e) { e.message += '\nPlease report this to https://github.com/chjj/marked.';