Files
transform/pages/html-to-pug.tsx
Ritesh Kumar 9f67f97573 2.1.0 (#128)
* HTML to Pug converter (#127)

* feat(pug): add HTML to pug converter

* fix(pug): added package details

* feat(analyze): added webpack bundle analyzer

*  fix(rust): handle special characters and duplicate keys (#131)

* remove duplicate google tag manager (#122)

* Update _app.tsx (#124)

* docs: add timneutkens as a contributor (#125)

* docs: update README.md

* docs: update .all-contributorsrc

* Upgrade Next.js to 9 (#126)

* Upgrade Next.js to 9

* Add back engines key

* Add globalObject

Brings in suggestion from https://github.com/zeit/next.js/issues/7873#issuecomment-512795482

* Add temporary fix for window issue

* fix(font): add fallback font for non mac browsers (#130)

closes #129

* fix(rust): handle special characters and duplicate keys

closes #97

* fix(rust): handle special chars

closes #97, closes #95, closes #89, closes #62

* chore(rust): remove settings

* feat(kotlin): added JSON to kotlin and json schema

* fixes

* fixes

* fixes

* fixes

* fixes

* added favicon

* social media tags
2019-07-25 00:38:09 +05:30

76 lines
1.6 KiB
TypeScript

import ConversionPanel from "@components/ConversionPanel";
import * as React from "react";
import { useCallback } from "react";
import { useSettings } from "@hooks/useSettings";
import Form, { InputType } from "@components/Form";
import html2pug from "html2pug";
import minify from "@assets/vendor/html-minifier";
const formFields = [
{
key: "tabs",
type: InputType.SWITCH,
label: "Use Tabs"
},
{
key: "commas",
type: InputType.SWITCH,
label: "Commas"
},
{
key: "doubleQuotes",
type: InputType.SWITCH,
label: "Use double quotes"
},
{
key: "fragment",
type: InputType.SWITCH,
label: "Use Fragment"
}
];
const defaultSettings = {
tabs: true,
commas: true,
doubleQuotes: false,
fragment: false
};
export default function() {
const name = "HTML to Pug";
const [settings, setSettings] = useSettings(name, defaultSettings);
const getSettingsElement = useCallback(({ open, toggle }) => {
return (
<Form<typeof defaultSettings>
title={name}
onSubmit={setSettings}
open={open}
toggle={toggle}
formsFields={formFields}
initialValues={settings}
/>
);
}, []);
const transformer = useCallback(
async ({ value }) => {
return html2pug(value, minify, settings);
},
[settings, minify]
);
return (
<ConversionPanel
transformer={transformer}
editorTitle="HTML"
editorLanguage="html"
resultTitle="Pug"
resultLanguage={"pug"}
resultSettingsElement={getSettingsElement}
settings={settings}
/>
);
}