diff --git a/lib/parseHtml.test.ts b/lib/parseHtml.test.ts
index 094681d19..ed3d1153a 100644
--- a/lib/parseHtml.test.ts
+++ b/lib/parseHtml.test.ts
@@ -14,6 +14,13 @@ describe('parseHtml', () => {
it('handles missing html', () => {
expect(() => trim()).not.toThrow()
})
+ it('handles links with spaces', () => {
+ const html = `
`
+
+ expect(trim(html)).toEqual('')
+ })
})
describe('toMarkdown', () => {
it('turns html into Markdown', () => {
diff --git a/lib/parseHtml.ts b/lib/parseHtml.ts
index 0f18d4062..cc01b6287 100644
--- a/lib/parseHtml.ts
+++ b/lib/parseHtml.ts
@@ -1,14 +1,27 @@
import * as h2m from 'h2m'
import { htmlDecode } from 'js-htmlencode'
-export const trim = (html: string = ''): string => html
- .replace(/ /g, ' ')
- .split('>')
- .map((token) => token.trim())
- .join('>')
- .split('')
- .map((token) => token.trim())
- .join('')
+export const trim = (html: string = ''): string => {
+ const trimmed = html
+ .replace(/ /g, ' ')
+ .split('>')
+ .map((token) => token.trim())
+ .join('>')
+ .split('')
+ .map((token) => token.trim())
+ .join('')
+ const rxSpaces = /href="(.*)"/g
+ const 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
+}
interface Node {
name: string