Skip to content

Commit

Permalink
test(htmlupdatermap): add
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsonsj committed Oct 28, 2024
1 parent 1ae6cfc commit b6f1ab9
Showing 1 changed file with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// eslint-disable-next-line @nx/enforce-module-boundaries
import {
htmlToSlate,
HtmlToSlateConfig,
htmlToSlateConfig,
} from '@slate-serializers/html';
import { Element } from 'domhandler';
import { getAttributeValue } from 'domutils';

describe('htmlToSlate configuration: htmlUpdaterMap', () => {
it('converts element tags to Slate nodes from the default configuration', () => {
const html = '<p>Paragraph 1</p><p>Paragraph 2</p>';
const config: HtmlToSlateConfig = {
...htmlToSlateConfig,
elementTags: {
...htmlToSlateConfig.elementTags,
div: (el) => ({
...(el && {
class: getAttributeValue(el, 'class'),
}),
type: 'div',
}),
},
htmlUpdaterMap: {
['p']: (paragraph) => {
return new Element('div', { ['class']: 'paragraph-wrapper' }, [
paragraph,
]);
},
},
};
expect(htmlToSlate(html, config)).toMatchInlineSnapshot(`
[
{
"children": [
{
"children": [
{
"text": "Paragraph 1",
},
],
"type": "p",
},
],
"class": "paragraph-wrapper",
"type": "div",
},
{
"children": [
{
"children": [
{
"text": "Paragraph 2",
},
],
"type": "p",
},
],
"class": "paragraph-wrapper",
"type": "div",
},
]
`);
});
});

0 comments on commit b6f1ab9

Please sign in to comment.