diff --git a/src/__tests__/html-to-adf.test.ts b/src/__tests__/html-to-adf.test.ts index 7537607..ff34aea 100644 --- a/src/__tests__/html-to-adf.test.ts +++ b/src/__tests__/html-to-adf.test.ts @@ -1,4 +1,4 @@ -import {convertHtmlToADF} from '../html-to-adf'; +import {convertHtmlToADF} from "../html-to-adf"; it('should convert a simple paragraph with bold', () => { const htmlString = `

test this

`; @@ -121,4 +121,38 @@ it('should convert a pre tag to code block', () => { ] } expect(result).toEqual(expected); - }); \ No newline at end of file + }); + + + it('should convert an a href tag to url', () => { + const htmlString = `

hello

+ `; + const result = convertHtmlToADF(htmlString); + const expected = { + version: 1, + type: "doc", + content: [ + { + type: "paragraph", + content: [ + { + type: "text", + text: "hello", + marks: [ + { + type: "link", + attrs: { + href: "https://example.com", + }, + }, + ], + }, + { + type: "hardBreak", + }, + ], + }, + ], + }; + expect(result).toEqual(expected); +}); diff --git a/src/html-to-adf.ts b/src/html-to-adf.ts index d270f22..4281a26 100644 --- a/src/html-to-adf.ts +++ b/src/html-to-adf.ts @@ -25,8 +25,8 @@ const processNode = (node: any, marks = [] as any) => { marks.push({ type: "link", attrs: { - href: node.attributes.href, - title: node.text || node.textContent, + href: node.attribs.href, + title: node.attribs.title || node.text || node.textContent, }, }); } else if (node.name === "br") {