Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
astro-wt
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
f277360d
authored
2024-11-27 10:30:35 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
In react, parse string style to object style.
1 parent
a2e25c4d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
2 deletions
lib/react.jsx
package-lock.json
package.json
lib/react.jsx
View file @
f277360
import
React
from
'react'
import
parseStyle
from
'style-to-object'
import
{
COMMENT_NODE
,
DOCUMENT_NODE
,
DOCTYPE_NODE
,
ELEMENT_NODE
,
TEXT_NODE
}
from
'ultrahtml'
import
{
parseHtml
,
createAdjuster
,
createMatcher
,
findNode
}
from
'astro-wt/html'
import
{
decode
}
from
'html-entities'
...
...
@@ -18,12 +18,16 @@ export const ReparseStaticChildren = (replaceOptions, Component) => (props) => {
}
export
const
fixAttributes
=
(
attributes
)
=>
{
const
{
class
:
className
,
srcset
:
srcSet
,
maxlength
:
maxLength
,
for
:
htmlFor
,
...
rest
}
=
attributes
const
{
class
:
className
,
s
tyle
,
s
rcset
:
srcSet
,
maxlength
:
maxLength
,
for
:
htmlFor
,
...
rest
}
=
attributes
const
result
=
rest
if
(
className
!==
undefined
)
result
.
className
=
className
if
(
srcSet
!==
undefined
)
result
.
srcSet
=
srcSet
if
(
maxLength
!==
undefined
)
result
.
maxLength
=
maxLength
if
(
htmlFor
!==
undefined
)
result
.
htmlFor
=
htmlFor
if
(
style
)
{
const
styleObject
=
parseStyle
(
style
)
result
.
style
=
styleObject
}
return
result
}
...
...
package-lock.json
View file @
f277360
...
...
@@ -10,6 +10,7 @@
"@reduxjs/toolkit"
:
"^2.2.5"
,
"html-entities"
:
"^2.5.2"
,
"parsel-js"
:
"^1.1.2"
,
"style-to-object"
:
"^1.0.8"
,
"ultrahtml"
:
"^1.5.3"
},
"devDependencies"
:
{
...
...
@@ -3288,6 +3289,12 @@
"integrity"
:
"sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
,
"dev"
:
true
},
"node_modules/inline-style-parser"
:
{
"version"
:
"0.2.4"
,
"resolved"
:
"https://registry.npmjs.org/inline-style-parser/-/inline-style-parser-0.2.4.tgz"
,
"integrity"
:
"sha512-0aO8FkhNZlj/ZIbNi7Lxxr12obT7cL1moPfE4tg1LkX7LlLfC6DeX4l2ZEud1ukP9jNQyNnfzQVqwbwmAATY4Q=="
,
"license"
:
"MIT"
},
"node_modules/is-arrayish"
:
{
"version"
:
"0.3.2"
,
"resolved"
:
"https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz"
,
...
...
@@ -6095,6 +6102,15 @@
"url"
:
"https://github.com/sponsors/sindresorhus"
}
},
"node_modules/style-to-object"
:
{
"version"
:
"1.0.8"
,
"resolved"
:
"https://registry.npmjs.org/style-to-object/-/style-to-object-1.0.8.tgz"
,
"integrity"
:
"sha512-xT47I/Eo0rwJmaXC4oilDGDWLohVhR6o/xAQcPQN8q6QBuZVL8qMYL85kLmST5cPjAorwvqIA4qXTRQoYHaL6g=="
,
"license"
:
"MIT"
,
"dependencies"
:
{
"inline-style-parser"
:
"0.2.4"
}
},
"node_modules/supports-color"
:
{
"version"
:
"5.5.0"
,
"resolved"
:
"https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz"
,
...
...
package.json
View file @
f277360
...
...
@@ -15,6 +15,7 @@
"@reduxjs/toolkit"
:
"^2.2.5"
,
"html-entities"
:
"^2.5.2"
,
"parsel-js"
:
"^1.1.2"
,
"style-to-object"
:
"^1.0.8"
,
"ultrahtml"
:
"^1.5.3"
},
"devDependencies"
:
{
...
...
Please
register
or
sign in
to post a comment