mirror of
https://github.com/docsifyjs/docsify.git
synced 2026-10-22 15:16:19 +08:00
WIP (this commit will be re-written): update use native Node ESM for server code, update config files to specifically use .cjs (those tools don't support Node ESM files yet), use a single eslintrc file, all test code uses ESM import/export syntax instead of require (WIP)
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ import { merge, hyphenate, isPrimitive, hasOwn } from './util/core';
|
||||
|
||||
const currentScript = document.currentScript;
|
||||
|
||||
export default function(vm) {
|
||||
export default function (vm) {
|
||||
const config = merge(
|
||||
{
|
||||
el: '#app',
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as sidebar from './sidebar';
|
||||
import { scrollIntoView, scroll2Top } from './scroll';
|
||||
|
||||
export function eventMixin(proto) {
|
||||
proto.$resetEvents = function(source) {
|
||||
proto.$resetEvents = function (source) {
|
||||
const { auto2top } = this.config;
|
||||
|
||||
(() => {
|
||||
|
||||
@@ -13,7 +13,7 @@ const cache = {};
|
||||
*/
|
||||
export function get(url, hasBar = false, headers = {}) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
const on = function() {
|
||||
const on = function () {
|
||||
xhr.addEventListener.apply(xhr, arguments);
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ export function get(url, hasBar = false, headers = {}) {
|
||||
xhr.send();
|
||||
|
||||
return {
|
||||
then: function(success, error = noop) {
|
||||
then: function (success, error = noop) {
|
||||
if (hasBar) {
|
||||
const id = setInterval(
|
||||
_ =>
|
||||
|
||||
@@ -60,7 +60,7 @@ export function fetchMixin(proto) {
|
||||
return path404;
|
||||
};
|
||||
|
||||
proto._loadSideAndNav = function(path, qs, loadSidebar, cb) {
|
||||
proto._loadSideAndNav = function (path, qs, loadSidebar, cb) {
|
||||
return () => {
|
||||
if (!loadSidebar) {
|
||||
return cb();
|
||||
@@ -76,7 +76,7 @@ export function fetchMixin(proto) {
|
||||
};
|
||||
};
|
||||
|
||||
proto._fetch = function(cb = noop) {
|
||||
proto._fetch = function (cb = noop) {
|
||||
const { path, query } = this.route;
|
||||
const qs = stringifyQuery(query, ['id']);
|
||||
const { loadNavbar, requestHeaders, loadSidebar } = this.config;
|
||||
@@ -114,7 +114,7 @@ export function fetchMixin(proto) {
|
||||
);
|
||||
};
|
||||
|
||||
proto._fetchCover = function() {
|
||||
proto._fetchCover = function () {
|
||||
const { coverpage, requestHeaders } = this.config;
|
||||
const query = this.route.query;
|
||||
const root = getParentPath(this.route.path);
|
||||
@@ -150,7 +150,7 @@ export function fetchMixin(proto) {
|
||||
}
|
||||
};
|
||||
|
||||
proto.$fetch = function(
|
||||
proto.$fetch = function (
|
||||
cb = noop,
|
||||
$resetEvents = this.$resetEvents.bind(this)
|
||||
) {
|
||||
@@ -171,7 +171,7 @@ export function fetchMixin(proto) {
|
||||
}
|
||||
};
|
||||
|
||||
proto._fetchFallbackPage = function(path, qs, cb = noop) {
|
||||
proto._fetchFallbackPage = function (path, qs, cb = noop) {
|
||||
const { requestHeaders, fallbackLanguages, loadSidebar } = this.config;
|
||||
|
||||
if (!fallbackLanguages) {
|
||||
@@ -210,7 +210,7 @@ export function fetchMixin(proto) {
|
||||
* @returns {Boolean} True if the requested page is not found
|
||||
* @private
|
||||
*/
|
||||
proto._fetch404 = function(path, qs, cb = noop) {
|
||||
proto._fetch404 = function (path, qs, cb = noop) {
|
||||
const { loadSidebar, requestHeaders, notFoundPage } = this.config;
|
||||
|
||||
const fnLoadSideAndNav = this._loadSideAndNav(path, qs, loadSidebar, cb);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { get } from './fetch/ajax';
|
||||
// major release. We'll tell people to get everything from the DOCSIFY global
|
||||
// when using the global build, but we'll highly recommend for them to import
|
||||
// from the ESM build (f.e. lib/docsify.esm.js and lib/docsify.min.esm.js).
|
||||
export default function() {
|
||||
export default function () {
|
||||
window.Docsify = {
|
||||
util,
|
||||
dom,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { isFn } from '../util/core';
|
||||
import { initLifecycle, callHook } from './lifecycle';
|
||||
|
||||
export function initMixin(proto) {
|
||||
proto._init = function() {
|
||||
proto._init = function () {
|
||||
const vm = this;
|
||||
vm.config = config(vm);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export function initLifecycle(vm) {
|
||||
export function callHook(vm, hookName, data, next = noop) {
|
||||
const queue = vm._hooks[hookName];
|
||||
|
||||
const step = function(index) {
|
||||
const step = function (index) {
|
||||
const hookFn = queue[index];
|
||||
|
||||
if (index >= queue.length) {
|
||||
|
||||
@@ -28,8 +28,9 @@ const compileMedia = {
|
||||
},
|
||||
iframe(url, title) {
|
||||
return {
|
||||
html: `<iframe src="${url}" ${title ||
|
||||
'width=100% height=400'}></iframe>`,
|
||||
html: `<iframe src="${url}" ${
|
||||
title || 'width=100% height=400'
|
||||
}></iframe>`,
|
||||
};
|
||||
},
|
||||
video(url, title) {
|
||||
@@ -205,7 +206,7 @@ export class Compiler {
|
||||
* @param {Number} level Type of heading (h<level> tag)
|
||||
* @returns {String} Heading element
|
||||
*/
|
||||
origin.heading = renderer.heading = function(text, level) {
|
||||
origin.heading = renderer.heading = function (text, level) {
|
||||
let { str, config } = getAndRemoveConfig(text);
|
||||
const nextToc = { level, title: removeAtag(str) };
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import Prism from 'prismjs';
|
||||
import 'prismjs/components/prism-markup-templating';
|
||||
|
||||
export const highlightCodeCompiler = ({ renderer }) =>
|
||||
(renderer.code = function(code, lang = 'markup') {
|
||||
(renderer.code = function (code, lang = 'markup') {
|
||||
const langOrMarkup = Prism.languages[lang] || Prism.languages.markup;
|
||||
const text = Prism.highlight(
|
||||
code.replace(/@DOCSIFY_QM@/g, '`'),
|
||||
|
||||
@@ -15,7 +15,7 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) {
|
||||
|
||||
while ((token = embedTokens[step++])) {
|
||||
// eslint-disable-next-line no-shadow
|
||||
const next = (function(token) {
|
||||
const next = (function (token) {
|
||||
return text => {
|
||||
let embedToken;
|
||||
if (text) {
|
||||
|
||||
@@ -90,7 +90,7 @@ function renderMain(html) {
|
||||
|
||||
if (!isAlreadyVue) {
|
||||
new window.Vue({
|
||||
mounted: function() {
|
||||
mounted: function () {
|
||||
this.$destroy();
|
||||
},
|
||||
}).$mount(elm);
|
||||
@@ -121,14 +121,14 @@ function renderNameLink(vm) {
|
||||
}
|
||||
|
||||
export function renderMixin(proto) {
|
||||
proto._renderTo = function(el, content, replace) {
|
||||
proto._renderTo = function (el, content, replace) {
|
||||
const node = dom.getNode(el);
|
||||
if (node) {
|
||||
node[replace ? 'outerHTML' : 'innerHTML'] = content;
|
||||
}
|
||||
};
|
||||
|
||||
proto._renderSidebar = function(text) {
|
||||
proto._renderSidebar = function (text) {
|
||||
const { maxLevel, subMaxLevel, loadSidebar, hideSidebar } = this.config;
|
||||
|
||||
if (hideSidebar) {
|
||||
@@ -156,7 +156,7 @@ export function renderMixin(proto) {
|
||||
this._bindEventOnRendered(activeEl);
|
||||
};
|
||||
|
||||
proto._bindEventOnRendered = function(activeEl) {
|
||||
proto._bindEventOnRendered = function (activeEl) {
|
||||
const { autoHeader } = this.config;
|
||||
|
||||
scrollActiveSidebar(this.router);
|
||||
@@ -172,14 +172,14 @@ export function renderMixin(proto) {
|
||||
}
|
||||
};
|
||||
|
||||
proto._renderNav = function(text) {
|
||||
proto._renderNav = function (text) {
|
||||
text && this._renderTo('nav', this.compiler.compile(text));
|
||||
if (this.config.loadNavbar) {
|
||||
getAndActive(this.router, 'nav');
|
||||
}
|
||||
};
|
||||
|
||||
proto._renderMain = function(text, opt = {}, next) {
|
||||
proto._renderMain = function (text, opt = {}, next) {
|
||||
if (!text) {
|
||||
return renderMain.call(this, text);
|
||||
}
|
||||
@@ -217,7 +217,7 @@ export function renderMixin(proto) {
|
||||
});
|
||||
};
|
||||
|
||||
proto._renderCover = function(text, coverOnly) {
|
||||
proto._renderCover = function (text, coverOnly) {
|
||||
const el = dom.getNode('.cover');
|
||||
|
||||
dom.toggleClass(
|
||||
@@ -261,7 +261,7 @@ export function renderMixin(proto) {
|
||||
sticky();
|
||||
};
|
||||
|
||||
proto._updateRender = function() {
|
||||
proto._updateRender = function () {
|
||||
// Render name link
|
||||
renderNameLink(this);
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ function init() {
|
||||
/**
|
||||
* Render progress bar
|
||||
*/
|
||||
export default function({ loaded, total, step }) {
|
||||
export default function ({ loaded, total, step }) {
|
||||
let num;
|
||||
|
||||
!barEl && init();
|
||||
|
||||
@@ -32,6 +32,6 @@ export function slugify(str) {
|
||||
return slug;
|
||||
}
|
||||
|
||||
slugify.clear = function() {
|
||||
slugify.clear = function () {
|
||||
cache = {};
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ export function parseQuery(query) {
|
||||
}
|
||||
|
||||
// Simple parse
|
||||
query.split('&').forEach(function(param) {
|
||||
query.split('&').forEach(function (param) {
|
||||
const parts = param.replace(/\+/g, ' ').split('=');
|
||||
|
||||
res[parts[0]] = parts[1] && decode(parts[1]);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
export function cached(fn) {
|
||||
const cache = Object.create(null);
|
||||
return function(str) {
|
||||
return function (str) {
|
||||
const key = isPrimitive(str) ? str : JSON.stringify(str);
|
||||
const hit = cache[key];
|
||||
return hit || (cache[key] = fn(str));
|
||||
@@ -29,7 +29,7 @@ export const hasOwn = Object.prototype.hasOwnProperty;
|
||||
*/
|
||||
export const merge =
|
||||
Object.assign ||
|
||||
function(to) {
|
||||
function (to) {
|
||||
for (let i = 1; i < arguments.length; i++) {
|
||||
const from = Object(arguments[i]);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ export const isMobile = inBrowser && document.body.clientWidth <= 600;
|
||||
*/
|
||||
export const supportsPushState =
|
||||
inBrowser &&
|
||||
(function() {
|
||||
(function () {
|
||||
// Borrowed wholesale from https://github.com/defunkt/jquery-pjax
|
||||
return (
|
||||
window.history &&
|
||||
|
||||
@@ -8,7 +8,7 @@ function replaceVar(block, color) {
|
||||
);
|
||||
}
|
||||
|
||||
export default function(color) {
|
||||
export default function (color) {
|
||||
// Variable support
|
||||
if (window.CSS && window.CSS.supports && window.CSS.supports('(--v:red)')) {
|
||||
return;
|
||||
|
||||
@@ -28,7 +28,7 @@ function install(hook, vm) {
|
||||
dom.appendTo(dom.find('.content'), div);
|
||||
|
||||
// eslint-disable-next-line
|
||||
window.disqus_config = function() {
|
||||
window.disqus_config = function () {
|
||||
this.page.url = location.origin + '/-' + vm.route.path;
|
||||
this.page.identifier = vm.route.path;
|
||||
this.page.title = document.title;
|
||||
@@ -39,7 +39,7 @@ function install(hook, vm) {
|
||||
if (typeof window.DISQUS !== 'undefined') {
|
||||
window.DISQUS.reset({
|
||||
reload: true,
|
||||
config: function() {
|
||||
config: function () {
|
||||
this.page.url = location.origin + '/-' + vm.route.path;
|
||||
this.page.identifier = vm.route.path;
|
||||
this.page.title = document.title;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable camelcase */
|
||||
const AllGithubEmoji = {
|
||||
'100': 'unicode/1f4af',
|
||||
'1234': 'unicode/1f522',
|
||||
100: 'unicode/1f4af',
|
||||
1234: 'unicode/1f522',
|
||||
'+1': 'unicode/1f44d',
|
||||
'-1': 'unicode/1f44e',
|
||||
'1st_place_medal': 'unicode/1f947',
|
||||
@@ -1804,7 +1804,7 @@ const AllGithubEmoji = {
|
||||
|
||||
// Emoji from GitHub API
|
||||
// https://api.github.com/emojis
|
||||
window.emojify = function(match, $1) {
|
||||
window.emojify = function (match, $1) {
|
||||
return AllGithubEmoji.hasOwnProperty($1) === false
|
||||
? match
|
||||
: '<img class="emoji" src="https://github.githubassets.com/images/icons/emoji/' +
|
||||
|
||||
@@ -18,7 +18,7 @@ function handleExternalScript() {
|
||||
}
|
||||
}
|
||||
|
||||
const install = function(hook) {
|
||||
const install = function (hook) {
|
||||
hook.doneEach(handleExternalScript);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import parser from './parser';
|
||||
|
||||
const install = function(hook, vm) {
|
||||
const install = function (hook, vm) {
|
||||
// Used to remove front matter from embedded pages if installed.
|
||||
vm.config.frontMatter = {};
|
||||
vm.config.frontMatter.installed = true;
|
||||
vm.config.frontMatter.parseMarkdown = function(content) {
|
||||
vm.config.frontMatter.parseMarkdown = function (content) {
|
||||
const { body } = parser(content);
|
||||
return body;
|
||||
};
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* Fork https://github.com/egoist/docute/blob/master/src/utils/front-matter.js
|
||||
*/
|
||||
/* eslint-disable */
|
||||
import parser from './yaml'
|
||||
import parser from './yaml';
|
||||
|
||||
var optionalByteOrderMark = '\\ufeff?'
|
||||
var optionalByteOrderMark = '\\ufeff?';
|
||||
var pattern =
|
||||
'^(' +
|
||||
optionalByteOrderMark +
|
||||
@@ -13,43 +13,43 @@ var pattern =
|
||||
'(?:\\2|\\.\\.\\.)' +
|
||||
'$' +
|
||||
'' +
|
||||
'(?:\\n)?)'
|
||||
'(?:\\n)?)';
|
||||
// NOTE: If this pattern uses the 'g' flag the `regex` variable definition will
|
||||
// need to be moved down into the functions that use it.
|
||||
var regex = new RegExp(pattern, 'm')
|
||||
var regex = new RegExp(pattern, 'm');
|
||||
|
||||
function extractor(string) {
|
||||
string = string || ''
|
||||
string = string || '';
|
||||
|
||||
var lines = string.split(/(\r?\n)/)
|
||||
var lines = string.split(/(\r?\n)/);
|
||||
if (lines[0] && /= yaml =|---/.test(lines[0])) {
|
||||
return parse(string)
|
||||
return parse(string);
|
||||
} else {
|
||||
return { attributes: {}, body: string }
|
||||
return { attributes: {}, body: string };
|
||||
}
|
||||
}
|
||||
|
||||
function parse(string) {
|
||||
var match = regex.exec(string)
|
||||
var match = regex.exec(string);
|
||||
|
||||
if (!match) {
|
||||
return {
|
||||
attributes: {},
|
||||
body: string
|
||||
}
|
||||
body: string,
|
||||
};
|
||||
}
|
||||
|
||||
var yaml = match[match.length - 1].replace(/^\s+|\s+$/g, '')
|
||||
var attributes = parser(yaml) || {}
|
||||
var body = string.replace(match[0], '')
|
||||
var yaml = match[match.length - 1].replace(/^\s+|\s+$/g, '');
|
||||
var attributes = parser(yaml) || {};
|
||||
var body = string.replace(match[0], '');
|
||||
|
||||
return { attributes: attributes, body: body, frontmatter: yaml }
|
||||
return { attributes: attributes, body: body, frontmatter: yaml };
|
||||
}
|
||||
|
||||
function test(string) {
|
||||
string = string || ''
|
||||
string = string || '';
|
||||
|
||||
return regex.test(string)
|
||||
return regex.test(string);
|
||||
}
|
||||
|
||||
export default extractor
|
||||
export default extractor;
|
||||
|
||||
+199
-197
@@ -27,7 +27,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
/**
|
||||
* @name YAML
|
||||
* @namespace
|
||||
*/
|
||||
*/
|
||||
|
||||
var errors = [],
|
||||
reference_blocks = [],
|
||||
@@ -46,14 +46,16 @@ var errors = [],
|
||||
key: new RegExp('([a-z0-9_-][ a-z0-9_-]+):( .+)?', 'i'),
|
||||
item: new RegExp('^-\\s+'),
|
||||
trim: new RegExp('^\\s+|\\s+$'),
|
||||
comment: new RegExp('([^\\\'\\"#]+([\\\'\\"][^\\\'\\"]*[\\\'\\"])*)*(#.*)?')
|
||||
}
|
||||
comment: new RegExp(
|
||||
'([^\\\'\\"#]+([\\\'\\"][^\\\'\\"]*[\\\'\\"])*)*(#.*)?'
|
||||
),
|
||||
};
|
||||
|
||||
/**
|
||||
* @class A block of lines of a given level.
|
||||
* @param {int} lvl The block's level.
|
||||
* @private
|
||||
*/
|
||||
* @class A block of lines of a given level.
|
||||
* @param {int} lvl The block's level.
|
||||
* @private
|
||||
*/
|
||||
function Block(lvl) {
|
||||
return {
|
||||
/* The block's parent */
|
||||
@@ -67,21 +69,21 @@ function Block(lvl) {
|
||||
/* Blocks with greater level */
|
||||
children: [],
|
||||
/* Add a block to the children collection */
|
||||
addChild: function(obj) {
|
||||
this.children.push(obj)
|
||||
obj.parent = this
|
||||
++this.length
|
||||
}
|
||||
}
|
||||
addChild: function (obj) {
|
||||
this.children.push(obj);
|
||||
obj.parent = this;
|
||||
++this.length;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// function to create an XMLHttpClient in a cross-browser manner
|
||||
function createXMLHTTPRequest() {
|
||||
var xmlhttp
|
||||
var xmlhttp;
|
||||
|
||||
try {
|
||||
// Mozilla / Safari / IE7
|
||||
xmlhttp = new XMLHttpRequest()
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
} catch (e) {
|
||||
// IE
|
||||
var XMLHTTP_IDS = new Array(
|
||||
@@ -90,347 +92,347 @@ function createXMLHTTPRequest() {
|
||||
'MSXML2.XMLHTTP.3.0',
|
||||
'MSXML2.XMLHTTP',
|
||||
'Microsoft.XMLHTTP'
|
||||
)
|
||||
var success = false
|
||||
);
|
||||
var success = false;
|
||||
for (var i = 0; i < XMLHTTP_IDS.length && !success; i++) {
|
||||
try {
|
||||
xmlhttp = new ActiveXObject(XMLHTTP_IDS[i])
|
||||
success = true
|
||||
xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
|
||||
success = true;
|
||||
} catch (e) {}
|
||||
}
|
||||
if (!success) {
|
||||
throw new Error('Unable to create XMLHttpRequest.')
|
||||
throw new Error('Unable to create XMLHttpRequest.');
|
||||
}
|
||||
}
|
||||
|
||||
return xmlhttp
|
||||
return xmlhttp;
|
||||
}
|
||||
|
||||
function parser(str) {
|
||||
var regLevel = regex['regLevel']
|
||||
var invalidLine = regex['invalidLine']
|
||||
var lines = str.split('\n')
|
||||
var m
|
||||
var regLevel = regex['regLevel'];
|
||||
var invalidLine = regex['invalidLine'];
|
||||
var lines = str.split('\n');
|
||||
var m;
|
||||
var level = 0,
|
||||
curLevel = 0
|
||||
curLevel = 0;
|
||||
|
||||
var blocks = []
|
||||
var blocks = [];
|
||||
|
||||
var result = new Block(-1)
|
||||
var currentBlock = new Block(0)
|
||||
result.addChild(currentBlock)
|
||||
var levels = []
|
||||
var line = ''
|
||||
var result = new Block(-1);
|
||||
var currentBlock = new Block(0);
|
||||
result.addChild(currentBlock);
|
||||
var levels = [];
|
||||
var line = '';
|
||||
|
||||
blocks.push(currentBlock)
|
||||
levels.push(level)
|
||||
blocks.push(currentBlock);
|
||||
levels.push(level);
|
||||
|
||||
for (var i = 0, len = lines.length; i < len; ++i) {
|
||||
line = lines[i]
|
||||
line = lines[i];
|
||||
|
||||
if (line.match(invalidLine)) {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((m = regLevel.exec(line))) {
|
||||
level = m[1].length
|
||||
} else level = 0
|
||||
level = m[1].length;
|
||||
} else level = 0;
|
||||
|
||||
if (level > curLevel) {
|
||||
var oldBlock = currentBlock
|
||||
currentBlock = new Block(level)
|
||||
oldBlock.addChild(currentBlock)
|
||||
blocks.push(currentBlock)
|
||||
levels.push(level)
|
||||
var oldBlock = currentBlock;
|
||||
currentBlock = new Block(level);
|
||||
oldBlock.addChild(currentBlock);
|
||||
blocks.push(currentBlock);
|
||||
levels.push(level);
|
||||
} else if (level < curLevel) {
|
||||
var added = false
|
||||
var added = false;
|
||||
|
||||
var k = levels.length - 1
|
||||
var k = levels.length - 1;
|
||||
for (; k >= 0; --k) {
|
||||
if (levels[k] == level) {
|
||||
currentBlock = new Block(level)
|
||||
blocks.push(currentBlock)
|
||||
levels.push(level)
|
||||
if (blocks[k].parent != null) blocks[k].parent.addChild(currentBlock)
|
||||
added = true
|
||||
break
|
||||
currentBlock = new Block(level);
|
||||
blocks.push(currentBlock);
|
||||
levels.push(level);
|
||||
if (blocks[k].parent != null) blocks[k].parent.addChild(currentBlock);
|
||||
added = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added) {
|
||||
errors.push('Error: Invalid indentation at line ' + i + ': ' + line)
|
||||
return
|
||||
errors.push('Error: Invalid indentation at line ' + i + ': ' + line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
currentBlock.lines.push(line.replace(regex['trim'], ''))
|
||||
curLevel = level
|
||||
currentBlock.lines.push(line.replace(regex['trim'], ''));
|
||||
curLevel = level;
|
||||
}
|
||||
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
|
||||
function processValue(val) {
|
||||
val = val.replace(regex['trim'], '')
|
||||
var m = null
|
||||
val = val.replace(regex['trim'], '');
|
||||
var m = null;
|
||||
|
||||
if (val == 'true') {
|
||||
return true
|
||||
return true;
|
||||
} else if (val == 'false') {
|
||||
return false
|
||||
return false;
|
||||
} else if (val == '.NaN') {
|
||||
return Number.NaN
|
||||
return Number.NaN;
|
||||
} else if (val == 'null') {
|
||||
return null
|
||||
return null;
|
||||
} else if (val == '.inf') {
|
||||
return Number.POSITIVE_INFINITY
|
||||
return Number.POSITIVE_INFINITY;
|
||||
} else if (val == '-.inf') {
|
||||
return Number.NEGATIVE_INFINITY
|
||||
return Number.NEGATIVE_INFINITY;
|
||||
} else if ((m = val.match(regex['dashesString']))) {
|
||||
return m[1]
|
||||
return m[1];
|
||||
} else if ((m = val.match(regex['quotesString']))) {
|
||||
return m[1]
|
||||
return m[1];
|
||||
} else if ((m = val.match(regex['float']))) {
|
||||
return parseFloat(m[0])
|
||||
return parseFloat(m[0]);
|
||||
} else if ((m = val.match(regex['integer']))) {
|
||||
return parseInt(m[0])
|
||||
return parseInt(m[0]);
|
||||
} else if (!isNaN((m = Date.parse(val)))) {
|
||||
return new Date(m)
|
||||
return new Date(m);
|
||||
} else if ((m = val.match(regex['single_key_value']))) {
|
||||
var res = {}
|
||||
res[m[1]] = processValue(m[2])
|
||||
return res
|
||||
var res = {};
|
||||
res[m[1]] = processValue(m[2]);
|
||||
return res;
|
||||
} else if ((m = val.match(regex['array']))) {
|
||||
var count = 0,
|
||||
c = ' '
|
||||
var res = []
|
||||
var content = ''
|
||||
var str = false
|
||||
c = ' ';
|
||||
var res = [];
|
||||
var content = '';
|
||||
var str = false;
|
||||
for (var j = 0, lenJ = m[1].length; j < lenJ; ++j) {
|
||||
c = m[1][j]
|
||||
c = m[1][j];
|
||||
if (c == "'" || c == '"') {
|
||||
if (str === false) {
|
||||
str = c
|
||||
content += c
|
||||
continue
|
||||
str = c;
|
||||
content += c;
|
||||
continue;
|
||||
} else if ((c == "'" && str == "'") || (c == '"' && str == '"')) {
|
||||
str = false
|
||||
content += c
|
||||
continue
|
||||
str = false;
|
||||
content += c;
|
||||
continue;
|
||||
}
|
||||
} else if (str === false && (c == '[' || c == '{')) {
|
||||
++count
|
||||
++count;
|
||||
} else if (str === false && (c == ']' || c == '}')) {
|
||||
--count
|
||||
--count;
|
||||
} else if (str === false && count == 0 && c == ',') {
|
||||
res.push(processValue(content))
|
||||
content = ''
|
||||
continue
|
||||
res.push(processValue(content));
|
||||
content = '';
|
||||
continue;
|
||||
}
|
||||
|
||||
content += c
|
||||
content += c;
|
||||
}
|
||||
|
||||
if (content.length > 0) res.push(processValue(content))
|
||||
return res
|
||||
if (content.length > 0) res.push(processValue(content));
|
||||
return res;
|
||||
} else if ((m = val.match(regex['map']))) {
|
||||
var count = 0,
|
||||
c = ' '
|
||||
var res = []
|
||||
var content = ''
|
||||
var str = false
|
||||
c = ' ';
|
||||
var res = [];
|
||||
var content = '';
|
||||
var str = false;
|
||||
for (var j = 0, lenJ = m[1].length; j < lenJ; ++j) {
|
||||
c = m[1][j]
|
||||
c = m[1][j];
|
||||
if (c == "'" || c == '"') {
|
||||
if (str === false) {
|
||||
str = c
|
||||
content += c
|
||||
continue
|
||||
str = c;
|
||||
content += c;
|
||||
continue;
|
||||
} else if ((c == "'" && str == "'") || (c == '"' && str == '"')) {
|
||||
str = false
|
||||
content += c
|
||||
continue
|
||||
str = false;
|
||||
content += c;
|
||||
continue;
|
||||
}
|
||||
} else if (str === false && (c == '[' || c == '{')) {
|
||||
++count
|
||||
++count;
|
||||
} else if (str === false && (c == ']' || c == '}')) {
|
||||
--count
|
||||
--count;
|
||||
} else if (str === false && count == 0 && c == ',') {
|
||||
res.push(content)
|
||||
content = ''
|
||||
continue
|
||||
res.push(content);
|
||||
content = '';
|
||||
continue;
|
||||
}
|
||||
|
||||
content += c
|
||||
content += c;
|
||||
}
|
||||
|
||||
if (content.length > 0) res.push(content)
|
||||
if (content.length > 0) res.push(content);
|
||||
|
||||
var newRes = {}
|
||||
var newRes = {};
|
||||
for (var j = 0, lenJ = res.length; j < lenJ; ++j) {
|
||||
if ((m = res[j].match(regex['key_value']))) {
|
||||
newRes[m[1]] = processValue(m[2])
|
||||
newRes[m[1]] = processValue(m[2]);
|
||||
}
|
||||
}
|
||||
|
||||
return newRes
|
||||
} else return val
|
||||
return newRes;
|
||||
} else return val;
|
||||
}
|
||||
|
||||
function processFoldedBlock(block) {
|
||||
var lines = block.lines
|
||||
var children = block.children
|
||||
var str = lines.join(' ')
|
||||
var chunks = [str]
|
||||
var lines = block.lines;
|
||||
var children = block.children;
|
||||
var str = lines.join(' ');
|
||||
var chunks = [str];
|
||||
for (var i = 0, len = children.length; i < len; ++i) {
|
||||
chunks.push(processFoldedBlock(children[i]))
|
||||
chunks.push(processFoldedBlock(children[i]));
|
||||
}
|
||||
return chunks.join('\n')
|
||||
return chunks.join('\n');
|
||||
}
|
||||
|
||||
function processLiteralBlock(block) {
|
||||
var lines = block.lines
|
||||
var children = block.children
|
||||
var str = lines.join('\n')
|
||||
var lines = block.lines;
|
||||
var children = block.children;
|
||||
var str = lines.join('\n');
|
||||
for (var i = 0, len = children.length; i < len; ++i) {
|
||||
str += processLiteralBlock(children[i])
|
||||
str += processLiteralBlock(children[i]);
|
||||
}
|
||||
return str
|
||||
return str;
|
||||
}
|
||||
|
||||
function processBlock(blocks) {
|
||||
var m = null
|
||||
var res = {}
|
||||
var lines = null
|
||||
var children = null
|
||||
var currentObj = null
|
||||
var m = null;
|
||||
var res = {};
|
||||
var lines = null;
|
||||
var children = null;
|
||||
var currentObj = null;
|
||||
|
||||
var level = -1
|
||||
var level = -1;
|
||||
|
||||
var processedBlocks = []
|
||||
var processedBlocks = [];
|
||||
|
||||
var isMap = true
|
||||
var isMap = true;
|
||||
|
||||
for (var j = 0, lenJ = blocks.length; j < lenJ; ++j) {
|
||||
if (level != -1 && level != blocks[j].level) continue
|
||||
if (level != -1 && level != blocks[j].level) continue;
|
||||
|
||||
processedBlocks.push(j)
|
||||
processedBlocks.push(j);
|
||||
|
||||
level = blocks[j].level
|
||||
lines = blocks[j].lines
|
||||
children = blocks[j].children
|
||||
currentObj = null
|
||||
level = blocks[j].level;
|
||||
lines = blocks[j].lines;
|
||||
children = blocks[j].children;
|
||||
currentObj = null;
|
||||
|
||||
for (var i = 0, len = lines.length; i < len; ++i) {
|
||||
var line = lines[i]
|
||||
var line = lines[i];
|
||||
|
||||
if ((m = line.match(regex['key']))) {
|
||||
var key = m[1]
|
||||
var key = m[1];
|
||||
|
||||
if (key[0] == '-') {
|
||||
key = key.replace(regex['item'], '')
|
||||
key = key.replace(regex['item'], '');
|
||||
if (isMap) {
|
||||
isMap = false
|
||||
isMap = false;
|
||||
if (typeof res.length === 'undefined') {
|
||||
res = []
|
||||
res = [];
|
||||
}
|
||||
}
|
||||
if (currentObj != null) res.push(currentObj)
|
||||
currentObj = {}
|
||||
isMap = true
|
||||
if (currentObj != null) res.push(currentObj);
|
||||
currentObj = {};
|
||||
isMap = true;
|
||||
}
|
||||
|
||||
if (typeof m[2] != 'undefined') {
|
||||
var value = m[2].replace(regex['trim'], '')
|
||||
var value = m[2].replace(regex['trim'], '');
|
||||
if (value[0] == '&') {
|
||||
var nb = processBlock(children)
|
||||
if (currentObj != null) currentObj[key] = nb
|
||||
else res[key] = nb
|
||||
reference_blocks[value.substr(1)] = nb
|
||||
var nb = processBlock(children);
|
||||
if (currentObj != null) currentObj[key] = nb;
|
||||
else res[key] = nb;
|
||||
reference_blocks[value.substr(1)] = nb;
|
||||
} else if (value[0] == '|') {
|
||||
if (currentObj != null)
|
||||
currentObj[key] = processLiteralBlock(children.shift())
|
||||
else res[key] = processLiteralBlock(children.shift())
|
||||
currentObj[key] = processLiteralBlock(children.shift());
|
||||
else res[key] = processLiteralBlock(children.shift());
|
||||
} else if (value[0] == '*') {
|
||||
var v = value.substr(1)
|
||||
var no = {}
|
||||
var v = value.substr(1);
|
||||
var no = {};
|
||||
|
||||
if (typeof reference_blocks[v] == 'undefined') {
|
||||
errors.push("Reference '" + v + "' not found!")
|
||||
errors.push("Reference '" + v + "' not found!");
|
||||
} else {
|
||||
for (var k in reference_blocks[v]) {
|
||||
no[k] = reference_blocks[v][k]
|
||||
no[k] = reference_blocks[v][k];
|
||||
}
|
||||
|
||||
if (currentObj != null) currentObj[key] = no
|
||||
else res[key] = no
|
||||
if (currentObj != null) currentObj[key] = no;
|
||||
else res[key] = no;
|
||||
}
|
||||
} else if (value[0] == '>') {
|
||||
if (currentObj != null)
|
||||
currentObj[key] = processFoldedBlock(children.shift())
|
||||
else res[key] = processFoldedBlock(children.shift())
|
||||
currentObj[key] = processFoldedBlock(children.shift());
|
||||
else res[key] = processFoldedBlock(children.shift());
|
||||
} else {
|
||||
if (currentObj != null) currentObj[key] = processValue(value)
|
||||
else res[key] = processValue(value)
|
||||
if (currentObj != null) currentObj[key] = processValue(value);
|
||||
else res[key] = processValue(value);
|
||||
}
|
||||
} else {
|
||||
if (currentObj != null) currentObj[key] = processBlock(children)
|
||||
else res[key] = processBlock(children)
|
||||
if (currentObj != null) currentObj[key] = processBlock(children);
|
||||
else res[key] = processBlock(children);
|
||||
}
|
||||
} else if (line.match(/^-\s*$/)) {
|
||||
if (isMap) {
|
||||
isMap = false
|
||||
isMap = false;
|
||||
if (typeof res.length === 'undefined') {
|
||||
res = []
|
||||
res = [];
|
||||
}
|
||||
}
|
||||
if (currentObj != null) res.push(currentObj)
|
||||
currentObj = {}
|
||||
isMap = true
|
||||
continue
|
||||
if (currentObj != null) res.push(currentObj);
|
||||
currentObj = {};
|
||||
isMap = true;
|
||||
continue;
|
||||
} else if ((m = line.match(/^-\s*(.*)/))) {
|
||||
if (currentObj != null) currentObj.push(processValue(m[1]))
|
||||
if (currentObj != null) currentObj.push(processValue(m[1]));
|
||||
else {
|
||||
if (isMap) {
|
||||
isMap = false
|
||||
isMap = false;
|
||||
if (typeof res.length === 'undefined') {
|
||||
res = []
|
||||
res = [];
|
||||
}
|
||||
}
|
||||
res.push(processValue(m[1]))
|
||||
res.push(processValue(m[1]));
|
||||
}
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentObj != null) {
|
||||
if (isMap) {
|
||||
isMap = false
|
||||
isMap = false;
|
||||
if (typeof res.length === 'undefined') {
|
||||
res = []
|
||||
res = [];
|
||||
}
|
||||
}
|
||||
res.push(currentObj)
|
||||
res.push(currentObj);
|
||||
}
|
||||
}
|
||||
|
||||
for (var j = processedBlocks.length - 1; j >= 0; --j) {
|
||||
blocks.splice.call(blocks, processedBlocks[j], 1)
|
||||
blocks.splice.call(blocks, processedBlocks[j], 1);
|
||||
}
|
||||
|
||||
return res
|
||||
return res;
|
||||
}
|
||||
|
||||
function semanticAnalysis(blocks) {
|
||||
var res = processBlock(blocks.children)
|
||||
return res
|
||||
var res = processBlock(blocks.children);
|
||||
return res;
|
||||
}
|
||||
|
||||
function preProcess(src) {
|
||||
var m
|
||||
var lines = src.split('\n')
|
||||
var m;
|
||||
var lines = src.split('\n');
|
||||
|
||||
var r = regex['comment']
|
||||
var r = regex['comment'];
|
||||
|
||||
for (var i in lines) {
|
||||
if ((m = lines[i].match(r))) {
|
||||
@@ -443,24 +445,24 @@ function preProcess(src) {
|
||||
lines[i] = "";
|
||||
*/
|
||||
if (typeof m[3] !== 'undefined') {
|
||||
lines[i] = m[0].substr(0, m[0].length - m[3].length)
|
||||
lines[i] = m[0].substr(0, m[0].length - m[3].length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lines.join('\n')
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function load(str) {
|
||||
errors = []
|
||||
reference_blocks = []
|
||||
processing_time = new Date().getTime()
|
||||
var pre = preProcess(str)
|
||||
var doc = parser(pre)
|
||||
var res = semanticAnalysis(doc)
|
||||
processing_time = new Date().getTime() - processing_time
|
||||
errors = [];
|
||||
reference_blocks = [];
|
||||
processing_time = new Date().getTime();
|
||||
var pre = preProcess(str);
|
||||
var doc = parser(pre);
|
||||
var res = semanticAnalysis(doc);
|
||||
processing_time = new Date().getTime() - processing_time;
|
||||
|
||||
return res
|
||||
return res;
|
||||
}
|
||||
|
||||
export default load
|
||||
export default load;
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ function init(id) {
|
||||
appendScript();
|
||||
window.ga =
|
||||
window.ga ||
|
||||
function() {
|
||||
function () {
|
||||
(window.ga.q = window.ga.q || []).push(arguments);
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ function collect() {
|
||||
window.ga('send', 'pageview');
|
||||
}
|
||||
|
||||
const install = function(hook) {
|
||||
const install = function (hook) {
|
||||
if (!$docsify.ga) {
|
||||
console.error('[Docsify] ga is required.');
|
||||
return;
|
||||
|
||||
@@ -9,7 +9,7 @@ function init(options) {
|
||||
window._paq = window._paq || [];
|
||||
window._paq.push(['trackPageView']);
|
||||
window._paq.push(['enableLinkTracking']);
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
appendScript(options);
|
||||
window._paq.push(['setTrackerUrl', options.host + '/matomo.php']);
|
||||
window._paq.push(['setSiteId', String(options.id)]);
|
||||
@@ -26,7 +26,7 @@ function collect() {
|
||||
window._paq.push(['trackPageView']);
|
||||
}
|
||||
|
||||
const install = function(hook) {
|
||||
const install = function (hook) {
|
||||
if (!$docsify.matomo) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('[Docsify] matomo is required.');
|
||||
|
||||
@@ -13,7 +13,7 @@ const CONFIG = {
|
||||
pathNamespaces: undefined,
|
||||
};
|
||||
|
||||
const install = function(hook, vm) {
|
||||
const install = function (hook, vm) {
|
||||
const { util } = Docsify;
|
||||
const opts = vm.config.search || CONFIG;
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ function getTableData(token) {
|
||||
if (!token.text && token.type === 'table') {
|
||||
token.cells.unshift(token.header);
|
||||
token.text = token.cells
|
||||
.map(function(rows) {
|
||||
.map(function (rows) {
|
||||
return rows.join(' | ');
|
||||
})
|
||||
.join(' |\n ');
|
||||
|
||||
Reference in New Issue
Block a user