From 6034891fed9d27ac8c572660b489805d933fdfc4 Mon Sep 17 00:00:00 2001 From: ubertao Date: Mon, 17 Sep 2018 00:51:37 +0800 Subject: [PATCH 1/5] Support multi-line compliments. --- modules/default/compliments/compliments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default/compliments/compliments.js b/modules/default/compliments/compliments.js index 74aef034..af3d6e34 100644 --- a/modules/default/compliments/compliments.js +++ b/modules/default/compliments/compliments.js @@ -160,7 +160,7 @@ Module.register("compliments", { var compliment = document.createTextNode(complimentText); var wrapper = document.createElement("div"); wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright"; - wrapper.appendChild(compliment); + wrapper.innerHTML = complimentText.replace(/\n/g, '
'); return wrapper; }, From 40725aa2a23c67719a347aa4b554069cbd436e29 Mon Sep 17 00:00:00 2001 From: ubertao Date: Mon, 17 Sep 2018 00:54:01 +0800 Subject: [PATCH 2/5] Update CHANGELOG.md with multi-line compliments support. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a976bec7..4afc38b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). *This release is scheduled to be released on 2018-10-01.* ### Added +- Support multi-line compliments - Simplified Chinese translation for "Feels" - Polish translate for "Feels" - French translate for "Feels" From cad7debc5be6054a06e8e168b7e6b6fa0df0832d Mon Sep 17 00:00:00 2001 From: ubertao Date: Thu, 20 Sep 2018 08:49:17 +0800 Subject: [PATCH 3/5] Replace innerHTML() with createElement() and appendChild() for security. --- modules/default/compliments/compliments.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/default/compliments/compliments.js b/modules/default/compliments/compliments.js index af3d6e34..43ef0e9e 100644 --- a/modules/default/compliments/compliments.js +++ b/modules/default/compliments/compliments.js @@ -157,10 +157,15 @@ Module.register("compliments", { getDom: function() { var complimentText = this.randomCompliment(); - var compliment = document.createTextNode(complimentText); var wrapper = document.createElement("div"); wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright"; - wrapper.innerHTML = complimentText.replace(/\n/g, '
'); + complimentText.split("\n").forEach(function(line, index) { + if (index > 0) { + wrapper.appendChild(document.createElement("br")); + } + wrapper.appendChild(document.createTextNode(line)); + + }); return wrapper; }, From d76c924ad11649959941b430c31fc0c35758a602 Mon Sep 17 00:00:00 2001 From: ubertao Date: Thu, 20 Sep 2018 09:09:06 +0800 Subject: [PATCH 4/5] Update compliments README.md for multi-line support. --- modules/default/compliments/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/default/compliments/README.md b/modules/default/compliments/README.md index 8f796888..7220cd29 100644 --- a/modules/default/compliments/README.md +++ b/modules/default/compliments/README.md @@ -107,6 +107,13 @@ config: { } ```` +#### Multi-line compliments: +Use `\n` to split compliment text into multiple lines, e.g. `First line.\nSecond line.` will be shown as: +``` +First line. +Second line. +``` + ### External Compliment File You may specify an external file that contains the three compliment arrays. This is particularly useful if you have a large number of compliments and do not wish to crowd your `config.js` file with a large array of compliments. From ba428c6cfe11f2a588edc9adbc673dbff342b104 Mon Sep 17 00:00:00 2001 From: ubertao Date: Mon, 24 Sep 2018 23:01:17 +0800 Subject: [PATCH 5/5] Use 'white-space: pre-line' for multi-line compliment. --- css/main.css | 4 ++++ modules/default/compliments/compliments.js | 11 +++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/css/main.css b/css/main.css index db1fb428..84f8c4d2 100644 --- a/css/main.css +++ b/css/main.css @@ -128,6 +128,10 @@ sup { text-overflow: ellipsis; } +.pre-line { + white-space: pre-line; +} + /** * Region Definitions. */ diff --git a/modules/default/compliments/compliments.js b/modules/default/compliments/compliments.js index 43ef0e9e..bfa85879 100644 --- a/modules/default/compliments/compliments.js +++ b/modules/default/compliments/compliments.js @@ -157,15 +157,10 @@ Module.register("compliments", { getDom: function() { var complimentText = this.randomCompliment(); + var compliment = document.createTextNode(complimentText); var wrapper = document.createElement("div"); - wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright"; - complimentText.split("\n").forEach(function(line, index) { - if (index > 0) { - wrapper.appendChild(document.createElement("br")); - } - wrapper.appendChild(document.createTextNode(line)); - - }); + wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright pre-line"; + wrapper.appendChild(compliment); return wrapper; },