From 3edbf8c2c6ed8c34ba9e6b5d894e52e904de9662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20=C3=96brink?= Date: Fri, 12 Feb 2021 13:49:10 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fixar=20links=20med=20mel?= =?UTF-8?q?lanslag=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/parseHtml.test.ts | 7 +++++++ lib/parseHtml.ts | 29 +++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/parseHtml.test.ts b/lib/parseHtml.test.ts index 094681d1..ed3d1153 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 = `
+ Hello +
` + + expect(trim(html)).toEqual('
Hello
') + }) }) describe('toMarkdown', () => { it('turns html into Markdown', () => { diff --git a/lib/parseHtml.ts b/lib/parseHtml.ts index 0f18d406..cc01b628 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(' token.trim()) - .join(' { + const trimmed = html + .replace(/ /g, ' ') + .split('>') + .map((token) => token.trim()) + .join('>') + .split(' token.trim()) + .join('