*/
-//
-// marked usage:
-//
-// alert( Roo.Markdown.toHtml("Markdown *rocks*.") );
-//
-// Note: move the sample code to the bottom of this
-// file before uncommenting it.
-//
-
+/**
+ *
+ * Roo.Markdown - is a very crude wrapper around marked..
+ *
+ * usage:
+ *
+ * alert( Roo.Markdown.toHtml("Markdown *rocks*.") );
+ *
+ * Note: move the sample code to the bottom of this
+ * file before uncommenting it.
+ *
+ */
-//
-// Showdown namespace
-//
Roo.Markdown = {};
Roo.Markdown.toHtml = function(text) {
- var c = new Roo.ux.Markdown.marked.setOptions({
- renderer: new Roo.ux.Showdown.marked.Renderer(),
+ var c = new Roo.Markdown.marked.setOptions({
+ renderer: new Roo.Markdown.marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
smartLists: true,
smartypants: false
});
-
+ // A FEW HACKS!!?
+
+ text = text.replace(/\\\n/g,' ');
return Roo.Markdown.marked(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, '"')
+ .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*)+/,
* Block Lexer
*/
- function Lexer(options) {
+ var Lexer = function (options) {
this.tokens = [];
this.tokens.links = {};
this.options = options || marked.defaults;
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({
* Inline Lexer & Compiler
*/
- function InlineLexer(links, options) {
+ var InlineLexer = function (links, options) {
this.options = options || marked.defaults;
this.links = links;
this.rules = inline.normal;
? this.options.sanitizer
? this.options.sanitizer(cap[0])
: escape(cap[0])
- : cap[0]
+ : cap[0];
continue;
}
*/
InlineLexer.prototype.smartypants = function(text) {
- if (!this.options.smartypants) return text;
+ if (!this.options.smartypants) { return text; }
return text
// em-dashes
.replace(/---/g, '\u2014')
*/
InlineLexer.prototype.mangle = function(text) {
- if (!this.options.mangle) return text;
+ if (!this.options.mangle) { return text; }
var out = ''
, l = text.length
, i = 0
* Renderer
*/
- function Renderer(options) {
+ /**
+ * eval:var:Renderer
+ */
+
+ var Renderer = function (options) {
this.options = options || {};
}
};
Renderer.prototype.table = function(header, body) {
- return '<table>\n'
+ return '<table class="table table-striped">\n'
+ '<thead>\n'
+ header
+ '</thead>\n'
/**
* Parsing & Compiling
*/
+ /**
+ * eval:var:Parser
+ */
- function Parser(options) {
+ var Parser= function (options) {
this.tokens = [];
this.token = null;
this.options = options || marked.defaults;
}
}
};
-
- /**
- * Helpers
- */
-
- function escape(html, encode) {
- return html
- .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
- .replace(/</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;
}
pending = tokens.length;
-
+ /**
+ * eval:var:done
+ */
var done = function(err) {
if (err) {
opt.highlight = highlight;
delete opt.highlight;
- if (!pending) return done();
+ if (!pending) { return done(); }
for (; i < tokens.length; i++) {
(function(token) {
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();
}
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.';