X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2FMarkdown.js;h=dff793e77c014064ba5b1bedb1765ca7a573c2ca;hb=dc5d9380aff25134bf025953bdafe40b580337ff;hp=c8260b7e7c8d1b2d6ca9012fdf14afcb7145ad0d;hpb=1e66e40774fb5b23d7f121e0f46923b3972d3989;p=roojs1 diff --git a/Roo/Markdown.js b/Roo/Markdown.js index c8260b7e7c..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; @@ -366,7 +444,7 @@ Roo.Markdown.toHtml = function(text) { loose = next || /\n\n(?!\s*$)/.test(item); if (i !== l - 1) { next = item.charAt(item.length - 1) === '\n'; - if (!loose) loose = next; + if (!loose) { loose = next; } } this.tokens.push({ @@ -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; @@ -648,7 +726,7 @@ Roo.Markdown.toHtml = function(text) { ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) - : cap[0] + : cap[0]; continue; } @@ -750,7 +828,7 @@ Roo.Markdown.toHtml = function(text) { */ InlineLexer.prototype.smartypants = function(text) { - if (!this.options.smartypants) return text; + if (!this.options.smartypants) { return text; } return text // em-dashes .replace(/---/g, '\u2014') @@ -773,7 +851,7 @@ Roo.Markdown.toHtml = function(text) { */ InlineLexer.prototype.mangle = function(text) { - if (!this.options.mangle) return text; + if (!this.options.mangle) { return text; } var out = '' , l = text.length , i = 0 @@ -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 '