From 3eca924a7c3fbf33773d326f1ec1020b90f41d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 9 Jul 2018 01:30:51 -0400 Subject: [PATCH] Make the MOTDs a little nicer if possible This removes the leading hyphens from MOTD lines (under the condition they all do) and trims empty lines around the MOTD (but not inside). --- client/js/render.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/client/js/render.js b/client/js/render.js index 461ef074..3fd6cec6 100644 --- a/client/js/render.js +++ b/client/js/render.js @@ -101,6 +101,20 @@ function buildChatMessage(msg) { template = "msg_unhandled"; } + // Make the MOTDs a little nicer if possible + if (msg.type === "motd") { + let lines = msg.text.split("\n"); + + // If all non-empty lines of the MOTD start with a hyphen (which is common + // across MOTDs), remove all the leading hyphens. + if (lines.every((line) => line === "" || line[0] === "-")) { + lines = lines.map((line) => line.substr(2)); + } + + // Remove empty lines around the MOTD (but not within it) + msg.text = lines.join("\n").trim(); + } + const renderedMessage = $(templates[template](msg)); const content = renderedMessage.find(".content");