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)`, 'g'), '')
+ }
// headings and hr
- r = r.replace(/^### (.*)/gm, '$1
')
- r = r.replace(/^## (.*)/gm, '$1
')
- r = r.replace(/^# (.*)/gm, '$1
')
+ r = r.replace(/^### (.*)(\r\n|\r|\n)?/gm, '$1
')
+ r = r.replace(/^## (.*)(\r\n|\r|\n)?/gm, '$1
')
+ r = r.replace(/^# (.*)(\r\n|\r|\n)?/gm, '$1
')
r = r.replace(/^---/gm, '
')
// bold, italics
r = r.replace(/\*\*(.*?)\*\*/g, '$1')
r = r.replace(/\*(.*?)\*/g, '$1')
- // unordered lists
- r = r.replace(/^\*\* (.*)/gm, '')
- r = r.replace(/^\* (.*)/gm, '')
- for (ii = 0; ii < 3; ii++)
- r = r.replace(new RegExp(`
${newline}`, 'g'), newline)
-
// links
r = r.replace(/(\[\[http)/g, '[[h_t_t_p') // Escape for avoiding clash between [[http://xxx]] and http://xxx
r = r.replace(/({{http)/g, '{{h_t_t_p')
@@ -173,9 +170,6 @@ export function toHTML(r, options) {
//Unescape http
r = r.replace(/(h_t_t_p)/g, 'http')
- // Preserver line breaks
- if (newline) r = r.replace(new RegExp(`${newline}(?=[^]+)`, 'g'), `
${newline}`)
-
r = escapeHTML(r)
return r
diff --git a/umap/static/umap/map.css b/umap/static/umap/map.css
index f00eceec..e17d8d92 100644
--- a/umap/static/umap/map.css
+++ b/umap/static/umap/map.css
@@ -1563,9 +1563,11 @@ span.popup-icon {
.umap-popup-container {
flex-grow: 1;
word-break: break-word;
+ white-space: pre-line;
+ margin-bottom: 10px;
}
-.leaflet-popup-content h3 {
- margin-bottom: 0;
+.umap-popup-container ul {
+ list-style-type: disc;
}
.leaflet-control-toolbar,
.leaflet-bar {
diff --git a/umap/static/umap/unittests/utils.js b/umap/static/umap/unittests/utils.js
index 4943d1b4..99b9c8a4 100644
--- a/umap/static/umap/unittests/utils.js
+++ b/umap/static/umap/unittests/utils.js
@@ -13,12 +13,12 @@ describe('Utils', function () {
it('should handle title', function () {
assert.equal(Utils.toHTML('# A title'), 'A title
')
})
+ it('should handle title followed by text', function () {
+ assert.equal(Utils.toHTML('# A title\nSome text.'), 'A title
Some text.')
+ })
it('should handle title in the middle of the content', function () {
- assert.equal(
- Utils.toHTML('A phrase\n## A title'),
- 'A phrase
\nA title
'
- )
+ assert.equal(Utils.toHTML('A phrase\n## A title'), 'A phrase\nA title
')
})
it('should handle hr', function () {
@@ -33,18 +33,6 @@ describe('Utils', function () {
assert.equal(Utils.toHTML('Some *italic*'), 'Some italic')
})
- it('should handle newlines', function () {
- assert.equal(Utils.toHTML('two\nlines'), 'two
\nlines')
- })
-
- it('should not change last newline', function () {
- assert.equal(Utils.toHTML('two\nlines\n'), 'two
\nlines\n')
- })
-
- it('should handle two successive newlines', function () {
- assert.equal(Utils.toHTML('two\n\nlines\n'), 'two
\n
\nlines\n')
- })
-
it('should handle links without formatting', function () {
assert.equal(
Utils.toHTML('A simple http://osm.org link'),
@@ -90,7 +78,7 @@ describe('Utils', function () {
it('should handle simple link followed by a carriage return', function () {
assert.equal(
Utils.toHTML('A simple link http://osm.org\nAnother line'),
- 'A simple link http://osm.org
\nAnother line'
+ 'A simple link http://osm.org\nAnother line'
)
})
@@ -174,6 +162,27 @@ describe('Utils', function () {
'A phrase with a http://iframeurl.com?to=http://another.com.'
)
})
+
+ it('simple bullet points', function () {
+ assert.equal(
+ Utils.toHTML('* First point\n* Second point\n* Last point'),
+ '- First point
- Second point
- Last point
'
+ )
+ })
+
+ it('bullet points with bold and italic', function () {
+ assert.equal(
+ Utils.toHTML('* First *point*\n* Second **point**\n* Last [[https://here.org|point]]'),
+ '- First point
- Second point
- Last point
'
+ )
+ })
+
+ it('title followed by bullet points', function () {
+ assert.equal(
+ Utils.toHTML('## Some title\n* First *point*\n* Second **point**\n* Last [[https://here.org|point]]'),
+ 'Some title
- First point
- Second point
- Last point
'
+ )
+ })
})
describe('#escapeHTML', function () {