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:
Joe Pea
2020-11-02 22:40:25 -08:00
parent c354bceb92
commit d72dd287c8
62 changed files with 1052 additions and 616 deletions
+2 -2
View File
@@ -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;
+3 -3
View File
@@ -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/' +
+1 -1
View File
@@ -18,7 +18,7 @@ function handleExternalScript() {
}
}
const install = function(hook) {
const install = function (hook) {
hook.doneEach(handleExternalScript);
};
+2 -2
View File
@@ -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;
};
+18 -18
View File
@@ -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
View File
@@ -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
View File
@@ -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;
+2 -2
View File
@@ -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.');
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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 ');