mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
fix: correctly parse http link including another http link in the path (#2460)
fix #2457 Thoughts @jschleic ?
This commit is contained in:
commit
5ab11428a5
2 changed files with 21 additions and 10 deletions
|
@ -159,16 +159,13 @@ export function toHTML(r, options) {
|
|||
r = r.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
||||
|
||||
// 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')
|
||||
r = r.replace(/(=http)/g, '=h_t_t_p') // http://xxx as query string, see https://github.com/umap-project/umap/issues/607
|
||||
r = r.replace(/(https?:[^ \<)\n]*)/g, `<a target="_${target}" href="$1">$1</a>`)
|
||||
r = r.replace(
|
||||
/\[\[(h_t_t_ps?:[^\]|]*?)\]\]/g,
|
||||
`<a target="_${target}" href="$1">$1</a>`
|
||||
/(^|\s|>|\()(https?:[^ \<)\n]*)/g,
|
||||
`$1<a target="_${target}" href="$2">$2</a>`
|
||||
)
|
||||
r = r.replace(/\[\[(https?:[^\]|]*?)\]\]/g, `<a target="_${target}" href="$1">$1</a>`)
|
||||
r = r.replace(
|
||||
/\[\[(h_t_t_ps?:[^|]*?)\|(.*?)\]\]/g,
|
||||
/\[\[(https?:[^|]*?)\|(.*?)\]\]/g,
|
||||
`<a target="_${target}" href="$1">$2</a>`
|
||||
)
|
||||
r = r.replace(/\[\[([^\]|]*?)\]\]/g, `<a target="_${target}" href="$1">$1</a>`)
|
||||
|
@ -176,15 +173,15 @@ export function toHTML(r, options) {
|
|||
|
||||
// iframe
|
||||
r = r.replace(
|
||||
/{{{(h_t_t_ps?[^|{]*)}}}/g,
|
||||
/{{{(https?[^|{]*)}}}/g,
|
||||
'<div><iframe frameborder="0" src="$1" width="100%" height="300px"></iframe></div>'
|
||||
)
|
||||
r = r.replace(
|
||||
/{{{(h_t_t_ps?[^|{]*)\|(\d*)(px)?}}}/g,
|
||||
/{{{(https?[^|{]*)\|(\d*)(px)?}}}/g,
|
||||
'<div><iframe frameborder="0" src="$1" width="100%" height="$2px"></iframe></div>'
|
||||
)
|
||||
r = r.replace(
|
||||
/{{{(h_t_t_ps?[^|{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g,
|
||||
/{{{(https?[^|{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g,
|
||||
'<div><iframe frameborder="0" src="$1" width="$4px" height="$2px"></iframe></div>'
|
||||
)
|
||||
|
||||
|
|
|
@ -54,6 +54,13 @@ describe('Utils', () => {
|
|||
)
|
||||
})
|
||||
|
||||
it('should handle links with another url in path', () => {
|
||||
assert.equal(
|
||||
Utils.toHTML('A simple https://osm.org/https://anotherurl.com link'),
|
||||
'A simple <a href="https://osm.org/https://anotherurl.com" target="_blank">https://osm.org/https://anotherurl.com</a> link'
|
||||
)
|
||||
})
|
||||
|
||||
it('should handle simple link inside parenthesis', () => {
|
||||
assert.equal(
|
||||
Utils.toHTML('A simple link (http://osm.org)'),
|
||||
|
@ -172,6 +179,13 @@ describe('Utils', () => {
|
|||
)
|
||||
})
|
||||
|
||||
it('http link with http link as in path', () => {
|
||||
assert.equal(
|
||||
Utils.toHTML('A phrase with a [[https://iframeurl.com/https://another.com]].'),
|
||||
'A phrase with a <a href="https://iframeurl.com/https://another.com" target="_blank">https://iframeurl.com/https://another.com</a>.'
|
||||
)
|
||||
})
|
||||
|
||||
it('simple bullet points', () => {
|
||||
assert.equal(
|
||||
Utils.toHTML('* First point\n* Second point\n* Last point'),
|
||||
|
|
Loading…
Reference in a new issue