From 0945ede8d1ee6bdc0372a3cdcbe33e511b394f45 Mon Sep 17 00:00:00 2001 From: Brecert <11599528+Brecert@users.noreply.github.com> Date: Fri, 22 Feb 2019 15:00:59 -0600 Subject: [PATCH] added support for future syntax highlighting of code-blocks --- src/messageFormatter.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/messageFormatter.js b/src/messageFormatter.js index 0f99ecd..6bf619e 100644 --- a/src/messageFormatter.js +++ b/src/messageFormatter.js @@ -41,7 +41,7 @@ export default (message) => { name: 'code-block', symbol: '``\`', recursive: false, - transformer: text => `
${text.trim()}
`, + transformer: text => `
${formatCode(text.trim())}
`, }) futoji.addTransformer({ @@ -53,6 +53,26 @@ export default (message) => { return futoji.format(message); } +/** + * format code to add syntax highlighting + */ +function formatCode(text) { + // matches if word until newline + // if spaces then it won't match + let nameRegex = new RegExp('^(\\w+)\\n') + + if(nameRegex.test(text)) { + let language = nameRegex.exec(text)[1] + let newText = text.replace(nameRegex, '') + + // TODO: format newText with language + + return newText + } + + return text +} + function escapeHtml(unsafe) { return unsafe .replace(/&/g, "&")