wikity 1.3.1 → 1.3.3
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/cli.js +1 -1
- package/dist/compile.js +40 -34
- package/dist/parse.js +49 -30
- package/package.json +7 -11
- package/readme.md +8 -7
package/dist/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ else if (arg(1).includes('c')) {
|
|
|
31
31
|
const configArgs = args.slice(2);
|
|
32
32
|
const argsList = configArgs.join(' ');
|
|
33
33
|
// retrieve item from arguments list
|
|
34
|
-
const getArgContent = (arg) => arg.test(argsList) && configArgs.filter((_, i) => arg.test(configArgs[i - 1])).join(' ') ||
|
|
34
|
+
const getArgContent = (arg) => arg.test(argsList) && configArgs.filter((_, i) => arg.test(configArgs[i - 1])).join(' ') || undefined;
|
|
35
35
|
// Fetch user-supplied arguments
|
|
36
36
|
const folder = arg(2) || '.';
|
|
37
37
|
const outputFolder = getArgContent(/^-+o/);
|
package/dist/compile.js
CHANGED
|
@@ -4,37 +4,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.compile = exports.eleventyCompile = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const glob_1 = __importDefault(require("glob"));
|
|
10
|
+
const dedent_1 = __importDefault(require("dedent"));
|
|
11
|
+
const formatter = require('html-formatter'); // does not have type package
|
|
11
12
|
const parse_1 = require("./parse");
|
|
12
|
-
const common_1 = require("./common");
|
|
13
13
|
const wiki_css_1 = __importDefault(require("./wiki.css"));
|
|
14
|
-
const r = String.raw;
|
|
15
14
|
function eleventyCompile(dir = '.', config = {}) {
|
|
16
15
|
compile(dir, { eleventy: true, ...config });
|
|
17
16
|
}
|
|
18
17
|
exports.eleventyCompile = eleventyCompile;
|
|
19
18
|
function compile(dir = '.', config = {}) {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
// set defaults
|
|
21
|
+
(_a = config.templatesFolder) !== null && _a !== void 0 ? _a : (config.templatesFolder = 'templates');
|
|
22
|
+
(_b = config.imagesFolder) !== null && _b !== void 0 ? _b : (config.imagesFolder = 'images');
|
|
23
|
+
(_c = config.outputFolder) !== null && _c !== void 0 ? _c : (config.outputFolder = 'wikity-out');
|
|
24
|
+
// directory variables (absolute paths)
|
|
25
|
+
const baseDir = path_1.default.resolve(dir);
|
|
26
|
+
const templatesFolder = path_1.default.join(baseDir, config.templatesFolder);
|
|
27
|
+
const imagesFolder = path_1.default.join(baseDir, config.imagesFolder);
|
|
28
|
+
const outputFolder = path_1.default.join(baseDir, config.outputFolder);
|
|
29
|
+
const outputImagesFolder = path_1.default.join(baseDir, config.outputFolder, config.imagesFolder);
|
|
30
|
+
const newConfig = { ...config, templatesFolder, imagesFolder, outputFolder };
|
|
20
31
|
let stylesCreated = false;
|
|
21
32
|
// Write wikitext files
|
|
22
|
-
const files =
|
|
33
|
+
const files = glob_1.default.sync(dir + "/**/*.wiki", {});
|
|
23
34
|
files.forEach((file) => {
|
|
24
35
|
var _a;
|
|
25
|
-
const fileData =
|
|
26
|
-
const { data: parsedContent, metadata } = (0, parse_1.parse)(fileData,
|
|
36
|
+
const fileData = fs_1.default.readFileSync(file, { encoding: 'utf8' });
|
|
37
|
+
const { data: parsedContent, metadata } = (0, parse_1.parse)(fileData, newConfig);
|
|
27
38
|
let outText = parsedContent;
|
|
28
|
-
const
|
|
29
|
-
const imagesFolder = config.imagesFolder || 'images';
|
|
30
|
-
const outputFolder = config.outputFolder || 'wikity-out';
|
|
31
|
-
const [, folder, filename] = file.match((0, common_1.RegExpBuilder)(r `^(.+?[\/\\]) ((?:(?:${templatesFolder}|${imagesFolder})[\/\\])?[^\/\\]+)$`, '')) || [];
|
|
32
|
-
const outFolder = dir + '/' + outputFolder + '/';
|
|
39
|
+
const filename = file.replace(dir, '').replace(/^[\/\\]/, '');
|
|
33
40
|
const outFilename = filename.replace(/ /g, '_').replace('.wiki', '.html');
|
|
34
|
-
const
|
|
41
|
+
const outFilePath = path_1.default.join(outputFolder, outFilename);
|
|
42
|
+
const urlPath = outFilename.replace(/(?<=^|\/)\w/g, m => m.toUpperCase()); // capitalise first letters
|
|
35
43
|
const displayTitle = metadata.displayTitle || urlPath.replace('.html', '');
|
|
36
44
|
// Eleventy configuration
|
|
37
|
-
const frontMatter = config.eleventy ?
|
|
45
|
+
const frontMatter = config.eleventy ? (0, dedent_1.default) `
|
|
38
46
|
---
|
|
39
47
|
permalink: /wiki/${urlPath}
|
|
40
48
|
---
|
|
@@ -49,7 +57,7 @@ function compile(dir = '.', config = {}) {
|
|
|
49
57
|
const lvl = +(((_a = match.match(/\d/g)) === null || _a === void 0 ? void 0 : _a[0]) || -1);
|
|
50
58
|
toc += `${`<ol>`.repeat(lvl - 1)} <li> <a href="#${encodeURI(text.replace(/ /g, '_'))}">${text}</a> </li> ${`</ol>`.repeat(lvl - 1)}`;
|
|
51
59
|
});
|
|
52
|
-
const tocElem =
|
|
60
|
+
const tocElem = (0, dedent_1.default) `
|
|
53
61
|
<div id="toc">
|
|
54
62
|
<span id="toc-heading">
|
|
55
63
|
<strong>Contents</strong>
|
|
@@ -70,14 +78,15 @@ function compile(dir = '.', config = {}) {
|
|
|
70
78
|
// Create plaintext of HTML for use as description/metadata property.
|
|
71
79
|
const plaintextData = parsedContent.replace(/<.+?>/gs, ' ');
|
|
72
80
|
// Create HTML
|
|
73
|
-
const
|
|
81
|
+
const folderUpCount = file.split(/[\/\\]/).length - dir.split(/[\/\\]/).length; // number of folders to go up by to get to root
|
|
82
|
+
const html = (0, dedent_1.default) `
|
|
74
83
|
<html>
|
|
75
84
|
<head>
|
|
76
85
|
<meta charset="utf-8">
|
|
77
86
|
<meta name="viewport" content="initial-scale=1.0, width=device-width">
|
|
78
87
|
<meta name="description" content="${plaintextData.substring(0, 256)}...">
|
|
79
88
|
<title>${displayTitle}</title>
|
|
80
|
-
<link id="default-styles" rel="stylesheet" href="
|
|
89
|
+
<link id="default-styles" rel="stylesheet" href="${'../'.repeat(folderUpCount)}./wiki.css">
|
|
81
90
|
</head>
|
|
82
91
|
<body>
|
|
83
92
|
<header>
|
|
@@ -94,25 +103,21 @@ function compile(dir = '.', config = {}) {
|
|
|
94
103
|
</html>
|
|
95
104
|
`;
|
|
96
105
|
// Write to file
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
fs.mkdirSync(outFolder + path);
|
|
100
|
-
}
|
|
106
|
+
if (!fs_1.default.existsSync(path_1.default.dirname(outFilePath))) {
|
|
107
|
+
fs_1.default.mkdirSync(path_1.default.dirname(outFilePath));
|
|
101
108
|
}
|
|
102
|
-
;
|
|
103
|
-
|
|
104
|
-
fs.writeFileSync(outFolder + outFilename, frontMatter + '\n' + renderedHtml, 'utf8');
|
|
109
|
+
const renderedHtml = formatter.render(html.replace(/(<\/\w+>) +(\S)/g, '$1 $2'));
|
|
110
|
+
fs_1.default.writeFileSync(outFilePath, frontMatter + '\n' + renderedHtml, 'utf8');
|
|
105
111
|
// Move images
|
|
106
|
-
|
|
112
|
+
(0, glob_1.default)(imagesFolder + '/*', {}, (err, files) => {
|
|
107
113
|
if (err) {
|
|
108
114
|
console.warn(err);
|
|
109
115
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
fs.mkdirSync(outImagesFolder);
|
|
116
|
+
if (!fs_1.default.existsSync(outputImagesFolder)) {
|
|
117
|
+
fs_1.default.mkdirSync(outputImagesFolder);
|
|
113
118
|
}
|
|
114
119
|
for (const file of files) {
|
|
115
|
-
|
|
120
|
+
fs_1.default.copyFileSync(file, path_1.default.join(outputImagesFolder, path_1.default.basename(file)));
|
|
116
121
|
}
|
|
117
122
|
;
|
|
118
123
|
});
|
|
@@ -126,13 +131,14 @@ function compile(dir = '.', config = {}) {
|
|
|
126
131
|
if (config.customStyles) {
|
|
127
132
|
styles += config.customStyles;
|
|
128
133
|
}
|
|
129
|
-
const cssOutput =
|
|
134
|
+
const cssOutput = config.eleventy ? (0, dedent_1.default) `
|
|
130
135
|
---
|
|
131
136
|
permalink: /wiki.css
|
|
132
137
|
---
|
|
133
138
|
${styles}
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
` : styles;
|
|
140
|
+
const cssOutFilename = config.eleventy ? 'wiki.css.njk' : 'wiki.css';
|
|
141
|
+
fs_1.default.writeFileSync(path_1.default.join(outputFolder, cssOutFilename), cssOutput);
|
|
136
142
|
}
|
|
137
143
|
});
|
|
138
144
|
}
|
package/dist/parse.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.parse = exports.rawParse = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const escape_html_1 = __importDefault(require("escape-html"));
|
|
10
|
+
const dateformat_1 = __importDefault(require("dateformat"));
|
|
7
11
|
const common_1 = require("./common");
|
|
8
12
|
const r = String.raw;
|
|
9
13
|
const MAX_RECURSION = 20;
|
|
10
|
-
const MAX_ARG_COUNT = 10;
|
|
11
14
|
const arg = r `\s*([^|}]+?)\s*`;
|
|
15
|
+
function fullyEscape(text) {
|
|
16
|
+
return (0, escape_html_1.default)(text)
|
|
17
|
+
.replace(/{/g, '{'); // avoid keeping plain {{}} which is parsed as a template call
|
|
18
|
+
}
|
|
12
19
|
function rawParse(data, config = {}) {
|
|
13
20
|
return parse(data, config).data;
|
|
14
21
|
}
|
|
15
22
|
exports.rawParse = rawParse;
|
|
16
23
|
function parse(data, config = {}) {
|
|
17
|
-
|
|
18
|
-
const
|
|
24
|
+
var _a, _b, _c;
|
|
25
|
+
const templatesFolder = (_a = config.templatesFolder) !== null && _a !== void 0 ? _a : 'templates';
|
|
26
|
+
const imagesFolder = (_b = config.imagesFolder) !== null && _b !== void 0 ? _b : 'images';
|
|
27
|
+
const outputFolder = (_c = config.outputFolder) !== null && _c !== void 0 ? _c : 'wikity-out';
|
|
19
28
|
const vars = {};
|
|
20
29
|
const metadata = {};
|
|
21
30
|
const nowikis = [];
|
|
@@ -24,14 +33,14 @@ function parse(data, config = {}) {
|
|
|
24
33
|
let rawExtLinkCount = 0;
|
|
25
34
|
let refCount = 0;
|
|
26
35
|
let outText = data;
|
|
27
|
-
|
|
36
|
+
const escaper = (text, n) => `%${text}#${n}`;
|
|
28
37
|
for (let l = 0, last = ''; l < MAX_RECURSION; l++) {
|
|
29
38
|
if (last === outText)
|
|
30
39
|
break;
|
|
31
40
|
last = outText;
|
|
32
41
|
outText = outText
|
|
33
42
|
// Nowiki: <nowiki></nowiki>
|
|
34
|
-
.replace((0, common_1.RegExpBuilder)(r `<nowiki> ([^]+?) </nowiki>`), (_, m) =>
|
|
43
|
+
.replace((0, common_1.RegExpBuilder)(r `<nowiki> ([^]+?) </nowiki>`), (_, m) => (nowikis.push(m), escaper('NOWIKI', nowikiCount++)))
|
|
35
44
|
// Sanitise unacceptable HTML
|
|
36
45
|
.replace((0, common_1.RegExpBuilder)(r `<(/?) \s* (?= script|link|meta|iframe|frameset|object|embed|applet|form|input|button|textarea )`), '<$1')
|
|
37
46
|
.replace((0, common_1.RegExpBuilder)(r `(?<= <[^>]+ ) (\bon(\w+))`), 'data-$2')
|
|
@@ -39,16 +48,22 @@ function parse(data, config = {}) {
|
|
|
39
48
|
.replace(/<!--[^]+?-->/g, '')
|
|
40
49
|
// Lines: ----
|
|
41
50
|
.replace(/^-{4,}/gm, '<hr>')
|
|
51
|
+
// Internal links: [[Page]] and [[Page|Text]]
|
|
52
|
+
.replace((0, common_1.RegExpBuilder)(r `\[\[ ([^\]|]+?) \]\]`), `<a class{{=}}"internal-link" title{{=}}"$1" href{{=}}"$1">$1</a>`)
|
|
53
|
+
.replace((0, common_1.RegExpBuilder)(r `\[\[ ([^\]|]+?) \| ([^\]]+?) \]\]`), `<a class{{=}}"internal-link" title{{=}}"$1" href{{=}}"/$1">$2</a>`)
|
|
54
|
+
.replace((0, common_1.RegExpBuilder)(r `(</a>)([a-z]+)`), '$2$1')
|
|
55
|
+
// External links: [href Page] and just [href]
|
|
56
|
+
.replace((0, common_1.RegExpBuilder)(r `\[ ((?:\w+:)?\/\/ [^\s\]]+) (\s [^\]]+?)? \]`), (_, href, txt) => `<a class{{=}}"external-link" href{{=}}"${href}">${txt || '[' + (++rawExtLinkCount) + ']'}</a>`)
|
|
57
|
+
// Magic words: {{!}}, {{reflist}}, etc
|
|
58
|
+
.replace((0, common_1.RegExpBuilder)(r `{{ \s* ! \s* }}`), escaper('VERT', 0))
|
|
59
|
+
.replace((0, common_1.RegExpBuilder)(r `{{ \s* = \s* }}`), escaper('EQUALS', 0))
|
|
60
|
+
.replace((0, common_1.RegExpBuilder)(r `{{ \s* [Rr]eflist \s* }}`), '<references/>')
|
|
42
61
|
// Metadata: displayTitle, __NOTOC__, etc
|
|
43
62
|
.replace((0, common_1.RegExpBuilder)(r `{{ \s* displayTitle: ([^}]+) }}`), (_, title) => (metadata.displayTitle = title, ''))
|
|
44
63
|
.replace((0, common_1.RegExpBuilder)(r `__NOINDEX__`), () => (metadata.noindex = true, ''))
|
|
45
64
|
.replace((0, common_1.RegExpBuilder)(r `__NOTOC__`), () => (metadata.notoc = true, ''))
|
|
46
65
|
.replace((0, common_1.RegExpBuilder)(r `__FORCETOC__`), () => (metadata.toc = true, ''))
|
|
47
66
|
.replace((0, common_1.RegExpBuilder)(r `__TOC__`), () => (metadata.toc = true, `<toc></toc>`))
|
|
48
|
-
// Magic words: {{!}}, {{reflist}}, etc
|
|
49
|
-
.replace((0, common_1.RegExpBuilder)(r `{{ \s* ! \s* }}`), '|')
|
|
50
|
-
.replace((0, common_1.RegExpBuilder)(r `{{ \s* = \s* }}`), '=')
|
|
51
|
-
.replace((0, common_1.RegExpBuilder)(r `{{ \s* [Rr]eflist \s* }}`), '<references/>')
|
|
52
67
|
// String functions: {{lc:}}, {{ucfirst:}}, {{len:}}, etc
|
|
53
68
|
.replace((0, common_1.RegExpBuilder)(r `{{ \s* #? urlencode: ${arg} }}`), (_, m) => encodeURI(m))
|
|
54
69
|
.replace((0, common_1.RegExpBuilder)(r `{{ \s* #? urldecode: ${arg} }}`), (_, m) => decodeURI(m))
|
|
@@ -93,20 +108,21 @@ function parse(data, config = {}) {
|
|
|
93
108
|
const errMsg = `Wikity does not use Wikipedia's #time function syntax. Use repetition-based formatting (e.g. yyyy-mm-dd) instead.`;
|
|
94
109
|
console.warn(`<Wikity> [WARN] ${errMsg}`);
|
|
95
110
|
}
|
|
96
|
-
return
|
|
111
|
+
return (0, dateformat_1.default)(args[1] ? new Date(args[1]) : new Date(), args[0]);
|
|
97
112
|
}
|
|
98
113
|
})
|
|
99
114
|
// Templates: {{template}}
|
|
100
115
|
.replace((0, common_1.RegExpBuilder)(r `(?<!{) {{ \s* ([^#{}|]+?) (\|[^{}]+)? }} (?!})`), (_, title, params = '') => {
|
|
101
|
-
const page = templatesFolder
|
|
116
|
+
const page = path_1.default.join(templatesFolder, title.trim().replace(/ /g, '_'));
|
|
102
117
|
let content = '';
|
|
103
118
|
// Try retrieve template content
|
|
104
119
|
try {
|
|
105
|
-
content =
|
|
120
|
+
content = fs_1.default.readFileSync(page + '.wiki', { encoding: 'utf8' });
|
|
106
121
|
}
|
|
107
122
|
catch {
|
|
108
123
|
// Return redlink if template doesn't exist
|
|
109
|
-
|
|
124
|
+
const relPage = path_1.default.basename(templatesFolder) + '/' + path_1.default.relative(templatesFolder, page);
|
|
125
|
+
return `<a class="internal-link redlink" title="${title}" href="${relPage}">${title}</a>`;
|
|
110
126
|
}
|
|
111
127
|
// Remove non-template sections
|
|
112
128
|
content = content
|
|
@@ -119,7 +135,7 @@ function parse(data, config = {}) {
|
|
|
119
135
|
for (let i = 1; i < args.length; i++) {
|
|
120
136
|
const parts = args[i].split('=');
|
|
121
137
|
const [arg, val] = parts[1]
|
|
122
|
-
? [parts[0],
|
|
138
|
+
? [parts[0], parts.slice(1).join('=')]
|
|
123
139
|
: [i.toString(), parts[0]];
|
|
124
140
|
content = content.replace(argMatch(arg), (_, defaultVal) => val || defaultVal || '');
|
|
125
141
|
}
|
|
@@ -133,7 +149,7 @@ function parse(data, config = {}) {
|
|
|
133
149
|
.replace((0, common_1.RegExpBuilder)(r `\[\[ (?:File|Image): (.+?) (\|.+?)? \]\]`), (_, file, params = '') => {
|
|
134
150
|
if (/{{/.test(params))
|
|
135
151
|
return _;
|
|
136
|
-
const path = imagesFolder
|
|
152
|
+
const path = path_1.default.join(imagesFolder, file.trim().replace(/ /g, '_'));
|
|
137
153
|
let caption = '';
|
|
138
154
|
let imageData = {};
|
|
139
155
|
let imageArgs = params.split('|').map((arg) => arg.replace(/"/g, '"'));
|
|
@@ -197,7 +213,7 @@ function parse(data, config = {}) {
|
|
|
197
213
|
"
|
|
198
214
|
>
|
|
199
215
|
<img
|
|
200
|
-
src="${path}"
|
|
216
|
+
src="${path_1.default.basename(imagesFolder)}/${path_1.default.relative(imagesFolder, path)}"
|
|
201
217
|
alt="${imageData.alt || file}"
|
|
202
218
|
width="${imageData.width || 300}"
|
|
203
219
|
height="${imageData.height || 300}"
|
|
@@ -215,12 +231,6 @@ function parse(data, config = {}) {
|
|
|
215
231
|
.replace((0, common_1.RegExpBuilder)(r `'' ([^']+?) ''`), '<i>$1</i>')
|
|
216
232
|
// Headings: ==heading==
|
|
217
233
|
.replace((0, common_1.RegExpBuilder)(r `^ (=+) \s* (.+?) \s* \1 \s* $`), (_, lvl, txt) => `<h${lvl.length} id="${encodeURI(txt.replace(/ /g, '_'))}">${txt}</h${lvl.length}>`)
|
|
218
|
-
// Internal links: [[Page]] and [[Page|Text]]
|
|
219
|
-
.replace((0, common_1.RegExpBuilder)(r `\[\[ ([^\]|]+?) \]\]`), `<a class="internal-link" title="$1" href="$1">$1</a>`)
|
|
220
|
-
.replace((0, common_1.RegExpBuilder)(r `\[\[ ([^\]|]+?) \| ([^\]]+?) \]\]`), `<a class="internal-link" title="$1" href="/$1">$2</a>`)
|
|
221
|
-
.replace((0, common_1.RegExpBuilder)(r `(</a>)([a-z]+)`), '$2$1')
|
|
222
|
-
// External links: [href Page] and just [href]
|
|
223
|
-
.replace((0, common_1.RegExpBuilder)(r `\[ ((?:\w+:)?\/\/ [^\s\]]+) (\s [^\]]+?)? \]`), (_, href, txt) => `<a class="external-link" href="${href}">${txt || '[' + (++rawExtLinkCount) + ']'}</a>`)
|
|
224
234
|
// Bulleted list: *item
|
|
225
235
|
.replace((0, common_1.RegExpBuilder)(r `^ (\*+) (.+?) $`), (_, lvl, txt) => `${'<ul>'.repeat(lvl.length)}<li>${txt}</li>${'</ul>'.repeat(lvl.length)}`)
|
|
226
236
|
.replace((0, common_1.RegExpBuilder)(r `</ul> (\s*?) <ul>`), '$1')
|
|
@@ -228,14 +238,16 @@ function parse(data, config = {}) {
|
|
|
228
238
|
.replace((0, common_1.RegExpBuilder)(r `^ (#+) (.+?) $`), (_, lvl, txt) => `${'<ol>'.repeat(lvl.length)}<li>${txt}</li>${'</ol>'.repeat(lvl.length)}`)
|
|
229
239
|
.replace((0, common_1.RegExpBuilder)(r `</ol> (\s*?) <ol>`), '$1')
|
|
230
240
|
// Definition list: ;head, :item
|
|
231
|
-
.replace((0, common_1.RegExpBuilder)(r `^ ; (
|
|
241
|
+
.replace((0, common_1.RegExpBuilder)(r `^ ; (.+?) : (.+?) $`), `<dl><dt>$1</td><dd>$2</dd></dl>`)
|
|
232
242
|
.replace((0, common_1.RegExpBuilder)(r `^ (:+) (.+?) $`), (_, lvl, txt) => `${'<dl>'.repeat(lvl.length)}<dd>${txt}</dd>${'</dl>'.repeat(lvl.length)}`)
|
|
243
|
+
.replace((0, common_1.RegExpBuilder)(r `^ ; (.+) $`), '<dl><dt>$1</dt></dl>')
|
|
233
244
|
.replace((0, common_1.RegExpBuilder)(r `</dl> (\s*?) <dl>`), '$1')
|
|
234
245
|
// Tables: {|, |+, !, |-, |, |}
|
|
235
246
|
.replace((0, common_1.RegExpBuilder)(r `^ \{\| (.*?) $`), (_, attrs) => `<table ${attrs}><tr>`)
|
|
236
247
|
.replace((0, common_1.RegExpBuilder)(r `^ ! ([^]+?) (?= \n^[!|] )`), (_, content) => `<th>${content}</th>`)
|
|
237
248
|
.replace((0, common_1.RegExpBuilder)(r `^ \|\+ (.*?) $`), (_, content) => `<caption>${content}</caption>`)
|
|
238
|
-
.replace((0, common_1.RegExpBuilder)(r `^ \|[^-+}] ([^]*?) (?= \n
|
|
249
|
+
.replace((0, common_1.RegExpBuilder)(r `^ \|[^-+}] ([^]*?) (?= \n | \|\| )`), (_, content) => `<td>${content}</td>`)
|
|
250
|
+
.replace((0, common_1.RegExpBuilder)(r `\|\|[^-+}] ([^]*?) (?= \n | \|\| )`), (_, content) => `<td>${content}</td>`)
|
|
239
251
|
.replace((0, common_1.RegExpBuilder)(r `^ \|- (.*?) $`), (_, attrs) => `</tr><tr ${attrs}>`)
|
|
240
252
|
.replace((0, common_1.RegExpBuilder)(r `^ \|\}`), `</tr></table>`)
|
|
241
253
|
// References: <ref></ref>, <references/>
|
|
@@ -249,10 +261,17 @@ function parse(data, config = {}) {
|
|
|
249
261
|
.replace((0, common_1.RegExpBuilder)(r ` \`\`\` ([^\`]+?) \`\`\` `), '<pre>$1</pre>')
|
|
250
262
|
.replace((0, common_1.RegExpBuilder)(r ` \`\` ([^\`]+?) \`\` `), '<code>$1</code>')
|
|
251
263
|
// Spacing
|
|
252
|
-
.replace(/(\r?\n){2}/g, '\n</p><p>\n')
|
|
253
|
-
|
|
254
|
-
|
|
264
|
+
.replace(/(\r?\n){2}/g, '\n</p><p>\n');
|
|
265
|
+
}
|
|
266
|
+
// Restore nowiki contents
|
|
267
|
+
for (let i = 0; i < nowikis.length; i++) {
|
|
268
|
+
outText = outText
|
|
269
|
+
.replace(escaper('NOWIKI', i), (_, n) => fullyEscape(nowikis[n]));
|
|
255
270
|
}
|
|
271
|
+
// Substitute magic word functions
|
|
272
|
+
outText = outText
|
|
273
|
+
.replaceAll(escaper('VERT', 0), '|')
|
|
274
|
+
.replaceAll(escaper('EQUALS', 0), '=');
|
|
256
275
|
const result = { data: outText, metadata: metadata };
|
|
257
276
|
return result;
|
|
258
277
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikity",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Compile wikitext to HTML: wikitext as a templating language.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -39,20 +39,16 @@
|
|
|
39
39
|
"license": "ISC",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"dateformat": "^4.6.3",
|
|
42
|
-
"dedent": "^
|
|
42
|
+
"dedent": "^1.5.3",
|
|
43
43
|
"escape-html": "^1.0.3",
|
|
44
|
-
"glob": "^
|
|
44
|
+
"glob": "^8.1.0",
|
|
45
45
|
"html-formatter": "^0.1.9"
|
|
46
46
|
},
|
|
47
|
-
"peerDependencies": {
|
|
48
|
-
"@11ty/eleventy": ">=0.10.0"
|
|
49
|
-
},
|
|
50
|
-
"peerDependenciesMeta": {
|
|
51
|
-
"@11ty/eleventy": {
|
|
52
|
-
"optional": true
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
47
|
"devDependencies": {
|
|
48
|
+
"@types/dateformat": "^3.0.1",
|
|
49
|
+
"@types/dedent": "^0.7.2",
|
|
50
|
+
"@types/escape-html": "^1.0.4",
|
|
51
|
+
"@types/glob": "^8.1.0",
|
|
56
52
|
"@types/node": "ts5.0",
|
|
57
53
|
"typescript": "~5.0.4 <5.1"
|
|
58
54
|
}
|
package/readme.md
CHANGED
|
@@ -69,12 +69,13 @@ Use Wikity along with Eleventy to have all your wiki files compiled during the b
|
|
|
69
69
|
// .eleventy.js (eleventy's configuration file)
|
|
70
70
|
const wikity = require('wikity');
|
|
71
71
|
module.exports = function (eleventyConfig) {
|
|
72
|
-
const
|
|
73
|
-
const templatesFolder = 'templates', imagesFolder = 'images'
|
|
74
|
-
const
|
|
75
|
-
const
|
|
72
|
+
const rootFolder = 'src';
|
|
73
|
+
const templatesFolder = 'templates', imagesFolder = 'images'; // defaults; relative to root folder
|
|
74
|
+
const outputFolder = 'wikity-out'; // default
|
|
75
|
+
const wikityOptions = { eleventy: true, templatesFolder, imagesFolder, outputFolder };
|
|
76
|
+
const wikityPlugin = () => wikity.compile(rootFolder, wikityOptions);
|
|
76
77
|
eleventyConfig.addPlugin(wikityPlugin);
|
|
77
|
-
eleventyConfig.addPassthroughCopy({
|
|
78
|
+
eleventyConfig.addPassthroughCopy({ 'src/images': 'wiki/' + imagesFolder }); // Eleventy does not pass through images by default
|
|
78
79
|
}
|
|
79
80
|
```
|
|
80
81
|
|
|
@@ -83,10 +84,10 @@ The above will use the following file structure (with some example wiki files gi
|
|
|
83
84
|
- `src/`
|
|
84
85
|
- `templates/`: Directory for wiki templates (called like `{{this}}`)
|
|
85
86
|
- `images/`: Directory to place images (called like `[[File:this]]`)
|
|
86
|
-
- `wikity-out/`: File templates compiled from the `.wiki` files (add this to `.gitignore`)
|
|
87
87
|
- `Index.wiki`: Example file
|
|
88
88
|
- `Other_Page.wiki`: Example other file
|
|
89
|
-
- `
|
|
89
|
+
- `wikity-out/`: File templates compiled from the `.wiki` files (add this to `.gitignore`)
|
|
90
|
+
- `wiki/`: Output HTML files compiled from `wikity-out/` (add this to `.gitignore`)
|
|
90
91
|
|
|
91
92
|
(View the above starting at the URL path `/wiki/` when ran in an HTTP server.)
|
|
92
93
|
|