Skip to content

Commit

Permalink
fix(convertslate): pass attribs to defaultTag (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsonsj authored Oct 23, 2024
1 parent 5b30f55 commit 42aa314
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/dom/src/lib/utilities/convert-slate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const convertSlate = ({

// default tag
if (!element && config.defaultTag && !node.type) {
element = transformElement(new Element(config.defaultTag, {}, children))
element = transformElement(new Element(config.defaultTag, attribs, children))
}

if (element) {
Expand Down
31 changes: 31 additions & 0 deletions packages/html/src/lib/serializers/slateToHtml/payload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@ import { Element } from 'domhandler'
import { slateToHtml, payloadSlateToHtmlConfig, type ElementTransform } from '@slate-serializers/html'

describe('slateToHtml: Payload CMS config', () => {
it('adds text alignment', () => {
const html = '<p style="text-align:left;">Left aligned.</p><p style="text-align:center;">Center aligned.</p><p style="text-align:right;">Right aligned.</p>'
const slate = [
{
"children": [
{
"text": "Left aligned."
}
],
"textAlign": "left"
},
{
"children": [
{
"text": "Center aligned."
}
],
"textAlign": "center"
},
{
"children": [
{
"text": "Right aligned."
}
],
"textAlign": "right"
},
]
expect(slateToHtml(slate, payloadSlateToHtmlConfig)).toEqual(html)
})

it('renders an upload field as an `img` HTML element if an image', () => {
const html = '<img src="/images/pink-hour-au-cafe-bataclan-paris.jpg">'
const slate = [
Expand Down

0 comments on commit 42aa314

Please sign in to comment.