Skip to content

Commit d1c7268

Browse files
committed
[build] 4.9.0
1 parent 8cd786c commit d1c7268

File tree

12 files changed

+74
-22
lines changed

12 files changed

+74
-22
lines changed

docs/_coverpage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![logo](_media/icon.svg)
22

3-
# docsify <small>4.8.6</small>
3+
# docsify <small>4.9.0</small>
44

55
> A magical documentation site generator.
66

lib/docsify.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3335,7 +3335,7 @@ function getAndRemoveConfig(str) {
33353335
str = str
33363336
.replace(/^'/, '')
33373337
.replace(/'$/, '')
3338-
.replace(/:([\w-]+)=?([\w-]+)?/g, function (m, key, value) {
3338+
.replace(/(?:^|\s):([\w-]+)=?([\w-]+)?/g, function (m, key, value) {
33393339
config[key] = (value && value.replace(/&quot;/g, '')) || true;
33403340
return ''
33413341
})
@@ -3483,6 +3483,7 @@ Compiler.prototype.compileEmbed = function compileEmbed (href, title) {
34833483
embed = compileMedia[type].call(this, href, title);
34843484
embed.type = type;
34853485
}
3486+
embed.fragment = config.fragment;
34863487

34873488
return embed
34883489
}
@@ -3633,6 +3634,23 @@ Compiler.prototype._initRenderer = function _initRenderer () {
36333634

36343635
return ("<img src=\"" + url + "\"data-origin=\"" + href + "\" alt=\"" + text + "\"" + attrs + ">")
36353636
};
3637+
origin.list = renderer.list = function (body, ordered, start) {
3638+
var isTaskList = /<li class="task-list-item">/.test(body.split('class="task-list"')[0]);
3639+
var isStartReq = start && start > 1;
3640+
var tag = ordered ? 'ol' : 'ul';
3641+
var tagAttrs = [
3642+
(isTaskList ? 'class="task-list"' : ''),
3643+
(isStartReq ? ("start=\"" + start + "\"") : '')
3644+
].join(' ').trim();
3645+
3646+
return ("<" + tag + " " + tagAttrs + ">" + body + "</" + tag + ">")
3647+
};
3648+
origin.listitem = renderer.listitem = function (text) {
3649+
var isTaskItem = /^(<input.*type="checkbox"[^>]*>)/.test(text);
3650+
var html = isTaskItem ? ("<li class=\"task-list-item\"><label>" + text + "</label></li>") : ("<li>" + text + "</li>");
3651+
3652+
return html
3653+
};
36363654

36373655
renderer.origin = origin;
36383656

@@ -3708,6 +3726,9 @@ function btn(el) {
37083726
var toggle = function (_) { return body.classList.toggle('close'); };
37093727

37103728
el = getNode(el);
3729+
if (el == null) {
3730+
return
3731+
}
37113732
on(el, 'click', function (e) {
37123733
e.stopPropagation();
37133734
toggle();
@@ -3723,7 +3744,9 @@ function btn(el) {
37233744

37243745
function collapse(el) {
37253746
el = getNode(el);
3726-
3747+
if (el == null) {
3748+
return
3749+
}
37273750
on(el, 'click', function (ref) {
37283751
var target = ref.target;
37293752

@@ -3761,8 +3784,10 @@ function sticky() {
37613784
*/
37623785
function getAndActive(router, el, isParent, autoTitle) {
37633786
el = getNode(el);
3764-
3765-
var links = findAll(el, 'a');
3787+
var links = [];
3788+
if (el != null) {
3789+
links = findAll(el, 'a');
3790+
}
37663791
var hash = decodeURI(router.toURL(router.getCurrentPath()));
37673792
var target;
37683793

@@ -3965,7 +3990,10 @@ function scrollActiveSidebar(router) {
39653990
coverHeight = cover ? cover.offsetHeight : 0;
39663991

39673992
var sidebar = getNode('.sidebar');
3968-
var lis = findAll(sidebar, 'li');
3993+
var lis = [];
3994+
if (sidebar != null) {
3995+
lis = findAll(sidebar, 'li');
3996+
}
39693997

39703998
for (var i = 0, len = lis.length; i < len; i += 1) {
39713999
var li = lis[i];
@@ -4049,6 +4077,11 @@ function walkFetchEmbed(ref, cb) {
40494077
if (token.embed.type === 'markdown') {
40504078
embedToken = compile.lexer(text);
40514079
} else if (token.embed.type === 'code') {
4080+
if (token.embed.fragment) {
4081+
var fragment = token.embed.fragment;
4082+
var pattern = new RegExp(("(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]"));
4083+
text = ((text.match(pattern) || [])[1] || '').trim();
4084+
}
40524085
embedToken = compile.lexer(
40534086
'```' +
40544087
token.embed.lang +
@@ -5013,7 +5046,7 @@ function initGlobalAPI () {
50135046
dom: dom,
50145047
get: get,
50155048
slugify: slugify,
5016-
version: '4.8.6'
5049+
version: '4.9.0'
50175050
};
50185051
window.DocsifyCompiler = Compiler;
50195052
window.marked = marked;

lib/docsify.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/plugins/search.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
(function () {
22
var INDEXS = {};
33

4+
var LOCAL_STORAGE = {
5+
EXPIRE_KEY: 'docsify.search.expires',
6+
INDEX_KEY: 'docsify.search.index'
7+
};
8+
9+
function resolveExpireKey(namespace) {
10+
return namespace ? ((LOCAL_STORAGE.EXPIRE_KEY) + "/" + namespace) : LOCAL_STORAGE.EXPIRE_KEY
11+
}
12+
function resolveIndexKey(namespace) {
13+
return namespace ? ((LOCAL_STORAGE.INDEX_KEY) + "/" + namespace) : LOCAL_STORAGE.INDEX_KEY
14+
}
15+
416
function escapeHtml(string) {
517
var entityMap = {
618
'&': '&amp;',
@@ -34,9 +46,9 @@ function getAllPaths(router) {
3446
return paths
3547
}
3648

37-
function saveData(maxAge) {
38-
localStorage.setItem('docsify.search.expires', Date.now() + maxAge);
39-
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS));
49+
function saveData(maxAge, expireKey, indexKey) {
50+
localStorage.setItem(expireKey, Date.now() + maxAge);
51+
localStorage.setItem(indexKey, JSON.stringify(INDEXS));
4052
}
4153

4254
function genIndex(path, content, router, depth) {
@@ -154,9 +166,13 @@ function search(query) {
154166

155167
function init$1(config, vm) {
156168
var isAuto = config.paths === 'auto';
157-
var isExpired = localStorage.getItem('docsify.search.expires') < Date.now();
158169

159-
INDEXS = JSON.parse(localStorage.getItem('docsify.search.index'));
170+
var expireKey = resolveExpireKey(config.namespace);
171+
var indexKey = resolveIndexKey(config.namespace);
172+
173+
var isExpired = localStorage.getItem(expireKey) < Date.now();
174+
175+
INDEXS = JSON.parse(localStorage.getItem(indexKey));
160176

161177
if (isExpired) {
162178
INDEXS = {};
@@ -177,7 +193,7 @@ function init$1(config, vm) {
177193
.get(vm.router.getFile(path), false, vm.config.requestHeaders)
178194
.then(function (result) {
179195
INDEXS[path] = genIndex(path, result, vm.router, config.depth);
180-
len === ++count && saveData(config.maxAge);
196+
len === ++count && saveData(config.maxAge, expireKey, indexKey);
181197
});
182198
});
183199
}
@@ -311,7 +327,8 @@ var CONFIG = {
311327
paths: 'auto',
312328
depth: 2,
313329
maxAge: 86400000, // 1 day
314-
hideOtherSidebarContent: false
330+
hideOtherSidebarContent: false,
331+
namespace: undefined
315332
};
316333

317334
var install = function (hook, vm) {
@@ -327,6 +344,7 @@ var install = function (hook, vm) {
327344
CONFIG.noData = opts.noData || CONFIG.noData;
328345
CONFIG.depth = opts.depth || CONFIG.depth;
329346
CONFIG.hideOtherSidebarContent = opts.hideOtherSidebarContent || CONFIG.hideOtherSidebarContent;
347+
CONFIG.namespace = opts.namespace || CONFIG.namespace;
330348
}
331349

332350
var isAuto = CONFIG.paths === 'auto';

lib/plugins/search.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)