Skip to content

Commit

Permalink
Drop style attributes during import for now
Browse files Browse the repository at this point in the history
Related to #506
  • Loading branch information
johno committed Jul 19, 2022
1 parent f5974f3 commit bb72987
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-laws-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@compai/css-gui': patch
---

Ignore style attribute on import for now
5 changes: 5 additions & 0 deletions packages/gui/src/lib/transformers/hast-to-editor-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { unified } from 'unified'
import { cleanNewLines } from './plugins/clean-new-lines'
import { propertiesToAttributes } from './plugins/properties-to-attributes'
import { Root } from 'rehype-parse/lib'
import { transformStyleAttributes } from './plugins/transform-style-attributes'
import { moveStyleToTopLevel } from './plugins/move-style-to-top-level'

export const hastToEditorSchema = (tree: Root) => {
const processedTree = unified()
.use(cleanNewLines)
// @ts-ignore
.use(moveStyleToTopLevel)
// @ts-ignore
.use(propertiesToAttributes)
.use(transformStyleAttributes)
.runSync(tree)

const htmlBody = processedTree.children[0]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { isObject, isString } from 'lodash-es'
import { visit } from 'unist-util-visit'

export const transformStyleAttributes = () => (tree: any) => {
visit(tree, 'element', (node) => {
if (!node.style || isObject(node.style)) {
return
}

// TODO: Perform a style import
// https://github.com/components-ai/css.gui/issues/506
if (isString(node.style)) {
delete node.style
}
})
}

0 comments on commit bb72987

Please sign in to comment.