fix: links (#64)
* fix: 🐛 Fixar links med mellanslag * fix: 🐛 Links med single quote
This commit is contained in:
parent
3edbf8c2c6
commit
905b893ca7
|
@ -17,9 +17,10 @@ describe('parseHtml', () => {
|
||||||
it('handles links with spaces', () => {
|
it('handles links with spaces', () => {
|
||||||
const html = `<div>
|
const html = `<div>
|
||||||
<a href="/foo bar">Hello </a>
|
<a href="/foo bar">Hello </a>
|
||||||
|
<a href='/foo bar'>Hello </a>
|
||||||
</div>`
|
</div>`
|
||||||
|
|
||||||
expect(trim(html)).toEqual('<div><a href="/foo%20bar">Hello</a></div>')
|
expect(trim(html)).toEqual('<div><a href="/foo%20bar">Hello</a><a href=\'/foo%20bar\'>Hello</a></div>')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('toMarkdown', () => {
|
describe('toMarkdown', () => {
|
||||||
|
|
|
@ -10,17 +10,26 @@ export const trim = (html: string = ''): string => {
|
||||||
.split('</')
|
.split('</')
|
||||||
.map((token) => token.trim())
|
.map((token) => token.trim())
|
||||||
.join('</')
|
.join('</')
|
||||||
|
|
||||||
|
let result = trimmed
|
||||||
const rxSpaces = /href="(.*)"/g
|
const rxSpaces = /href="(.*)"/g
|
||||||
const matches = trimmed.match(rxSpaces)
|
let matches = trimmed.match(rxSpaces)
|
||||||
if (matches) {
|
if (matches) {
|
||||||
let result = trimmed
|
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
result = result.replace(match, match.replace(/ /g, '%20'))
|
result = result.replace(match, match.replace(/ /g, '%20'))
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
return trimmed
|
|
||||||
|
const rxSpacesSing = /href='(.*)'/g
|
||||||
|
matches = trimmed.match(rxSpacesSing)
|
||||||
|
if (matches) {
|
||||||
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
|
for (const match of matches) {
|
||||||
|
result = result.replace(match, match.replace(/ /g, '%20'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Node {
|
interface Node {
|
||||||
|
|
Loading…
Reference in New Issue