diff options
author | 2023-07-24 23:36:32 +0000 | |
---|---|---|
committer | 2023-07-24 23:36:32 +0000 | |
commit | 25e04a2ecbda7952a68220ce6739ae1c75144858 (patch) | |
tree | 1fc602a9a1cef5bb9cde6b3d3c8465f7129cbb90 /packages/integrations/markdoc/src/html/css/parse-inline-css-to-react.ts | |
parent | 7461e82c81438df956861197536f9ceeaf63d6b3 (diff) | |
download | astro-25e04a2ecbda7952a68220ce6739ae1c75144858.tar.gz astro-25e04a2ecbda7952a68220ce6739ae1c75144858.tar.zst astro-25e04a2ecbda7952a68220ce6739ae1c75144858.zip |
[ci] format
Diffstat (limited to 'packages/integrations/markdoc/src/html/css/parse-inline-css-to-react.ts')
-rw-r--r-- | packages/integrations/markdoc/src/html/css/parse-inline-css-to-react.ts | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/packages/integrations/markdoc/src/html/css/parse-inline-css-to-react.ts b/packages/integrations/markdoc/src/html/css/parse-inline-css-to-react.ts index 3b67f9a32..dd429788a 100644 --- a/packages/integrations/markdoc/src/html/css/parse-inline-css-to-react.ts +++ b/packages/integrations/markdoc/src/html/css/parse-inline-css-to-react.ts @@ -1,23 +1,24 @@ +import { styleToObject } from './style-to-object.js'; -import { styleToObject } from "./style-to-object.js"; +export function parseInlineCSSToReactLikeObject( + css: string | undefined | null +): React.CSSProperties | undefined { + if (typeof css === 'string') { + const cssObject: Record<string, string> = {}; + styleToObject(css, (originalCssDirective: string, value: string) => { + const reactCssDirective = convertCssDirectiveNameToReactCamelCase(originalCssDirective); + cssObject[reactCssDirective] = value; + }); + return cssObject; + } -export function parseInlineCSSToReactLikeObject(css: string | undefined | null): React.CSSProperties | undefined { - if (typeof css === "string") { - const cssObject: Record<string, string> = {}; - styleToObject(css, (originalCssDirective: string, value: string) => { - const reactCssDirective = convertCssDirectiveNameToReactCamelCase(originalCssDirective); - cssObject[reactCssDirective] = value; - }); - return cssObject; - } - - return undefined; + return undefined; } function convertCssDirectiveNameToReactCamelCase(original: string): string { - // capture group 1 is the character to capitalize, the hyphen is omitted by virtue of being outside the capture group - const replaced = original.replace(/-([a-z0-9])/ig, (_match, char) => { - return char.toUpperCase(); - }); - return replaced; + // capture group 1 is the character to capitalize, the hyphen is omitted by virtue of being outside the capture group + const replaced = original.replace(/-([a-z0-9])/gi, (_match, char) => { + return char.toUpperCase(); + }); + return replaced; } |