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 '