docisy用的一些插件
This commit is contained in:
@@ -0,0 +1 @@
|
||||
var bszCaller,bszTag;!function(){var c,d,e,a=!1,b=[];ready=function(c){return a||"interactive"===document.readyState||"complete"===document.readyState?c.call(document):b.push(function(){return c.call(this)}),this},d=function(){for(var a=0,c=b.length;c>a;a++)b[a].apply(document);b=[]},e=function(){a||(a=!0,d.call(window),document.removeEventListener?document.removeEventListener("DOMContentLoaded",e,!1):document.attachEvent&&(document.detachEvent("onreadystatechange",e),window==window.top&&(clearInterval(c),c=null)))},document.addEventListener?document.addEventListener("DOMContentLoaded",e,!1):document.attachEvent&&(document.attachEvent("onreadystatechange",function(){/loaded|complete/.test(document.readyState)&&e()}),window==window.top&&(c=setInterval(function(){try{a||document.documentElement.doScroll("left")}catch(b){return}e()},5)))}(),bszCaller={fetch:function(a,b){var c="BusuanziCallback_"+Math.floor(1099511627776*Math.random());window[c]=this.evalCall(b),a=a.replace("=BusuanziCallback","="+c),scriptTag=document.createElement("SCRIPT"),scriptTag.type="text/javascript",scriptTag.defer=!0,scriptTag.src=a,document.getElementsByTagName("HEAD")[0].appendChild(scriptTag)},evalCall:function(a){return function(b){ready(function(){try{a(b),scriptTag.parentElement.removeChild(scriptTag)}catch(c){bszTag.hides()}})}}},bszCaller.fetch("//busuanzi.ibruce.info/busuanzi?jsonpCallback=BusuanziCallback",function(a){bszTag.texts(a),bszTag.shows()}),bszTag={bszs:["site_pv","page_pv","site_uv"],texts:function(a){this.bszs.map(function(b){var c=document.getElementById("busuanzi_value_"+b);c&&(c.innerHTML=a[b])})},hides:function(){this.bszs.map(function(a){var b=document.getElementById("busuanzi_container_"+a);b&&(b.style.display="none")})},shows:function(){this.bszs.map(function(a){var b=document.getElementById("busuanzi_container_"+a);b&&(b.style.display="inline")})}};
|
||||
@@ -0,0 +1,60 @@
|
||||
//default values
|
||||
var defaultOptions = {
|
||||
countable: true,
|
||||
position: "top",
|
||||
margin: "10px",
|
||||
float: "right",
|
||||
fontsize: "0.9em",
|
||||
color: "rgb(90,90,90)",
|
||||
language: "english",
|
||||
isExpected: true,
|
||||
}
|
||||
|
||||
// Docsify plugin functions
|
||||
function plugin(hook, vm) {
|
||||
if (!defaultOptions.countable) {
|
||||
return
|
||||
}
|
||||
let wordsCount
|
||||
hook.beforeEach(function (content) {
|
||||
// Match regex every time you start parsing .md
|
||||
wordsCount = content.match(/([\u4e00-\u9fa5]+?|[a-zA-Z0-9]+)/g).length
|
||||
return content
|
||||
})
|
||||
hook.afterEach(function (html, next) {
|
||||
let str = wordsCount + " words"
|
||||
let readTime = Math.ceil(wordsCount / 400) + " min"
|
||||
//Determine whether to use the Chinese style according to the attribute "language"
|
||||
if (defaultOptions.language === "chinese") {
|
||||
str = wordsCount + " 字"
|
||||
readTime = Math.ceil(wordsCount / 400) + " 分钟"
|
||||
}
|
||||
|
||||
//add html string
|
||||
next(
|
||||
`
|
||||
${defaultOptions.position === "bottom" ? html : ""}
|
||||
<div style="margin-${defaultOptions.position ? "bottom" : "top"}: ${
|
||||
defaultOptions.margin
|
||||
};">
|
||||
<span style="
|
||||
float: ${defaultOptions.float === "right" ? "right" : "left"};
|
||||
font-size: ${defaultOptions.fontsize};
|
||||
color:${defaultOptions.color};">
|
||||
${str}
|
||||
${defaultOptions.isExpected ? ` | ${readTime}` : ""}
|
||||
</span>
|
||||
<div style="clear: both"></div>
|
||||
</div>
|
||||
${defaultOptions.position !== "bottom" ? html : ""}
|
||||
`
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// Docsify plugin options
|
||||
window.$docsify["count"] = Object.assign(
|
||||
defaultOptions,
|
||||
window.$docsify["count"]
|
||||
)
|
||||
window.$docsify.plugins = [].concat(plugin, window.$docsify.plugins)
|
||||
@@ -0,0 +1,76 @@
|
||||
(function (Prism) {
|
||||
|
||||
// https://yaml.org/spec/1.2/spec.html#c-ns-anchor-property
|
||||
// https://yaml.org/spec/1.2/spec.html#c-ns-alias-node
|
||||
var anchorOrAlias = /[*&][^\s[\]{},]+/;
|
||||
// https://yaml.org/spec/1.2/spec.html#c-ns-tag-property
|
||||
var tag = /!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/;
|
||||
// https://yaml.org/spec/1.2/spec.html#c-ns-properties(n,c)
|
||||
var properties = '(?:' + tag.source + '(?:[ \t]+' + anchorOrAlias.source + ')?|'
|
||||
+ anchorOrAlias.source + '(?:[ \t]+' + tag.source + ')?)';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} value
|
||||
* @param {string} [flags]
|
||||
* @returns {RegExp}
|
||||
*/
|
||||
function createValuePattern(value, flags) {
|
||||
flags = (flags || '').replace(/m/g, '') + 'm'; // add m flag
|
||||
var pattern = /([:\-,[{]\s*(?:\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|]|}|\s*#))/.source
|
||||
.replace(/<<prop>>/g, function () { return properties; }).replace(/<<value>>/g, function () { return value; });
|
||||
return RegExp(pattern, flags)
|
||||
}
|
||||
|
||||
Prism.languages.yaml = {
|
||||
'scalar': {
|
||||
pattern: RegExp(/([\-:]\s*(?:\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)[^\r\n]+(?:\2[^\r\n]+)*)/.source
|
||||
.replace(/<<prop>>/g, function () { return properties; })),
|
||||
lookbehind: true,
|
||||
alias: 'string'
|
||||
},
|
||||
'comment': /#.*/,
|
||||
'key': {
|
||||
pattern: RegExp(/((?:^|[:\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)[^\r\n{[\]},#\s]+?(?=\s*:\s)/.source
|
||||
.replace(/<<prop>>/g, function () { return properties; })),
|
||||
lookbehind: true,
|
||||
alias: 'atrule'
|
||||
},
|
||||
'directive': {
|
||||
pattern: /(^[ \t]*)%.+/m,
|
||||
lookbehind: true,
|
||||
alias: 'important'
|
||||
},
|
||||
'datetime': {
|
||||
pattern: createValuePattern(/\d{4}-\d\d?-\d\d?(?:[tT]|[ \t]+)\d\d?:\d{2}:\d{2}(?:\.\d*)?[ \t]*(?:Z|[-+]\d\d?(?::\d{2})?)?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(?::\d{2}(?:\.\d*)?)?/.source),
|
||||
lookbehind: true,
|
||||
alias: 'number'
|
||||
},
|
||||
'boolean': {
|
||||
pattern: createValuePattern(/true|false/.source, 'i'),
|
||||
lookbehind: true,
|
||||
alias: 'important'
|
||||
},
|
||||
'null': {
|
||||
pattern: createValuePattern(/null|~/.source, 'i'),
|
||||
lookbehind: true,
|
||||
alias: 'important'
|
||||
},
|
||||
'string': {
|
||||
// \2 because of the lookbehind group
|
||||
pattern: createValuePattern(/("|')(?:(?!\2)[^\\\r\n]|\\.)*\2/.source),
|
||||
lookbehind: true,
|
||||
greedy: true
|
||||
},
|
||||
'number': {
|
||||
pattern: createValuePattern(/[+-]?(?:0x[\da-f]+|0o[0-7]+|(?:\d+\.?\d*|\.?\d+)(?:e[+-]?\d+)?|\.inf|\.nan)/.source, 'i'),
|
||||
lookbehind: true
|
||||
},
|
||||
'tag': tag,
|
||||
'important': anchorOrAlias,
|
||||
'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
|
||||
};
|
||||
|
||||
Prism.languages.yml = Prism.languages.yaml;
|
||||
|
||||
}(Prism));
|
||||
Reference in New Issue
Block a user