@knapsack/app
Version:
Build Design Systems on top of knapsack, by Basalt
23 lines (20 loc) • 531 B
text/typescript
import prettier from 'prettier/standalone';
import parserHtml from 'prettier/parser-html';
/**
* Format code with Prettier
* If it can't format, it just returns original code
* @link https://prettier.io/docs/en/options.html#parser
*/
export function formatHtmlCode(code: string): string {
if (!code) return code;
try {
return prettier.format(code?.trim(), {
parser: 'html',
plugins: [parserHtml],
});
} catch (error) {
console.error(error);
return code;
}
}
export default formatHtmlCode;