Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/__tests__/html-to-adf.test.ts
Original file line number Diff line number Diff line change
@@ -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 = `<p>test <b>this</b></p>`;
Expand Down Expand Up @@ -121,4 +121,38 @@ it('should convert a pre tag to code block', () => {
]
}
expect(result).toEqual(expected);
});
});


it('should convert an a href tag to url', () => {
const htmlString = `<p><a href="https://example.com" title="Example" target="_blank">hello</a></br></p>
`;
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);
});
4 changes: 2 additions & 2 deletions src/html-to-adf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Loading