Browse Source

upgrade less.js, marked.js

master
Christian Müller 11 years ago
parent
commit
801477ef6b
  1. 11
      resources/public/js/less.js
  2. 113
      resources/public/js/marked.js
  3. 3
      resources/public/js/themes.js

11
resources/public/js/less.js

File diff suppressed because one or more lines are too long

113
resources/public/js/marked.js

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
/**
* marked - a markdown parser
* Copyright (c) 2011-2013, Christopher Jeffrey. (MIT Licensed)
* Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
* https://github.com/chjj/marked
*/
@ -18,9 +18,9 @@ var block = { @@ -18,9 +18,9 @@ var block = {
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
nptable: noop,
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/,
list: /^( *)(bull) [\s\S]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/,
blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
table: noop,
paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
@ -35,13 +35,18 @@ block.item = replace(block.item, 'gm') @@ -35,13 +35,18 @@ block.item = replace(block.item, 'gm')
block.list = replace(block.list)
(/bull/g, block.bullet)
('hr', /\n+(?=(?: *[-*_]){3,} *(?:\n+|$))/)
('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
('def', '\\n+(?=' + block.def.source + ')')
();
block.blockquote = replace(block.blockquote)
('def', block.def)
();
block._tag = '(?!(?:'
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
+ '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|@)\\b';
+ '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
block.html = replace(block.html)
('comment', /<!--[\s\S]*?-->/)
@ -141,7 +146,7 @@ Lexer.prototype.lex = function(src) { @@ -141,7 +146,7 @@ Lexer.prototype.lex = function(src) {
* Lexing
*/
Lexer.prototype.token = function(src, top) {
Lexer.prototype.token = function(src, top, bq) {
var src = src.replace(/^ +$/gm, '')
, next
, loose
@ -264,7 +269,7 @@ Lexer.prototype.token = function(src, top) { @@ -264,7 +269,7 @@ Lexer.prototype.token = function(src, top) {
// Pass `top` to keep the current
// "toplevel" state. This is exactly
// how markdown.pl works.
this.token(cap, top);
this.token(cap, top, true);
this.tokens.push({
type: 'blockquote_end'
@ -333,7 +338,7 @@ Lexer.prototype.token = function(src, top) { @@ -333,7 +338,7 @@ Lexer.prototype.token = function(src, top) {
});
// Recurse.
this.token(item, false);
this.token(item, false, bq);
this.tokens.push({
type: 'list_item_end'
@ -361,7 +366,7 @@ Lexer.prototype.token = function(src, top) { @@ -361,7 +366,7 @@ Lexer.prototype.token = function(src, top) {
}
// def
if (top && (cap = this.rules.def.exec(src))) {
if ((!bq && top) && (cap = this.rules.def.exec(src))) {
src = src.substring(cap[0].length);
this.tokens.links[cap[1].toLowerCase()] = {
href: cap[2],
@ -515,6 +520,7 @@ function InlineLexer(links, options) { @@ -515,6 +520,7 @@ function InlineLexer(links, options) {
this.links = links;
this.rules = inline.normal;
this.renderer = this.options.renderer || new Renderer;
this.renderer.options = this.options;
if (!this.links) {
throw new
@ -583,7 +589,7 @@ InlineLexer.prototype.output = function(src) { @@ -583,7 +589,7 @@ InlineLexer.prototype.output = function(src) {
}
// url (gfm)
if (cap = this.rules.url.exec(src)) {
if (!this.inLink && (cap = this.rules.url.exec(src))) {
src = src.substring(cap[0].length);
text = escape(cap[1]);
href = text;
@ -593,6 +599,11 @@ InlineLexer.prototype.output = function(src) { @@ -593,6 +599,11 @@ InlineLexer.prototype.output = function(src) {
// tag
if (cap = this.rules.tag.exec(src)) {
if (!this.inLink && /^<a /i.test(cap[0])) {
this.inLink = true;
} else if (this.inLink && /^<\/a>/i.test(cap[0])) {
this.inLink = false;
}
src = src.substring(cap[0].length);
out += this.options.sanitize
? escape(cap[0])
@ -603,10 +614,12 @@ InlineLexer.prototype.output = function(src) { @@ -603,10 +614,12 @@ InlineLexer.prototype.output = function(src) {
// link
if (cap = this.rules.link.exec(src)) {
src = src.substring(cap[0].length);
this.inLink = true;
out += this.outputLink(cap, {
href: cap[2],
title: cap[3]
});
this.inLink = false;
continue;
}
@ -621,7 +634,9 @@ InlineLexer.prototype.output = function(src) { @@ -621,7 +634,9 @@ InlineLexer.prototype.output = function(src) {
src = cap[0].substring(1) + src;
continue;
}
this.inLink = true;
out += this.outputLink(cap, link);
this.inLink = false;
continue;
}
@ -735,13 +750,13 @@ InlineLexer.prototype.mangle = function(text) { @@ -735,13 +750,13 @@ InlineLexer.prototype.mangle = function(text) {
* Renderer
*/
function Renderer() {}
Renderer.prototype.code = function(code, lang, escaped, options) {
options = options || {};
function Renderer(options) {
this.options = options || {};
}
if (options.highlight) {
var out = options.highlight(code, lang);
Renderer.prototype.code = function(code, lang, escaped) {
if (this.options.highlight) {
var out = this.options.highlight(code, lang);
if (out != null && out !== code) {
escaped = true;
code = out;
@ -755,10 +770,10 @@ Renderer.prototype.code = function(code, lang, escaped, options) { @@ -755,10 +770,10 @@ Renderer.prototype.code = function(code, lang, escaped, options) {
}
return '<pre><code class="'
+ options.langPrefix
+ lang
+ this.options.langPrefix
+ escape(lang, true)
+ '">'
+ (escaped ? code : escape(code))
+ (escaped ? code : escape(code, true))
+ '\n</code></pre>\n';
};
@ -770,11 +785,11 @@ Renderer.prototype.html = function(html) { @@ -770,11 +785,11 @@ Renderer.prototype.html = function(html) {
return html;
};
Renderer.prototype.heading = function(text, level, raw, options) {
Renderer.prototype.heading = function(text, level, raw) {
return '<h'
+ level
+ ' id="'
+ options.headerPrefix
+ this.options.headerPrefix
+ raw.toLowerCase().replace(/[^\w]+/g, '-')
+ '">'
+ text
@ -784,7 +799,7 @@ Renderer.prototype.heading = function(text, level, raw, options) { @@ -784,7 +799,7 @@ Renderer.prototype.heading = function(text, level, raw, options) {
};
Renderer.prototype.hr = function() {
return '<hr>\n';
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
};
Renderer.prototype.list = function(body, ordered) {
@ -837,7 +852,7 @@ Renderer.prototype.codespan = function(text) { @@ -837,7 +852,7 @@ Renderer.prototype.codespan = function(text) {
};
Renderer.prototype.br = function() {
return '<br>';
return this.options.xhtml ? '<br/>' : '<br>';
};
Renderer.prototype.del = function(text) {
@ -845,6 +860,18 @@ Renderer.prototype.del = function(text) { @@ -845,6 +860,18 @@ Renderer.prototype.del = function(text) {
};
Renderer.prototype.link = function(href, title, text) {
if (this.options.sanitize) {
try {
var prot = decodeURIComponent(unescape(href))
.replace(/[^\w:]/g, '')
.toLowerCase();
} catch (e) {
return '';
}
if (prot.indexOf('javascript:') === 0) {
return '';
}
}
var out = '<a href="' + href + '"';
if (title) {
out += ' title="' + title + '"';
@ -858,7 +885,7 @@ Renderer.prototype.image = function(href, title, text) { @@ -858,7 +885,7 @@ Renderer.prototype.image = function(href, title, text) {
if (title) {
out += ' title="' + title + '"';
}
out += '>';
out += this.options.xhtml ? '/>' : '>';
return out;
};
@ -872,6 +899,7 @@ function Parser(options) { @@ -872,6 +899,7 @@ function Parser(options) {
this.options = options || marked.defaults;
this.options.renderer = this.options.renderer || new Renderer;
this.renderer = this.options.renderer;
this.renderer.options = this.options;
}
/**
@ -945,15 +973,12 @@ Parser.prototype.tok = function() { @@ -945,15 +973,12 @@ Parser.prototype.tok = function() {
return this.renderer.heading(
this.inline.output(this.token.text),
this.token.depth,
this.token.text,
this.options
);
this.token.text);
}
case 'code': {
return this.renderer.code(this.token.text,
this.token.lang,
this.token.escaped,
this.options);
this.token.escaped);
}
case 'table': {
var header = ''
@ -1057,6 +1082,19 @@ function escape(html, encode) { @@ -1057,6 +1082,19 @@ function escape(html, encode) {
.replace(/'/g, '&#39;');
}
function unescape(html) {
return html.replace(/&([#\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 || '';
@ -1116,8 +1154,13 @@ function marked(src, opt, callback) { @@ -1116,8 +1154,13 @@ function marked(src, opt, callback) {
pending = tokens.length;
var done = function() {
var out, err;
var done = function(err) {
if (err) {
opt.highlight = highlight;
return callback(err);
}
var out;
try {
out = Parser.parse(tokens, opt);
@ -1146,6 +1189,7 @@ function marked(src, opt, callback) { @@ -1146,6 +1189,7 @@ function marked(src, opt, callback) {
return --pending || done();
}
return highlight(token.text, token.lang, function(err, code) {
if (err) return done(err);
if (code == null || code === token.text) {
return --pending || done();
}
@ -1194,7 +1238,8 @@ marked.defaults = { @@ -1194,7 +1238,8 @@ marked.defaults = {
langPrefix: 'lang-',
smartypants: false,
headerPrefix: '',
renderer: new Renderer
renderer: new Renderer,
xhtml: false
};
/**
@ -1214,7 +1259,7 @@ marked.inlineLexer = InlineLexer.output; @@ -1214,7 +1259,7 @@ marked.inlineLexer = InlineLexer.output;
marked.parse = marked;
if (typeof exports === 'object') {
if (typeof module !== 'undefined' && typeof exports === 'object') {
module.exports = marked;
} else if (typeof define === 'function' && define.amd) {
define(function() { return marked; });

3
resources/public/js/themes.js

@ -108,9 +108,8 @@ fileref.setAttribute("type", "text/css") @@ -108,9 +108,8 @@ fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", fontURL)
document.getElementsByTagName("head")[0].appendChild(fileref)
less.modifyVars(vars);
function showFooter(){
less.modifyVars(vars);
var elem = $("footer");
if(!elem) return;
if(window.innerHeight * 0.85 >= document.body.clientHeight) {

Loading…
Cancel
Save