wikity 1.3.0 → 1.3.1
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/bin/index.js +2 -0
- package/dist/cli.d.ts +1 -0
- package/{src → dist}/cli.js +58 -47
- package/dist/common.d.ts +20 -0
- package/dist/common.js +7 -0
- package/{src → dist}/compile.d.ts +3 -3
- package/dist/compile.js +139 -0
- package/{src → dist}/index.d.ts +11 -8
- package/dist/index.js +11 -0
- package/{src → dist}/parse.d.ts +3 -3
- package/dist/parse.js +259 -0
- package/dist/wiki.css.d.ts +2 -0
- package/dist/wiki.css.js +31 -0
- package/license.md +1 -1
- package/package.json +59 -54
- package/readme.md +47 -19
- package/src/cli.d.ts +0 -2
- package/src/common.d.ts +0 -15
- package/src/common.js +0 -15
- package/src/compile.js +0 -153
- package/src/index.js +0 -8
- package/src/parse.js +0 -239
package/package.json
CHANGED
|
@@ -1,54 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "wikity",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "Compile wikitext to HTML: wikitext as a templating language.",
|
|
5
|
-
"main": "
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "tsc && cd test && eleventy"
|
|
8
|
-
},
|
|
9
|
-
"bin": {
|
|
10
|
-
"wikity": "
|
|
11
|
-
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
"
|
|
51
|
-
"@
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "wikity",
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"description": "Compile wikitext to HTML: wikitext as a templating language.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "tsc && cd test && eleventy"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"wikity": "bin/index.js"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=12"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin/",
|
|
17
|
+
"dist/"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"compiler",
|
|
21
|
+
"compilation",
|
|
22
|
+
"wikitext",
|
|
23
|
+
"mediawiki",
|
|
24
|
+
"html",
|
|
25
|
+
"template-language",
|
|
26
|
+
"templating-language",
|
|
27
|
+
"eleventy",
|
|
28
|
+
"eleventy-plugin"
|
|
29
|
+
],
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/Nixinova/Wikity.git"
|
|
33
|
+
},
|
|
34
|
+
"author": "Nixinova (https://nixinova.com)",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/Nixinova/Wikity/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/Nixinova/Wikity#readme",
|
|
39
|
+
"license": "ISC",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"dateformat": "^4.6.3",
|
|
42
|
+
"dedent": "^0.7.0",
|
|
43
|
+
"escape-html": "^1.0.3",
|
|
44
|
+
"glob": "^7.2.3",
|
|
45
|
+
"html-formatter": "^0.1.9"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@11ty/eleventy": ">=0.10.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@11ty/eleventy": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "ts5.0",
|
|
57
|
+
"typescript": "~5.0.4 <5.1"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/readme.md
CHANGED
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
# Wikity
|
|
6
6
|
|
|
7
|
-
**Wikity** is a tool that allows you to use Wikitext (used by Wikipedia, Fandom, etc) as a templating language to create HTML pages
|
|
7
|
+
**Wikity** is a tool that allows you to use Wikitext (used by Wikipedia, Fandom, etc) as a templating language to create HTML pages.
|
|
8
|
+
|
|
9
|
+
This package comes with built-in support for compilation using [Eleventy](https://11ty.dev).
|
|
8
10
|
|
|
9
11
|
## Install
|
|
10
12
|
|
|
11
13
|
Wikity is available [on npm](https://www.npmjs.com/package/wikity).
|
|
14
|
+
Install locally to use in a Node package or install globally for use from the command-line.
|
|
12
15
|
|
|
13
16
|
| Local install | Global install |
|
|
14
17
|
| -------------------- | ----------------------- |
|
|
@@ -20,24 +23,33 @@ Wikity is available [on npm](https://www.npmjs.com/package/wikity).
|
|
|
20
23
|
|
|
21
24
|
- `wikity.compile(folder?: string, options?: object): void`
|
|
22
25
|
- Compile all Wikitext (`.wiki`) files from an input folder (defaults to the current directory, `.`) into HTML.
|
|
23
|
-
- `wikity.eleventyPlugin(folder?: string, options?: object): void`
|
|
24
|
-
- An implementation of `compile()` for use with Eleventy's `addPlugin` API. Identical to `compile()` except that option `eleventy` is `true` by default.
|
|
25
26
|
- `wikity.parse(input: string, options?: object): string`
|
|
26
|
-
- Parse raw wikitext input into HTML.
|
|
27
|
+
- Parse raw wikitext input into HTML.
|
|
27
28
|
|
|
28
29
|
- **Options**:
|
|
29
|
-
- `
|
|
30
|
-
- Where outputted HTML files shall be placed (default: `wikity-out`).
|
|
31
|
-
- `templatesFolder?: string`
|
|
32
|
-
- What folder to place templates in (default: `'templates'`).
|
|
33
|
-
- `imagesFolder?: string`
|
|
34
|
-
- What folder to place images in (default: `'images'`). Make sure to pass through this folder to your build output if applicable.
|
|
35
|
-
- `eleventy?: boolean`
|
|
30
|
+
- `eleventy: boolean = false`
|
|
36
31
|
- Whether [front matter](https://www.11ty.dev/docs/data-frontmatter/) will be added to the outputted HTML for Eleventy to read (default: `false`).
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
-
|
|
32
|
+
(**This parameter *must* be set to `true` if you want to use this with Eleventy.**)
|
|
33
|
+
- `outputFolder: string`
|
|
34
|
+
- *Used only with `compile()`.*
|
|
35
|
+
- Where outputted HTML files shall be placed.
|
|
36
|
+
- Default: `'wikity-out'`.
|
|
37
|
+
- `templatesFolder: string`
|
|
38
|
+
- What folder to place templates in.
|
|
39
|
+
- Default: `'templates'`.
|
|
40
|
+
- `imagesFolder: string`
|
|
41
|
+
- What folder to place images in.
|
|
42
|
+
- Default: `'images'`.
|
|
43
|
+
- `defaultStyles: boolean`
|
|
44
|
+
- *Used only with `compile()`.*
|
|
45
|
+
- Whether to use default wiki styling.
|
|
46
|
+
- Default: to `true` when called from `compile()` and `false` when called from `parse()`.
|
|
47
|
+
- `customStyles: string`
|
|
48
|
+
- *Used only with `compile()`.*
|
|
49
|
+
- Custom CSS styles to add to the wiki pages.
|
|
50
|
+
- Default: empty (`''`).
|
|
51
|
+
|
|
52
|
+
#### Example
|
|
41
53
|
|
|
42
54
|
```js
|
|
43
55
|
const wikity = require('wikity');
|
|
@@ -49,20 +61,35 @@ wikity.compile();
|
|
|
49
61
|
let html = wikity.parse(`'''bold''' [[link|text]]`); // <b>bold</b> <a href="link"...>text</a>
|
|
50
62
|
```
|
|
51
63
|
|
|
52
|
-
|
|
64
|
+
#### As an Eleventy plugin
|
|
65
|
+
|
|
66
|
+
Use Wikity along with Eleventy to have all your wiki files compiled during the build process:
|
|
53
67
|
|
|
54
68
|
```js
|
|
55
69
|
// .eleventy.js (eleventy's configuration file)
|
|
56
70
|
const wikity = require('wikity');
|
|
57
71
|
module.exports = function (eleventyConfig) {
|
|
58
|
-
const wikiFolder = '
|
|
59
|
-
const
|
|
60
|
-
const
|
|
72
|
+
const wikiFolder = 'src';
|
|
73
|
+
const templatesFolder = 'templates', imagesFolder = 'images', outputFolder = 'wikity-out'; // defaults
|
|
74
|
+
const wikityOptions = { templatesFolder, imagesFolder, outputFolder };
|
|
75
|
+
const wikityPlugin = () => wikity.compile(wikiFolder, { eleventy: true, ...wikityOptions });
|
|
61
76
|
eleventyConfig.addPlugin(wikityPlugin);
|
|
62
77
|
eleventyConfig.addPassthroughCopy({[imagesFolder]: 'wiki/' + imagesFolder}); // Eleventy does not pass through images by default
|
|
63
78
|
}
|
|
64
79
|
```
|
|
65
80
|
|
|
81
|
+
The above will use the following file structure (with some example wiki files given):
|
|
82
|
+
|
|
83
|
+
- `src/`
|
|
84
|
+
- `templates/`: Directory for wiki templates (called like `{{this}}`)
|
|
85
|
+
- `images/`: Directory to place images (called like `[[File:this]]`)
|
|
86
|
+
- `wikity-out/`: File templates compiled from the `.wiki` files (add this to `.gitignore`)
|
|
87
|
+
- `Index.wiki`: Example file
|
|
88
|
+
- `Other_Page.wiki`: Example other file
|
|
89
|
+
- `wiki/`: Output HTML files compiled from wikity-out (add this to `.gitignore`)
|
|
90
|
+
|
|
91
|
+
(View the above starting at the URL path `/wiki/` when ran in an HTTP server.)
|
|
92
|
+
|
|
66
93
|
### Command-line
|
|
67
94
|
```cmd
|
|
68
95
|
$ wikity help
|
|
@@ -81,6 +108,7 @@ Use [Wikitext](https://en.wikipedia.org/wiki/Help:Wikitext) (file extension `.wi
|
|
|
81
108
|
|
|
82
109
|
Any wiki templates (called using `{{template name}}`) must be inside the `templates/` folder by default.
|
|
83
110
|
Any files must be inside the `images/` folder by default.
|
|
111
|
+
Your wikitext (`*.wiki`) files go in the root directory by default.
|
|
84
112
|
|
|
85
113
|
### Wiki markup
|
|
86
114
|
|
package/src/cli.d.ts
DELETED
package/src/common.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare type Metadata = Record<string, any>;
|
|
2
|
-
export declare type Config = {
|
|
3
|
-
outputFolder?: string;
|
|
4
|
-
eleventy?: boolean;
|
|
5
|
-
defaultStyles?: boolean;
|
|
6
|
-
customStyles?: string;
|
|
7
|
-
templatesFolder?: string;
|
|
8
|
-
imagesFolder?: string;
|
|
9
|
-
};
|
|
10
|
-
export declare class Result extends String {
|
|
11
|
-
metadata: Metadata;
|
|
12
|
-
constructor(str: string);
|
|
13
|
-
}
|
|
14
|
-
export declare function RegExpBuilder(regex: string, flag?: string): RegExp;
|
|
15
|
-
export declare const VERSION = "1.3.0";
|
package/src/common.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VERSION = exports.RegExpBuilder = exports.Result = void 0;
|
|
4
|
-
class Result extends String {
|
|
5
|
-
constructor(str) {
|
|
6
|
-
super(str);
|
|
7
|
-
this.metadata = {};
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.Result = Result;
|
|
11
|
-
function RegExpBuilder(regex, flag = 'mgi') {
|
|
12
|
-
return RegExp(regex.replace(/ /g, '').replace(/\|\|.+?\|\|/g, ''), flag);
|
|
13
|
-
}
|
|
14
|
-
exports.RegExpBuilder = RegExpBuilder;
|
|
15
|
-
exports.VERSION = '1.3.0';
|
package/src/compile.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compile = exports.eleventyCompile = void 0;
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const glob = require('glob');
|
|
6
|
-
const dedent = require('dedent');
|
|
7
|
-
const formatter = require('html-formatter');
|
|
8
|
-
const parse_1 = require("./parse");
|
|
9
|
-
const common_1 = require("./common");
|
|
10
|
-
const r = String.raw;
|
|
11
|
-
function eleventyCompile(dir = '.', config = {}) {
|
|
12
|
-
compile(dir, { eleventy: true, ...config });
|
|
13
|
-
}
|
|
14
|
-
exports.eleventyCompile = eleventyCompile;
|
|
15
|
-
function compile(dir = '.', config = {}) {
|
|
16
|
-
let stylesCreated = false;
|
|
17
|
-
// Write wikitext files
|
|
18
|
-
const files = glob.sync((dir || '.') + "/**/*.wiki", {});
|
|
19
|
-
files.forEach((file) => {
|
|
20
|
-
var _a;
|
|
21
|
-
let data = fs.readFileSync(file, { encoding: 'utf8' });
|
|
22
|
-
let content = parse_1.parse(data, config);
|
|
23
|
-
let outText = content.toString();
|
|
24
|
-
const templatesFolder = config.templatesFolder || 'templates';
|
|
25
|
-
const imagesFolder = config.imagesFolder || 'images';
|
|
26
|
-
let [, folder, filename] = file.match(common_1.RegExpBuilder(r `^(.+?[\/\\]) ((?:(?:${templatesFolder}|${imagesFolder})[\/\\])?[^\/\\]+)$`, '')) || [];
|
|
27
|
-
let outFolder = (dir || folder || '.') + '/' + (config.outputFolder || 'wikity-out') + '/';
|
|
28
|
-
let outFilename = filename.replace(/ /g, '_').replace('.wiki', '.html');
|
|
29
|
-
let url = outFilename.replace(/(?<=^|\/)\w/g, m => m.toUpperCase());
|
|
30
|
-
let displayTitle = content.metadata.displayTitle || url.replace('.html', '');
|
|
31
|
-
// Eleventy configuration
|
|
32
|
-
let frontMatter = '';
|
|
33
|
-
if (config.eleventy) {
|
|
34
|
-
frontMatter = dedent `
|
|
35
|
-
---
|
|
36
|
-
permalink: /wiki/${url}
|
|
37
|
-
---
|
|
38
|
-
`;
|
|
39
|
-
}
|
|
40
|
-
// Create HTML
|
|
41
|
-
let toc = '';
|
|
42
|
-
if (!content.metadata.notoc && (content.metadata.toc || (((_a = outText.match(/<h\d[^>]*>/g)) === null || _a === void 0 ? void 0 : _a.length) || 0) > 3)) {
|
|
43
|
-
let headings = Array.from(content.match(/<h\d[^>]*>.+?<\/h\d>/gs) || []);
|
|
44
|
-
headings.forEach(match => {
|
|
45
|
-
var _a;
|
|
46
|
-
const text = match.replace(/\s*<\/?h\d[^>]*>\s*/g, '');
|
|
47
|
-
const lvl = +(((_a = match.match(/\d/g)) === null || _a === void 0 ? void 0 : _a[0]) || -1);
|
|
48
|
-
toc += `${`<ol>`.repeat(lvl - 1)} <li> <a href="#${encodeURI(text.replace(/ /g, '_'))}">${text}</a> </li> ${`</ol>`.repeat(lvl - 1)}`;
|
|
49
|
-
});
|
|
50
|
-
toc = dedent `
|
|
51
|
-
<div id="toc">
|
|
52
|
-
<span id="toc-heading">
|
|
53
|
-
<strong>Contents</strong>
|
|
54
|
-
[<a href="javascript:void(0)" onclick="
|
|
55
|
-
document.querySelector('#toc ol').setAttribute('style', this.innerText === 'hide' ? 'display: none;' : '');
|
|
56
|
-
this.innerText = this.innerText === 'hide' ? 'show' : 'hide';
|
|
57
|
-
">hide</a>]
|
|
58
|
-
</span>
|
|
59
|
-
<ol>${toc}</ol>
|
|
60
|
-
</div>
|
|
61
|
-
`;
|
|
62
|
-
if (outText.includes('<toc></toc>'))
|
|
63
|
-
outText = outText.replace('<toc></toc>', toc);
|
|
64
|
-
else
|
|
65
|
-
outText = outText.replace(/<h\d[^>]*>/, toc + '$&');
|
|
66
|
-
}
|
|
67
|
-
let html = dedent `
|
|
68
|
-
<html>
|
|
69
|
-
<head>
|
|
70
|
-
<meta charset="utf-8">
|
|
71
|
-
<meta name="viewport" content="initial-scale=1.0, width=device-width">
|
|
72
|
-
<meta name="description" content="${data.substr(0, 256)}">
|
|
73
|
-
<title>${displayTitle}</title>
|
|
74
|
-
<link id="default-styles" rel="stylesheet" href="/wiki.css">
|
|
75
|
-
</head>
|
|
76
|
-
<body>
|
|
77
|
-
<header>
|
|
78
|
-
<h1 id="page-title">${displayTitle}</h1>
|
|
79
|
-
</header>
|
|
80
|
-
<main>
|
|
81
|
-
<p>\n${outText}
|
|
82
|
-
</p>
|
|
83
|
-
</main>
|
|
84
|
-
<footer>
|
|
85
|
-
<p id="credit_wikity">Created using <a href="https://github.com/Nixinova/Wikity">Wikity</a></p>
|
|
86
|
-
</footer>
|
|
87
|
-
</body>
|
|
88
|
-
</html>
|
|
89
|
-
`;
|
|
90
|
-
// Write to file
|
|
91
|
-
['', templatesFolder, imagesFolder].forEach((path) => {
|
|
92
|
-
if (!fs.existsSync(outFolder + path))
|
|
93
|
-
fs.mkdirSync(outFolder + path);
|
|
94
|
-
});
|
|
95
|
-
let renderedHtml = formatter.render(html).replace(/(<\/\w+>)(\S)/g, '$1 $2');
|
|
96
|
-
fs.writeFileSync(outFolder + outFilename, frontMatter + '\n' + renderedHtml, 'utf8');
|
|
97
|
-
// Move images
|
|
98
|
-
glob(imagesFolder + '/*', {}, (err, files) => {
|
|
99
|
-
if (err)
|
|
100
|
-
console.warn(err);
|
|
101
|
-
const outImagesFolder = outFolder + imagesFolder + '/';
|
|
102
|
-
if (!fs.existsSync(outImagesFolder))
|
|
103
|
-
fs.mkdirSync(outImagesFolder);
|
|
104
|
-
files.forEach((file) => fs.copyFileSync(file, outImagesFolder + file.split(/[/\\]/).pop()));
|
|
105
|
-
});
|
|
106
|
-
// Create site styles
|
|
107
|
-
if (!stylesCreated) {
|
|
108
|
-
stylesCreated = true;
|
|
109
|
-
let styles = '';
|
|
110
|
-
if (config.defaultStyles !== false) {
|
|
111
|
-
styles = dedent `
|
|
112
|
-
body {font-family: sans-serif; margin: 4em; max-width: 1000px; background: #eee;}
|
|
113
|
-
main {margin: 3em -1em; background: #fff; padding: 1em;}
|
|
114
|
-
h1, h2 {margin-bottom: 0.6em; font-weight: normal; border-bottom: 1px solid #a2a9b1;}
|
|
115
|
-
ul, ol {margin: 0.3em 0 0 1.6em; padding: 0;}
|
|
116
|
-
dt {font-weight: bold;}
|
|
117
|
-
dd, dl dl {margin-block: 0; margin-inline-start: 30px;}
|
|
118
|
-
|
|
119
|
-
figure {margin: 1em;}
|
|
120
|
-
.image-thumb, .image-frame {padding: 6px; border: 1px solid gray;}
|
|
121
|
-
figcaption {padding-top: 6px;}
|
|
122
|
-
|
|
123
|
-
table.wikitable {border-collapse: collapse;}
|
|
124
|
-
table.wikitable, table.wikitable th, table.wikitable td {border: 1px solid gray; padding: 6px;}
|
|
125
|
-
table.wikitable th {background-color: #eaecf0; text-align: center;}
|
|
126
|
-
|
|
127
|
-
a:not(:hover) {text-decoration: none;}
|
|
128
|
-
a.internal-link {color: #04a;}
|
|
129
|
-
a.internal-link:visited {color: #26d;}
|
|
130
|
-
a.external-link {color: #36b;}
|
|
131
|
-
a.external-link:visited {color: #58d;}
|
|
132
|
-
a.external-link::after {content: '\1f855';}
|
|
133
|
-
a.redlink {color: #d33;}
|
|
134
|
-
a.redlink:visited {color: #b44;}
|
|
135
|
-
|
|
136
|
-
#toc {display: inline-block; border: 1px solid #aab; padding: 8px; background-color: #f8f8f8; font-size: 95%;}
|
|
137
|
-
#toc-heading {display: block; text-align: center;}
|
|
138
|
-
#toc ol {margin: 0 0 0 1.3em;}
|
|
139
|
-
`;
|
|
140
|
-
}
|
|
141
|
-
if (config.customStyles)
|
|
142
|
-
styles += config.customStyles;
|
|
143
|
-
let cssOutput = dedent `
|
|
144
|
-
---
|
|
145
|
-
permalink: /wiki.css
|
|
146
|
-
---
|
|
147
|
-
${styles}
|
|
148
|
-
`;
|
|
149
|
-
fs.writeFileSync(outFolder + 'wiki.css.njk', cssOutput);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
exports.compile = compile;
|