[build] 4.6.1

This commit is contained in:
qingwei.li 2018-02-12 16:28:37 +08:00
parent 50fe22563b
commit 149d9929f8
5 changed files with 200 additions and 75 deletions

View File

@ -1,6 +1,6 @@
![logo](_media/icon.svg)
# docsify <small>4.6.0</small>
# docsify <small>4.6.1</small>
> A magical documentation site generator.

View File

@ -5,8 +5,9 @@
function cached (fn) {
var cache = Object.create(null);
return function cachedFn (str) {
var hit = cache[str];
return hit || (cache[str] = fn(str))
var key = isPrimitive(str) ? str : JSON.stringify(str);
var hit = cache[key];
return hit || (cache[key] = fn(str))
}
}
@ -2876,7 +2877,6 @@ var replaceSlug = cached(function (path) {
});
var cachedLinks = {};
var uid = 0;
function getAndRemoveConfig (str) {
if ( str === void 0 ) str = '';
@ -2894,46 +2894,37 @@ function getAndRemoveConfig (str) {
return { str: str, config: config }
}
var compileMedia = {
markdown: function markdown (url) {
var this$1 = this;
var id = "docsify-get-" + (uid++);
{
get(url, false).then(function (text) {
document.getElementById(id).innerHTML = this$1.compile(text);
});
return ("<div data-origin=\"" + url + "\" id=" + id + "></div>")
return {
url: url
}
},
iframe: function iframe (url, title) {
return ("<iframe src=\"" + url + "\" " + (title || 'width=100% height=400') + "></iframe>")
return {
code: ("<iframe src=\"" + url + "\" " + (title || 'width=100% height=400') + "></iframe>")
}
},
video: function video (url, title) {
return ("<video src=\"" + url + "\" " + (title || 'controls') + ">Not Support</video>")
return {
code: ("<video src=\"" + url + "\" " + (title || 'controls') + ">Not Support</video>")
}
},
audio: function audio (url, title) {
return ("<audio src=\"" + url + "\" " + (title || 'controls') + ">Not Support</audio>")
return {
code: ("<audio src=\"" + url + "\" " + (title || 'controls') + ">Not Support</audio>")
}
},
code: function code (url, title) {
var this$1 = this;
var lang = url.match(/\.(\w+)$/);
var id = "docsify-get-" + (uid++);
var ext = url.match(/\.(\w+)$/);
lang = title || (lang && lang[1]);
if (lang === 'md') { lang = 'markdown'; }
ext = title || (ext && ext[1]);
if (ext === 'md') { ext = 'markdown'; }
{
get(url, false).then(function (text) {
document.getElementById(id).innerHTML = this$1.compile(
'```' + ext + '\n' + text.replace(/`/g, '@qm@') + '\n```\n'
).replace(/@qm@/g, '`');
});
return ("<div data-origin=\"" + url + "\" id=" + id + "></div>")
return {
url: url,
lang: lang
}
}
};
@ -2961,12 +2952,18 @@ var Compiler = function Compiler (config, router) {
compile = marked;
}
this._marked = compile;
this.compile = cached(function (text) {
var html = '';
if (!text) { return text }
html = compile(text);
if (isPrimitive(text)) {
html = compile(text);
} else {
html = compile.parser(text);
}
html = config.noEmoji ? html : emojify(html);
slugify.clear();
@ -2974,7 +2971,42 @@ var Compiler = function Compiler (config, router) {
});
};
Compiler.prototype.matchNotCompileLink = function matchNotCompileLink (link) {
Compiler.prototype.compileEmbed = function compileEmbed (href, title) {
var ref = getAndRemoveConfig(title);
var str = ref.str;
var config = ref.config;
var embed;
title = str;
if (config.include) {
if (!isAbsolutePath(href)) {
href = getPath(this.contentBase, href);
}
var media;
if (config.type && (media = compileMedia[config.type])) {
embed = media.call(this, href, title);
embed.type = config.type;
} else {
var type = 'code';
if (/\.(md|markdown)/.test(href)) {
type = 'markdown';
} else if (/\.html?/.test(href)) {
type = 'iframe';
} else if (/\.(mp4|ogg)/.test(href)) {
type = 'video';
} else if (/\.mp3/.test(href)) {
type = 'audio';
}
embed = compileMedia[type].call(this, href, title);
embed.type = type;
}
return embed
}
};
Compiler.prototype._matchNotCompileLink = function _matchNotCompileLink (link) {
var links = this.config.noCompileLinks || [];
for (var i = 0; i < links.length; i++) {
@ -3026,6 +3058,7 @@ Compiler.prototype._initRenderer = function _initRenderer () {
origin.code = renderer.code = function (code, lang) {
if ( lang === void 0 ) lang = '';
code = code.replace(/@DOCSIFY_QM@/g, '`');
var hl = prism.highlight(
code,
prism.languages[lang] || prism.languages.markup
@ -3043,33 +3076,9 @@ Compiler.prototype._initRenderer = function _initRenderer () {
var config = ref.config;
title = str;
if (config.include) {
if (!isAbsolutePath(href)) {
href = getPath(contentBase, href);
}
var media;
if (config.type && (media = compileMedia[config.type])) {
return media.call(_self, href, title)
}
var type = 'code';
if (/\.(md|markdown)/.test(href)) {
type = 'markdown';
} else if (/\.html?/.test(href)) {
type = 'iframe';
} else if (/\.(mp4|ogg)/.test(href)) {
type = 'video';
} else if (/\.mp3/.test(href)) {
type = 'audio';
}
return compileMedia[type].call(_self, href, title)
}
if (
!/:|(\/{2})/.test(href) &&
!_self.matchNotCompileLink(href) &&
!_self._matchNotCompileLink(href) &&
!config.ignore
) {
if (href === _self.config.homepage) { href = 'README'; }
@ -3508,6 +3517,105 @@ function scroll2Top (offset) {
scrollEl.scrollTop = offset === true ? 0 : Number(offset);
}
var cached$1 = {};
function walkFetchEmbed (ref, cb) {
var step = ref.step; if ( step === void 0 ) step = 0;
var embedTokens = ref.embedTokens;
var compile = ref.compile;
var fetch = ref.fetch;
var token = embedTokens[step];
if (!token) {
return cb({})
}
var next = function (text) {
var embedToken;
if (text) {
if (token.embed.type === 'markdown') {
embedToken = compile.lexer(text);
} else if (token.embed.type === 'code') {
embedToken = compile.lexer(
'```' +
token.embed.lang +
'\n' +
text.replace(/`/g, '@DOCSIFY_QM@') +
'\n```\n'
);
}
}
cb({ token: token, embedToken: embedToken });
walkFetchEmbed({ step: ++step, compile: compile, embedTokens: embedTokens, fetch: fetch }, cb);
};
{
get(token.embed.url).then(next);
}
}
function prerenderEmbed (ref, done) {
var compiler = ref.compiler;
var raw = ref.raw;
var fetch = ref.fetch;
var hit;
if ((hit = cached$1[raw])) {
return done(hit)
}
var compile = compiler._marked;
var tokens = compile.lexer(raw);
var embedTokens = [];
var linkRE = compile.InlineLexer.rules.link;
var links = tokens.links;
tokens.forEach(function (token, index) {
if (token.type === 'paragraph') {
token.text = token.text.replace(
new RegExp(linkRE, 'g'),
function (src, filename, href, title) {
var embed = compiler.compileEmbed(href, title);
if (embed) {
if (embed.type === 'markdown' || embed.type === 'code') {
embedTokens.push({
index: index,
embed: embed
});
}
return embed.code
}
return src
}
);
}
});
var moveIndex = 0;
walkFetchEmbed({ compile: compile, embedTokens: embedTokens, fetch: fetch }, function (ref) {
var embedToken = ref.embedToken;
var token = ref.token;
if (token) {
var index = token.index + moveIndex;
merge(links, embedToken.links);
tokens = tokens
.slice(0, index)
.concat(embedToken, tokens.slice(index + 1));
moveIndex += embedToken.length - 1;
} else {
cached$1[raw] = tokens.concat();
tokens.links = cached$1[raw].links = links;
done(tokens);
}
});
}
function executeScript () {
var script = findAll('.markdown-section>script')
.filter(function (s) { return !/template/.test(s.type); })[0];
@ -3621,7 +3729,7 @@ function renderMixin (proto) {
getAndActive(this.router, 'nav');
};
proto._renderMain = function (text, opt) {
proto._renderMain = function (text, opt, next) {
var this$1 = this;
if ( opt === void 0 ) opt = {};
@ -3630,12 +3738,31 @@ function renderMixin (proto) {
}
callHook(this, 'beforeEach', text, function (result) {
var html = this$1.isHTML ? result : this$1.compiler.compile(result);
if (opt.updatedAt) {
html = formatUpdated(html, opt.updatedAt, this$1.config.formatUpdated);
}
var html;
var callback = function () {
if (opt.updatedAt) {
html = formatUpdated(html, opt.updatedAt, this$1.config.formatUpdated);
}
callHook(this$1, 'afterEach', html, function (text) { return renderMain.call(this$1, text); });
callHook(this$1, 'afterEach', html, function (text) { return renderMain.call(this$1, text); });
};
if (this$1.isHTML) {
html = this$1.result;
callback();
next();
} else {
prerenderEmbed(
{
compiler: this$1.compiler,
raw: text
},
function (tokens) {
html = this$1.compiler.compile(tokens);
callback();
next();
}
);
}
});
};
@ -3736,16 +3863,16 @@ function initRender (vm) {
toggleClass(body, 'ready');
}
var cached$1 = {};
var cached$2 = {};
function getAlias (path, alias, last) {
var match = Object.keys(alias).filter(function (key) {
var re = cached$1[key] || (cached$1[key] = new RegExp(("^" + key + "$")));
var re = cached$2[key] || (cached$2[key] = new RegExp(("^" + key + "$")));
return re.test(path) && path !== last
})[0];
return match
? getAlias(path.replace(cached$1[match], alias[match]), alias, path)
? getAlias(path.replace(cached$2[match], alias[match]), alias, path)
: path
}
@ -4074,12 +4201,10 @@ function fetchMixin (proto) {
// Load main content
last.then(
function (text, opt) {
this$1._renderMain(text, opt);
loadSideAndNav();
this$1._renderMain(text, opt, loadSideAndNav);
},
function (_) {
this$1._renderMain(null);
loadSideAndNav();
this$1._renderMain(null, {}, loadSideAndNav);
}
);
@ -4254,7 +4379,7 @@ initGlobalAPI();
/**
* Version
*/
Docsify.version = '4.6.0';
Docsify.version = '4.6.1';
/**
* Run Docsify

2
lib/docsify.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -37,5 +37,5 @@
"integrity": "sha1-6DWIAbhrg7F1YNTjw4LXrvIQCUQ="
}
},
"version": "4.6.0"
"version": "4.6.1"
}

View File

@ -1,6 +1,6 @@
{
"name": "docsify-server-renderer",
"version": "4.6.0",
"version": "4.6.1",
"description": "docsify server renderer",
"author": {
"name": "qingwei-li",