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', () => {
|
||||
const html = `<div>
|
||||
<a href="/foo bar">Hello </a>
|
||||
<a href='/foo bar'>Hello </a>
|
||||
</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', () => {
|
||||
|
|
|
@ -10,17 +10,26 @@ export const trim = (html: string = ''): string => {
|
|||
.split('</')
|
||||
.map((token) => token.trim())
|
||||
.join('</')
|
||||
|
||||
let result = trimmed
|
||||
const rxSpaces = /href="(.*)"/g
|
||||
const matches = trimmed.match(rxSpaces)
|
||||
let matches = trimmed.match(rxSpaces)
|
||||
if (matches) {
|
||||
let result = trimmed
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const match of matches) {
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue