Skip to content

Commit a57ad20

Browse files
committed
update lib files
1 parent cf687c1 commit a57ad20

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

lib/docsify.js

Lines changed: 7 additions & 1 deletion
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(/"/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
}
@@ -4049,6 +4050,11 @@ function walkFetchEmbed(ref, cb) {
40494050
if (token.embed.type === 'markdown') {
40504051
embedToken = compile.lexer(text);
40514052
} else if (token.embed.type === 'code') {
4053+
if (token.embed.fragment) {
4054+
var fragment = token.embed.fragment;
4055+
var pattern = new RegExp(("(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]"));
4056+
text = ((text.match(pattern) || [])[1] || '').trim();
4057+
}
40524058
embedToken = compile.lexer(
40534059
'```' +
40544060
token.embed.lang +

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
'&': '&',
@@ -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)