From a15b4b7a670b3096d09c6fc2c0e8c77e47707562 Mon Sep 17 00:00:00 2001 From: LiteHell Date: Fri, 16 Feb 2018 17:33:13 +0900 Subject: [PATCH] Added some grammars * works like shit. --- .vscode/launch.json | 2 +- basicHTMLRenderer.js | 13 ++++++ processors/linkProcessor.js | 1 + processors/renderProcessor.js | 77 ++++++++++++++++++++++++++++++++++- 4 files changed, 91 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8ace34e..9eb5cb2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "type": "node", "request": "launch", "name": "Launch Program", - "program": "${workspaceRoot}\\test\\app.js" + "program": "${workspaceRoot}/test/app.js" } ] } \ No newline at end of file diff --git a/basicHTMLRenderer.js b/basicHTMLRenderer.js index b93b6a9..f37e44f 100644 --- a/basicHTMLRenderer.js +++ b/basicHTMLRenderer.js @@ -294,6 +294,19 @@ function HTMLRenderer(_options) { break; case 'paragraph-end': appendResult('

'); + break; + case 'wiki-box-start': + appendResult('
'); + break; + case 'wiki-box-end': + appendResult('
'); + break; + case 'folding-start': + appendResult('
' + encodeHTMLComponent(i.summary) + ''); + break; + case 'folding-end': + appendResult('
'); + break; } } function finalLoop(callback) { diff --git a/processors/linkProcessor.js b/processors/linkProcessor.js index 6752b89..3d54b8c 100644 --- a/processors/linkProcessor.js +++ b/processors/linkProcessor.js @@ -17,6 +17,7 @@ module.exports = (text, type, configs) => { if (!configs.included) return [{ name: "add-category", + blur: href[0].endsWith('#blur'), categoryName: category }]; } else if (/^파일:(.+)$/.test(href[0])) { diff --git a/processors/renderProcessor.js b/processors/renderProcessor.js index 19360d4..25f557f 100644 --- a/processors/renderProcessor.js +++ b/processors/renderProcessor.js @@ -4,7 +4,82 @@ module.exports = (text, type) => { name: "unsafe-plain", text: text.substring(6) }]; - } + } else if (/^#!folding/i.test(text) && text.indexOf('\n') >= 10) { + return [{ + name: "folding-start", + summary: text.substring(10, text.indexOf('\n')) + }, { + name: "wikitext", + treatAsBlock: true, + text: text.substring(text.indexOf('\n') + 1) + }, + { + name: "folding-end" + } + ]; + } else if (/^#!syntax/i.test(text) && text.indexOf('\n') >= 9) { + return [{ + name: "syntax-highlighting", + header: text.substring(9, text.indexOf('\n')), + body: text.substring(text.indexOf('\n') + 1) + }]; + } else if (/^#!wiki/i.test(text)) { + if (text.indexOf('\n') >= 7) { + let params = text.substring(7, text.indexOf('\n')); + if (params.startsWith("style=\"") && /" +$/.test(params)) { + return [{ + name: "wiki-box-start", + style: params.substring(7, params.length - /" +$/.exec(params)[0].length) + }, { + name: "wikitext", + treatAsBlock: true, + text: text.substring(text.indexOf('\n') + 1) + }, { + name: "wiki-box-end" + }] + } else { + return [{ + name: "wiki-box-start" + }, { + name: "wikitext", + treatAsBlock: true, + text: text.substring(text.indexOf('\n') + 1) + }, { + name: "wiki-box-end" + }] + + } + } + } else if (/^#([A-Fa-f0-9]{3,6}) (.*)$/.test(text)) { + let matches = /^#([A-Fa-f0-9]{3,6}) (.*)$/.exec(text); + if (matches[1].length === 0 && matches[2].length === 0) + return [{ + name: "plain", + text: text + }]; + return [{ + name: "font-color-start", + color: matches[1] + }, { + name: "wikitext", + parseFormat: true, + text: matches[2] + }, { + name: "font-color-end" + }]; + } else if (/^\+([1-5]) (.*)$/.test(text)) { + let matches = /^\+([1-5]) (.*)$/.exec(text); + return [{ + name: "font-size-start", + level: matches[1] + }, { + name: "wikitext", + parseFormat: true, + text: matches[2] + }, { + name: "font-size-end" + }]; + }; return [{ name: "monoscape-font-start", pre: true