Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions constants/jsxAttributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const JSX_BOOLEAN_ATTRIBUTES = [
"async",
"autoFocus",
"autoPlay",
"checked",
"controls",
"default",
"defer",
"disabled",
"formNoValidate",
"hidden",
"loop",
"multiple",
"muted",
"noValidate",
"open",
"readOnly",
"required",
"reversed",
"scoped",
"selected"
] as const;

export type JsxBooleanAttribute = typeof JSX_BOOLEAN_ATTRIBUTES[number];

export const BOOLEAN_ATTRIBUTES_REGEX = new RegExp(
`\\b(${JSX_BOOLEAN_ATTRIBUTES.join("|")})=""`,
"g"
);
2 changes: 2 additions & 0 deletions pages/html-to-jsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useSettings } from "@hooks/useSettings";
import isSvg from "is-svg";
import { Alert, Heading } from "evergreen-ui";
import Router from "next/router";
import { BOOLEAN_ATTRIBUTES_REGEX } from "@constants/jsxAttributes";

interface Settings {
createFunction: boolean;
Expand Down Expand Up @@ -39,6 +40,7 @@ export default function HtmlToJsxComponent() {
createClass: false
});
let result = converter.convert(value);
result = result.replace(BOOLEAN_ATTRIBUTES_REGEX, "$1");

if (settings.createFunction) {
result = `export const Foo = () => (${result})`;
Expand Down