Skip to content

Commit 9ac58f1

Browse files
authored
Merge pull request #509 from components-ai/fix-style-error
Drop style attributes during import for now
2 parents d46084a + bb72987 commit 9ac58f1

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

.changeset/stupid-laws-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compai/css-gui': patch
3+
---
4+
5+
Ignore style attribute on import for now

packages/gui/src/lib/transformers/hast-to-editor-schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import { unified } from 'unified'
22
import { cleanNewLines } from './plugins/clean-new-lines'
33
import { propertiesToAttributes } from './plugins/properties-to-attributes'
44
import { Root } from 'rehype-parse/lib'
5+
import { transformStyleAttributes } from './plugins/transform-style-attributes'
6+
import { moveStyleToTopLevel } from './plugins/move-style-to-top-level'
57

68
export const hastToEditorSchema = (tree: Root) => {
79
const processedTree = unified()
810
.use(cleanNewLines)
911
// @ts-ignore
12+
.use(moveStyleToTopLevel)
13+
// @ts-ignore
1014
.use(propertiesToAttributes)
15+
.use(transformStyleAttributes)
1116
.runSync(tree)
1217

1318
const htmlBody = processedTree.children[0]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { isObject, isString } from 'lodash-es'
2+
import { visit } from 'unist-util-visit'
3+
4+
export const transformStyleAttributes = () => (tree: any) => {
5+
visit(tree, 'element', (node) => {
6+
if (!node.style || isObject(node.style)) {
7+
return
8+
}
9+
10+
// TODO: Perform a style import
11+
// https://github.com/components-ai/css.gui/issues/506
12+
if (isString(node.style)) {
13+
delete node.style
14+
}
15+
})
16+
}

0 commit comments

Comments
 (0)