diff --git a/lib/parseHtml.test.ts b/lib/parseHtml.test.ts index ed3d1153..2d2628b0 100644 --- a/lib/parseHtml.test.ts +++ b/lib/parseHtml.test.ts @@ -17,9 +17,10 @@ describe('parseHtml', () => { it('handles links with spaces', () => { const html = `
` - expect(trim(html)).toEqual('') + expect(trim(html)).toEqual('') }) }) describe('toMarkdown', () => { diff --git a/lib/parseHtml.ts b/lib/parseHtml.ts index cc01b628..ac4a7aec 100644 --- a/lib/parseHtml.ts +++ b/lib/parseHtml.ts @@ -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 {