summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/src/html/css/parse-inline-css-to-react.ts
diff options
context:
space:
mode:
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.ts35
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;
}