From fa2bef85d3dd6bbe0c39a7dca2def2a2ad1422b3 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 29 May 2024 10:35:25 +0200 Subject: [PATCH] fix: refactor new line management in popups Basically, we do not add `
` anymore, but instead let the newline and use the css `white-space: pre-line;`. Also remove new lines after title. While doing that change, I needed to reorder regex so the ones needing a newline before would still have it (bullets points). I've added tests and removed some to cover those changes. fix #1854 --- umap/static/umap/js/modules/utils.js | 24 ++++++---------- umap/static/umap/map.css | 6 ++-- umap/static/umap/unittests/utils.js | 43 +++++++++++++++++----------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/umap/static/umap/js/modules/utils.js b/umap/static/umap/js/modules/utils.js index 1da8fd9f..eca2c44e 100644 --- a/umap/static/umap/js/modules/utils.js +++ b/umap/static/umap/js/modules/utils.js @@ -112,27 +112,24 @@ export function escapeHTML(s) { export function toHTML(r, options) { if (!r) return '' const target = (options && options.target) || 'blank' - let ii - // detect newline format - const newline = r.indexOf('\r\n') != -1 ? '\r\n' : r.indexOf('\n') != -1 ? '\n' : '' + // unordered lists + r = r.replace(/^\*\* (.*)/gm, '') + r = r.replace(/^\* (.*)/gm, '') + for (let ii = 0; ii < 3; ii++) { + r = r.replace(new RegExp(`(\r\n|\r|\n)${newline}