wikity 1.3.2 → 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/compile.js CHANGED
@@ -106,7 +106,7 @@ function compile(dir = '.', config = {}) {
106
106
  if (!fs_1.default.existsSync(path_1.default.dirname(outFilePath))) {
107
107
  fs_1.default.mkdirSync(path_1.default.dirname(outFilePath));
108
108
  }
109
- const renderedHtml = formatter.render(html).replace(/(<\/\w+>)(\S)/g, '$1 $2');
109
+ const renderedHtml = formatter.render(html.replace(/(<\/\w+>) +(\S)/g, '$1&#32;$2'));
110
110
  fs_1.default.writeFileSync(outFilePath, frontMatter + '\n' + renderedHtml, 'utf8');
111
111
  // Move images
112
112
  (0, glob_1.default)(imagesFolder + '/*', {}, (err, files) => {
package/dist/parse.js CHANGED
@@ -33,13 +33,14 @@ function parse(data, config = {}) {
33
33
  let rawExtLinkCount = 0;
34
34
  let refCount = 0;
35
35
  let outText = data;
36
+ const escaper = (text, n) => `%${text}#${n}`;
36
37
  for (let l = 0, last = ''; l < MAX_RECURSION; l++) {
37
38
  if (last === outText)
38
39
  break;
39
40
  last = outText;
40
41
  outText = outText
41
42
  // Nowiki: <nowiki></nowiki>
42
- .replace((0, common_1.RegExpBuilder)(r `<nowiki> ([^]+?) </nowiki>`), (_, m) => `%NOWIKI#${nowikis.push(m), nowikiCount++}%`)
43
+ .replace((0, common_1.RegExpBuilder)(r `<nowiki> ([^]+?) </nowiki>`), (_, m) => (nowikis.push(m), escaper('NOWIKI', nowikiCount++)))
43
44
  // Sanitise unacceptable HTML
44
45
  .replace((0, common_1.RegExpBuilder)(r `<(/?) \s* (?= script|link|meta|iframe|frameset|object|embed|applet|form|input|button|textarea )`), '&lt;$1')
45
46
  .replace((0, common_1.RegExpBuilder)(r `(?<= <[^>]+ ) (\bon(\w+))`), 'data-$2')
@@ -47,16 +48,22 @@ function parse(data, config = {}) {
47
48
  .replace(/<!--[^]+?-->/g, '')
48
49
  // Lines: ----
49
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/>')
50
61
  // Metadata: displayTitle, __NOTOC__, etc
51
62
  .replace((0, common_1.RegExpBuilder)(r `{{ \s* displayTitle: ([^}]+) }}`), (_, title) => (metadata.displayTitle = title, ''))
52
63
  .replace((0, common_1.RegExpBuilder)(r `__NOINDEX__`), () => (metadata.noindex = true, ''))
53
64
  .replace((0, common_1.RegExpBuilder)(r `__NOTOC__`), () => (metadata.notoc = true, ''))
54
65
  .replace((0, common_1.RegExpBuilder)(r `__FORCETOC__`), () => (metadata.toc = true, ''))
55
66
  .replace((0, common_1.RegExpBuilder)(r `__TOC__`), () => (metadata.toc = true, `<toc></toc>`))
56
- // Magic words: {{!}}, {{reflist}}, etc
57
- .replace((0, common_1.RegExpBuilder)(r `{{ \s* ! \s* }}`), '&vert;')
58
- .replace((0, common_1.RegExpBuilder)(r `{{ \s* = \s* }}`), '&equals;')
59
- .replace((0, common_1.RegExpBuilder)(r `{{ \s* [Rr]eflist \s* }}`), '<references/>')
60
67
  // String functions: {{lc:}}, {{ucfirst:}}, {{len:}}, etc
61
68
  .replace((0, common_1.RegExpBuilder)(r `{{ \s* #? urlencode: ${arg} }}`), (_, m) => encodeURI(m))
62
69
  .replace((0, common_1.RegExpBuilder)(r `{{ \s* #? urldecode: ${arg} }}`), (_, m) => decodeURI(m))
@@ -128,7 +135,7 @@ function parse(data, config = {}) {
128
135
  for (let i = 1; i < args.length; i++) {
129
136
  const parts = args[i].split('=');
130
137
  const [arg, val] = parts[1]
131
- ? [parts[0], ...parts.slice(1)]
138
+ ? [parts[0], parts.slice(1).join('=')]
132
139
  : [i.toString(), parts[0]];
133
140
  content = content.replace(argMatch(arg), (_, defaultVal) => val || defaultVal || '');
134
141
  }
@@ -224,12 +231,6 @@ function parse(data, config = {}) {
224
231
  .replace((0, common_1.RegExpBuilder)(r `'' ([^']+?) ''`), '<i>$1</i>')
225
232
  // Headings: ==heading==
226
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}>`)
227
- // Internal links: [[Page]] and [[Page|Text]]
228
- .replace((0, common_1.RegExpBuilder)(r `\[\[ ([^\]|]+?) \]\]`), `<a class="internal-link" title="$1" href="$1">$1</a>`)
229
- .replace((0, common_1.RegExpBuilder)(r `\[\[ ([^\]|]+?) \| ([^\]]+?) \]\]`), `<a class="internal-link" title="$1" href="/$1">$2</a>`)
230
- .replace((0, common_1.RegExpBuilder)(r `(</a>)([a-z]+)`), '$2$1')
231
- // External links: [href Page] and just [href]
232
- .replace((0, common_1.RegExpBuilder)(r `\[ ((?:\w+:)?\/\/ [^\s\]]+) (\s [^\]]+?)? \]`), (_, href, txt) => `<a class="external-link" href="${href}">${txt || '[' + (++rawExtLinkCount) + ']'}</a>`)
233
234
  // Bulleted list: *item
234
235
  .replace((0, common_1.RegExpBuilder)(r `^ (\*+) (.+?) $`), (_, lvl, txt) => `${'<ul>'.repeat(lvl.length)}<li>${txt}</li>${'</ul>'.repeat(lvl.length)}`)
235
236
  .replace((0, common_1.RegExpBuilder)(r `</ul> (\s*?) <ul>`), '$1')
@@ -237,8 +238,9 @@ function parse(data, config = {}) {
237
238
  .replace((0, common_1.RegExpBuilder)(r `^ (#+) (.+?) $`), (_, lvl, txt) => `${'<ol>'.repeat(lvl.length)}<li>${txt}</li>${'</ol>'.repeat(lvl.length)}`)
238
239
  .replace((0, common_1.RegExpBuilder)(r `</ol> (\s*?) <ol>`), '$1')
239
240
  // Definition list: ;head, :item
240
- .replace((0, common_1.RegExpBuilder)(r `^ ; (.+) $`), '<dl><dt>$1</dt></dl>')
241
+ .replace((0, common_1.RegExpBuilder)(r `^ ; (.+?) : (.+?) $`), `<dl><dt>$1</td><dd>$2</dd></dl>`)
241
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>')
242
244
  .replace((0, common_1.RegExpBuilder)(r `</dl> (\s*?) <dl>`), '$1')
243
245
  // Tables: {|, |+, !, |-, |, |}
244
246
  .replace((0, common_1.RegExpBuilder)(r `^ \{\| (.*?) $`), (_, attrs) => `<table ${attrs}><tr>`)
@@ -261,10 +263,15 @@ function parse(data, config = {}) {
261
263
  // Spacing
262
264
  .replace(/(\r?\n){2}/g, '\n</p><p>\n');
263
265
  }
264
- // Final changes (run only once)
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]));
270
+ }
271
+ // Substitute magic word functions
265
272
  outText = outText
266
- // Restore nowiki contents
267
- .replace(/%NOWIKI#(\d+)%/g, (_, n) => fullyEscape(nowikis[n]));
273
+ .replaceAll(escaper('VERT', 0), '|')
274
+ .replaceAll(escaper('EQUALS', 0), '=');
268
275
  const result = { data: outText, metadata: metadata };
269
276
  return result;
270
277
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikity",
3
- "version": "1.3.2",
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": {