\n${outText} 105 |
106 |├── .gitattributes ├── .gitignore ├── bin └── index.js ├── changelog.md ├── example ├── .eleventy.js ├── .gitignore ├── package.json └── src │ ├── Index.wiki │ ├── images │ └── diamond.png │ └── templates │ └── Header.wiki ├── license.md ├── package-lock.json ├── package.json ├── readme.md ├── src ├── cli.ts ├── common.ts ├── compile.ts ├── index.ts ├── parse.ts └── wiki.css.ts ├── test ├── .eleventy.js └── src │ ├── example.wiki │ ├── images │ └── Example.png │ └── templates │ ├── plain.wiki │ └── subst.wiki └── tsconfig.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # General 2 | * text=auto 3 | 4 | # Module CSS 5 | *.css.* linguist-language=CSS 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | node_modules/ 3 | 4 | # Site output 5 | _site/ 6 | wikity-out/ 7 | 8 | # Compiled source 9 | dist/ 10 | -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('../dist/cli.js'); 3 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.3.6 4 | *2024-11-14* 5 | - Changed TOC generation to only include wikitext headings. 6 | - Fixed TOC being misplaced when non-wikitext headings are on the page. 7 | - Fixed TOC styling. 8 | - Fixed spacing issues in output such as in metadata and cite notes. 9 | - Fixed layout issues with non-`thumb` images. 10 | 11 | ## 1.3.5 12 | *2024-05-12* 13 | - Changed output to no longer be prettified. 14 | - Fixed spacing issues resulting from output prettification. 15 | - Fixed a crash occurring when invalid dates are given to `#time`. 16 | - Fixed links in image captions breaking the output. 17 | - Fixed underscores appearing in the default page title when present in the URL. 18 | - Fixed links not being automatically capitalised. 19 | - Fixed named references not working. 20 | - Fixed template calls inside table cells breaking the table. 21 | - Fixed headings not working when containing formatting. 22 | - Fixed all index numbers in the TOC being '1'. 23 | - Fixed images being deformed to 300x300px by default. 24 | 25 | ## 1.3.4 26 | *2024-05-18* 27 | - Added support for video embeds: currently only supports `{{#ev:youtube}}` and `{{#ev:vimeo}}`. 28 | - Added support for named references. 29 | - Added styling for infoboxes (`#infobox`). 30 | - Changed images to be displayed inline by default when no float is given. 31 | - Fixed a crash occurring when attempting to apply custom styles. 32 | - Fixed a crash occurring when a template goes unparsed. 33 | - Fixed unused parameters being substituted with random numbers instead of their default values. 34 | - Fixed templates not being trimmed before being substituted. 35 | - Fixed lists not outputting properly when a parser function is used on the line. 36 | - Fixed tables not allowing attributes syntax. 37 | - Fixed files and links becoming broken when parameters are inside them. 38 | - Fixed images being erroneously parsed as regular links. 39 | - Fixed internal links sometimes having wrong targets. 40 | - Fixed the TOC being inline in the default styles. 41 | - Fixed CSS selector for TOC heading not being specific enough. 42 | 43 | ## 1.3.3 44 | *2024-05-08* 45 | - Fixed characters around elements being erroneously padded with spaces. 46 | - Fixed inline definition lists not being parsed. 47 | - Fixed equal signs in named template arguments creating broken output. 48 | - Fixed piped links in template arguments creating broken output. 49 | 50 | ## 1.3.2 51 | *2024-05-08* 52 | - Fixed `nowiki` content not being fully unparsed. 53 | - Fixed output files not having the correct path to the default stylesheet. 54 | - Fixed URLs in output files being absolute. 55 | - Fixed various issues with incorrect outputted file names. 56 | - Fixed `||` not being treated as valid table cell syntax. 57 | - Fixed front matter being generated even when config option `eleventy` was set to `false`. 58 | - Fixed defaults not being used when `compile` called from CLI. 59 | - Unmarked Eleventy as a peer dependency. 60 | 61 | ## 1.3.1 62 | *2024-05-03* 63 | - Allowed support for Eleventy >1.0.0. 64 | - Fixed crash occurring when compiling images with no parameters. 65 | - Fixed default template arguments not being parsed. 66 | - Fixed output description metadata property being malformed. 67 | 68 | ## 1.3.0 69 | *2021-05-16* 70 | - Added configuration option `imagesFolder` to configure the folder that images are placed in. 71 | - Added support for images using the `[[File:Image.png|options|caption]]` syntax. 72 | - Added `class="wikitable"` table styling. 73 | - Fixed a crash occurring when the templates folder did not exist when compiling. 74 | 75 | ## 1.2.1 76 | *2021-04-02* 77 | - Added previously-unimplemented `config` option to `parse()` to configure the `templatesFolder`. 78 | - Changed table of contents to not require default styling to collapse. 79 | - Fixed internal links being incorrectly root-relative. 80 | - Fixed templates output folder not being created on initialisation. 81 | - Fixed unset arguments not being removed from the output. 82 | 83 | ## 1.2.0 84 | *2021-04-01* 85 | - Added function `eleventyPlugin()` for use with Eleventy's `addPlugin` method. 86 | - Added configuration option `outputFolder` to configure the folder the compiled HTML files are placed in. 87 | - Added configuration option `templatesFolder` to configure the folder templates are placed in. 88 | - Added CLI options `--outputFolder`, `--templatesFolder`, `--eleventy`, and `--defaultStyles` to change configuration options. 89 | - Added support for tables. 90 | - Added a warning when the parser detects non-repetition-based `#time` function syntax is being used. 91 | 92 | ## 1.1.0 93 | *2021-03-28* 94 | - Added `parse` CLI command to implement `parse()`. 95 | - Added a generated table of contents if there are over 4 headings. 96 | - Added support for `nowiki` tag. 97 | - Added support for `onlyinclude`, `includeonly`, and `noinclude` tags in templates. 98 | - Added support for magic words `__TOC__`, `__FORCETOC__`, `__NOTOC__`, and `__NOINDEX__`. 99 | - Added support for control function `{{displaytitle:}}` to control the page's displayed title. 100 | - Added support for string functions `lc:`, `uc:`, `lcfirst:`, `ucfirst:`, `replace:`, `explode:`, `sub:`, `len:`, `pos:`, `padleft:`, `padright:`, `urlencode:`, and `urldecode:`. 101 | - Added support for horizontal rules using `----`. 102 | - Changed time codes in `#datetime`/`#date`/`#time` function to be based on reduplication instead of unique characters with escaping based on quoting instead of prefixing with a backslash (i.e., `{{#time: j F Y (\n\o\w)}}` → `{{#time: dd mmm yyyy "(now)"}}`). 103 | - Fixed inline tags removing whitespace from either end. 104 | - Fixed single-line-only syntax not being parsed correctly. 105 | 106 | ## 1.0.1 107 | *2021-03-28* 108 | - Changed HTML output to be prettified. 109 | - Fixed arguments not being substituted properly. 110 | - Fixed nested templates and parser functions not being substituted properly. 111 | - Fixed templates and parser functions spread out across multiple lines not being parsed. 112 | 113 | ## 1.0.0 114 | *2021-03-27* 115 | - Added `compile()` function and CLI command to compile wikitext into HTML. 116 | - Added `parse()` function to parse raw wikitext input. 117 | -------------------------------------------------------------------------------- /example/.eleventy.js: -------------------------------------------------------------------------------- 1 | const wikity = require('wikity'); 2 | 3 | module.exports = function (eleventyConfig) { 4 | const wikityOptions = { 5 | eleventy: true, 6 | templatesFolder: 'templates', 7 | imagesFolder: 'images', 8 | outputFolder: 'wikity-out/', 9 | }; 10 | const wikityPlugin = () => wikity.compile('src', wikityOptions); 11 | eleventyConfig.addPlugin(wikityPlugin); 12 | eleventyConfig.addPassthroughCopy({ 'src/images': 'wiki/images' }); 13 | } 14 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | _site/ 3 | wikity-out/ 4 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my_wiki", 3 | "scripts": { 4 | "build": "eleventy", 5 | "dev": "eleventy --watch --serve" 6 | }, 7 | "dependencies": { 8 | "@11ty/eleventy": "^3.0.0", 9 | "wikity": "^1.3.5" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/src/Index.wiki: -------------------------------------------------------------------------------- 1 | {{Header}} 2 | 3 | = Index Page = 4 | 5 | Welcome to the [[File:diamond.png|10px]] wiki. 6 | -------------------------------------------------------------------------------- /example/src/images/diamond.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nixinova/Wikity/96b079b5701a58031a81d30b2552929f910fe0be/example/src/images/diamond.png -------------------------------------------------------------------------------- /example/src/templates/Header.wiki: -------------------------------------------------------------------------------- 1 |
code block| 127 | | `=heading=` | heading | 128 | | `==subheading==` | subheading | 129 | | `*bulleted` |
\n${outText} 105 |
106 |Failed to load video ${id} from ${platform}.
`;
220 | return `
221 |
232 | ${description ? `$1') 390 | .replace(re(r` \`\` ([^\`]+?) \`\` `), '
$1
')
391 |
392 | // Spacing
393 | .replace(/(\r?\n){2}/g, '\n\n')
394 |
395 | }
396 |
397 | // Final (one-time) substitutions
398 |
399 | for (let i = 0; i < nowikis.length; i++) {
400 | outText = outText
401 | // Restore nowiki contents
402 | .replace(escaper('NOWIKI', i), nowikis[i])
403 | }
404 | outText = outText
405 | // References: ${references}
`;
424 | })
425 | // Magic word functions
426 | .replaceAll(escaper('VERT'), '|')
427 | .replaceAll(escaper('EQUALS'), '=')
428 |
429 | // Escape all {{ to avoid crashes
430 | outText = outText
431 | .replaceAll('{{', '{{')
432 |
433 | const result: Result = { data: outText, metadata: metadata };
434 | return result;
435 | }
436 |
--------------------------------------------------------------------------------
/src/wiki.css.ts:
--------------------------------------------------------------------------------
1 | export default String.raw`
2 | body {font-family: sans-serif; margin: auto; max-width: 1000px; background: #eee;}
3 | main {margin: 3em -1em; background: #fff; padding: 1em;}
4 | h1, h2 {margin-bottom: 0.6em; font-weight: normal; border-bottom: 1px solid #a2a9b1;}
5 | ul, ol {margin: 0.3em 0 0 1.6em; padding: 0;}
6 | dt {font-weight: bold;}
7 | dd, dl dl {margin-block: 0; margin-inline-start: 30px;}
8 |
9 | figure {margin: 1em; width: 300px;}
10 | .image-thumb, .image-frame {padding: 6px; border: 1px solid gray;}
11 | .image-default {margin: 0;}
12 | figcaption {padding-top: 6px;}
13 |
14 | table.wikitable {border-collapse: collapse;}
15 | table.wikitable, table.wikitable th, table.wikitable td {border: 1px solid gray; padding: 6px;}
16 | table.wikitable th {background-color: #eaecf0; text-align: center;}
17 |
18 | a:not(:hover) {text-decoration: none;}
19 | a.internal-link {color: #04a;}
20 | a.internal-link:visited {color: #26d;}
21 | a.external-link {color: #36b;}
22 | a.external-link:visited {color: #58d;}
23 | a.external-link::after {content: '\1f855';}
24 | a.redlink {color: #d33;}
25 | a.redlink:visited {color: #b44;}
26 |
27 | #page_toc {border: 1px solid #aab; padding: 8px; width: fit-content; background-color: #f8f8f8; font-size: 95%;}
28 | #page_toc_heading {display: block; text-align: center;}
29 | #page_toc ol {margin: 0 0 0 1.3em;}
30 |
31 | #infobox {float: right; clear: right; margin: 0 0 1em 1em; width: 300px; padding: 2px; border: 1px solid #CCC; overflow: auto; font-size: 90%;}
32 | #infobox tr:first-child :first-child {padding: 10px; text-align: center; font-weight: bold; font-size: 120%;}
33 | #infobox th {padding-left: 10px; text-align: left;}
34 | `
35 |
--------------------------------------------------------------------------------
/test/.eleventy.js:
--------------------------------------------------------------------------------
1 | const wikity = require('../dist/index.js')
2 |
3 | module.exports = function (eleventyConfig) {
4 | const rootFolder = 'src';
5 | const options = { eleventy: true };
6 | eleventyConfig.addPlugin(() => wikity.compile(rootFolder, options));
7 | eleventyConfig.addPassthroughCopy({ [`${rootFolder}/images/`]: 'wiki/images' });
8 | }
9 |
--------------------------------------------------------------------------------
/test/src/example.wiki:
--------------------------------------------------------------------------------
1 | {{displaytitle: Example Page}}
2 | Example
3 | '''Wikity''' is a ''very'' useful build tool!
4 |
5 | Code
105 | =
must match.
146 | * {{#lc:TEXT}} = text
147 | * {{#ucfirst:text}} = Text
148 | * {{#len:12345}} = 5
149 | * {{#sub:string|2|4}} = ring
150 | * {{#pos:text|x}} = 2
151 | * {{#padleft:text|5|_}} = _text
152 | * {{#padright:msg|5|_}} = msg__
153 | * {{#replace:Message|e|3}} = M3ssag3
154 | * {{#explode:A-B-C-D|-|2}} = C
155 | * {{#urlencode:t e x t}} = t%20e%20x%20t
156 | * {{#urldecode:a%20b%27c}} = a b'c
157 | →
must match.
170 | * {{#if: true | true text | false text }} → true text
171 | * {{#if: {{{variable|}}} | true text | false text }} → false text
172 | * {{#if: {{{image|}}}
173 | | Image: [[File:{{{image|}}}|48px|link={{{link|}}}]]
174 | | None
175 | }} = None
176 | * {{#if: {{{image|Example.png}}}
177 | | Image: [[File:{{{image|Example.png}}}|48px|link={{{link|}}}]]
178 | | None
179 | }} = [Example.png]
180 | * {{ #vardefine: test | value }} → (empty: variable defined)
181 | * [[{{ #var:test }}]] → [[value]]
182 | * "{{#var: unset | this {{=}} unset }}" → "this = unset"
183 | * {{#switch: value
184 | | nope = none
185 | | val = val!
186 | | #default = one
187 | }} → one
188 | * {{#date: yyyy-mm-dd (ddd) 'm' | 27 Mar 21}} → [today's date] m
189 | * {{#vardefine: nested | {{#var: null | nil}} {{#vardefine: x | 1}} {{=}}.}} → (empty: variable defined)
190 | * {{#var: nested}} → nil =.
191 |