wikity 1.3.5 → 1.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common.js +1 -2
- package/dist/compile.js +17 -18
- package/dist/parse.js +7 -14
- package/dist/wiki.css.js +4 -4
- package/license.md +1 -1
- package/package.json +3 -3
- package/readme.md +4 -0
package/dist/common.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegExpBuilder =
|
|
3
|
+
exports.RegExpBuilder = RegExpBuilder;
|
|
4
4
|
function RegExpBuilder(regex, flag = 'mgi') {
|
|
5
5
|
return RegExp(regex.replace(/ /g, '').replace(/\|\|.+?\|\|/g, ''), flag);
|
|
6
6
|
}
|
|
7
|
-
exports.RegExpBuilder = RegExpBuilder;
|
package/dist/compile.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.eleventyCompile = eleventyCompile;
|
|
7
|
+
exports.compile = compile;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const glob_1 = __importDefault(require("glob"));
|
|
@@ -13,7 +14,6 @@ const wiki_css_1 = __importDefault(require("./wiki.css"));
|
|
|
13
14
|
function eleventyCompile(dir = '.', config = {}) {
|
|
14
15
|
compile(dir, { eleventy: true, ...config });
|
|
15
16
|
}
|
|
16
|
-
exports.eleventyCompile = eleventyCompile;
|
|
17
17
|
function compile(dir = '.', config = {}) {
|
|
18
18
|
var _a, _b, _c;
|
|
19
19
|
// set defaults
|
|
@@ -49,7 +49,7 @@ function compile(dir = '.', config = {}) {
|
|
|
49
49
|
// Create TOC
|
|
50
50
|
if (!metadata.notoc && (metadata.toc || (((_a = outText.match(/<h\d[^>]*>/g)) === null || _a === void 0 ? void 0 : _a.length) || 0) > 3)) {
|
|
51
51
|
let toc = '';
|
|
52
|
-
let headings = Array.from(parsedContent.match(/<h\d[^>]*>.+?<\/h\d>/gs) || []);
|
|
52
|
+
let headings = Array.from(parsedContent.match(/<h\d auto[^>]*>.+?<\/h\d>/gs) || []);
|
|
53
53
|
headings.forEach(match => {
|
|
54
54
|
var _a;
|
|
55
55
|
const headingInner = match.replace(/\s*<\/?h\d[^>]*>\s*/g, '');
|
|
@@ -59,25 +59,29 @@ function compile(dir = '.', config = {}) {
|
|
|
59
59
|
});
|
|
60
60
|
toc = toc.replace(/<\/ol>\s*<ol>/g, '');
|
|
61
61
|
const tocElem = (0, dedent_1.default) `
|
|
62
|
-
<div id="
|
|
63
|
-
<span id="
|
|
62
|
+
<div id="page_toc">
|
|
63
|
+
<span id="page_toc_heading">
|
|
64
64
|
<strong>Contents</strong>
|
|
65
65
|
[<a href="javascript:void(0)" onclick="
|
|
66
|
-
document.getElementById('
|
|
66
|
+
document.getElementById('page_toc_contents').setAttribute('style', this.innerText === 'hide' ? 'display: none;' : '');
|
|
67
67
|
this.innerText = this.innerText === 'hide' ? 'show' : 'hide';
|
|
68
68
|
">hide</a>]
|
|
69
69
|
</span>
|
|
70
|
-
<ol id="
|
|
70
|
+
<ol id="page_toc_contents">${toc}</ol>
|
|
71
71
|
</div>
|
|
72
72
|
`;
|
|
73
73
|
// Set TOC on page
|
|
74
|
-
if (outText.includes('<toc></toc>'))
|
|
74
|
+
if (outText.includes('<toc></toc>')) {
|
|
75
|
+
// put TOC where explicitly declared
|
|
75
76
|
outText = outText.replace('<toc></toc>', tocElem);
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// put TOC above first auto heading
|
|
80
|
+
outText = outText.replace(/<h[1-6] auto/, tocElem + '$&');
|
|
81
|
+
}
|
|
78
82
|
}
|
|
79
83
|
// Create plaintext of HTML for use as description/metadata property.
|
|
80
|
-
const plaintextData = parsedContent.replace(/<.+?>/gs, '
|
|
84
|
+
const plaintextData = parsedContent.replace(/<.+?>/gs, '');
|
|
81
85
|
// Create HTML
|
|
82
86
|
const folderUpCount = file.split(/[\/\\]/).length - dir.split(/[\/\\]/).length; // number of folders to go up by to get to root
|
|
83
87
|
const html = (0, dedent_1.default) `
|
|
@@ -104,9 +108,7 @@ function compile(dir = '.', config = {}) {
|
|
|
104
108
|
</html>
|
|
105
109
|
`;
|
|
106
110
|
// Write to file
|
|
107
|
-
|
|
108
|
-
fs_1.default.mkdirSync(path_1.default.dirname(outFilePath));
|
|
109
|
-
}
|
|
111
|
+
fs_1.default.mkdirSync(path_1.default.dirname(outFilePath), { recursive: true });
|
|
110
112
|
const formattedHtml = html.replace(/\n[\n\s]+/g, '\n');
|
|
111
113
|
fs_1.default.writeFileSync(outFilePath, frontMatter + '\n' + formattedHtml, 'utf8');
|
|
112
114
|
// Move images
|
|
@@ -114,9 +116,7 @@ function compile(dir = '.', config = {}) {
|
|
|
114
116
|
if (err) {
|
|
115
117
|
console.warn(err);
|
|
116
118
|
}
|
|
117
|
-
|
|
118
|
-
fs_1.default.mkdirSync(outputImagesFolder);
|
|
119
|
-
}
|
|
119
|
+
fs_1.default.mkdirSync(outputImagesFolder, { recursive: true });
|
|
120
120
|
for (const file of files) {
|
|
121
121
|
fs_1.default.copyFileSync(file, path_1.default.join(outputImagesFolder, path_1.default.basename(file)));
|
|
122
122
|
}
|
|
@@ -138,4 +138,3 @@ function compile(dir = '.', config = {}) {
|
|
|
138
138
|
}
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
|
-
exports.compile = compile;
|
package/dist/parse.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.rawParse = rawParse;
|
|
7
|
+
exports.parse = parse;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const dateformat_1 = __importDefault(require("dateformat"));
|
|
@@ -34,7 +35,6 @@ const escaper = (text, n = 0) => `%${text}#${n}`;
|
|
|
34
35
|
function rawParse(data, config = {}) {
|
|
35
36
|
return parse(data, config).data;
|
|
36
37
|
}
|
|
37
|
-
exports.rawParse = rawParse;
|
|
38
38
|
function parse(data, config = {}) {
|
|
39
39
|
var _a, _b, _c;
|
|
40
40
|
const KEY = Math.random().toString().slice(2); // key used to allow certain disallowed HTML elements
|
|
@@ -121,7 +121,7 @@ function parse(data, config = {}) {
|
|
|
121
121
|
image-${imageData.type || 'default'}
|
|
122
122
|
"
|
|
123
123
|
style="
|
|
124
|
-
|
|
124
|
+
margin: 8px;
|
|
125
125
|
float: ${imageData.float || 'none'};
|
|
126
126
|
clear: ${imageData.float || 'none'};
|
|
127
127
|
vertical-align: ${imageData.align || 'unset'};
|
|
@@ -309,7 +309,7 @@ function parse(data, config = {}) {
|
|
|
309
309
|
// Headings: ==heading==
|
|
310
310
|
.replace((0, common_1.RegExpBuilder)(r `^ (=+) \s* (.+?) \s* \1 \s* $`), (_, lvl, txt) => {
|
|
311
311
|
const linkForm = encodeURI(txt.replace(/ /g, '_').replace(/<.+?>/g, ''));
|
|
312
|
-
return `<h${lvl.length} id="${linkForm}">${txt}</h${lvl.length}>`;
|
|
312
|
+
return `<h${lvl.length} auto id="${linkForm}">${txt}</h${lvl.length}>`;
|
|
313
313
|
})
|
|
314
314
|
// Bulleted list: *item
|
|
315
315
|
.replace((0, common_1.RegExpBuilder)(r `^ (\*+) (.+?) $`), (_, lvl, content) => {
|
|
@@ -369,14 +369,8 @@ function parse(data, config = {}) {
|
|
|
369
369
|
if (!ref)
|
|
370
370
|
return _;
|
|
371
371
|
ref.i++;
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
<a id="cite-${ref.id}${ref.i > 0 ? `_${ref.i}` : ''}" class="ref" href="#ref-${ref.id}">
|
|
375
|
-
[${ref.id}]
|
|
376
|
-
</a>
|
|
377
|
-
</sup>
|
|
378
|
-
`;
|
|
379
|
-
return content;
|
|
372
|
+
const citeId = `cite-${ref.id}${ref.i > 0 ? `_${ref.i}` : ''}`;
|
|
373
|
+
return `<sup class="refnote"><a id="${citeId}" class="ref" href="#ref-${ref.id}">[${ref.id}]</a></sup>`;
|
|
380
374
|
})
|
|
381
375
|
// Nonstandard: ``code`` and ```code blocks```
|
|
382
376
|
.replace((0, common_1.RegExpBuilder)(r ` \`\`\` ([^\`]+?) \`\`\` `), '<pre>$1</pre>')
|
|
@@ -397,7 +391,7 @@ function parse(data, config = {}) {
|
|
|
397
391
|
let multiRefContent = '';
|
|
398
392
|
if (refdata.i > 0) {
|
|
399
393
|
for (let i = 0; i <= refdata.i; i++) {
|
|
400
|
-
multiRefContent += `<sup><a href="#cite-${refdata.id}${i > 0 ? `_${i}` : ''}">${i + 1}</a></sup
|
|
394
|
+
multiRefContent += `<sup><a href="#cite-${refdata.id}${i > 0 ? `_${i}` : ''}">${i + 1}</a></sup> `;
|
|
401
395
|
}
|
|
402
396
|
}
|
|
403
397
|
const refline = `
|
|
@@ -420,4 +414,3 @@ function parse(data, config = {}) {
|
|
|
420
414
|
const result = { data: outText, metadata: metadata };
|
|
421
415
|
return result;
|
|
422
416
|
}
|
|
423
|
-
exports.parse = parse;
|
package/dist/wiki.css.js
CHANGED
|
@@ -8,7 +8,7 @@ ul, ol {margin: 0.3em 0 0 1.6em; padding: 0;}
|
|
|
8
8
|
dt {font-weight: bold;}
|
|
9
9
|
dd, dl dl {margin-block: 0; margin-inline-start: 30px;}
|
|
10
10
|
|
|
11
|
-
figure {margin: 1em;}
|
|
11
|
+
figure {margin: 1em; width: 300px;}
|
|
12
12
|
.image-thumb, .image-frame {padding: 6px; border: 1px solid gray;}
|
|
13
13
|
.image-default {margin: 0;}
|
|
14
14
|
figcaption {padding-top: 6px;}
|
|
@@ -26,9 +26,9 @@ a.external-link::after {content: '\1f855';}
|
|
|
26
26
|
a.redlink {color: #d33;}
|
|
27
27
|
a.redlink:visited {color: #b44;}
|
|
28
28
|
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
29
|
+
#page_toc {border: 1px solid #aab; padding: 8px; width: fit-content; background-color: #f8f8f8; font-size: 95%;}
|
|
30
|
+
#page_toc_heading {display: block; text-align: center;}
|
|
31
|
+
#page_toc ol {margin: 0 0 0 1.3em;}
|
|
32
32
|
|
|
33
33
|
#infobox {float: right; clear: right; margin: 0 0 1em 1em; width: 300px; padding: 2px; border: 1px solid #CCC; overflow: auto; font-size: 90%;}
|
|
34
34
|
#infobox tr:first-child :first-child {padding: 10px; text-align: center; font-weight: bold; font-size: 120%;}
|
package/license.md
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikity",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "Compile wikitext to HTML
|
|
3
|
+
"version": "1.3.7",
|
|
4
|
+
"description": "Compile wikitext to HTML! Supporst use of wikitext as a templating language.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "tsc && cd test && eleventy"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"license": "ISC",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"dateformat": "^4.6.3",
|
|
42
|
-
"dedent": "^1.
|
|
42
|
+
"dedent": "^1.7.1",
|
|
43
43
|
"escape-html": "^1.0.3",
|
|
44
44
|
"glob": "^8.1.0"
|
|
45
45
|
},
|
package/readme.md
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
This package comes with built-in support for compilation using [Eleventy](https://11ty.dev).
|
|
10
10
|
|
|
11
|
+
## Exemplar
|
|
12
|
+
|
|
13
|
+
See the `example` folder for a template on making your own wiki site!
|
|
14
|
+
|
|
11
15
|
## Install
|
|
12
16
|
|
|
13
17
|
Wikity is available [on npm](https://www.npmjs.com/package/wikity).
|