@maizzle/framework
Version:
Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.
38 lines (37 loc) • 1.65 kB
TypeScript
import { ChildNode } from "domhandler";
//#region src/transformers/attributeToStyle.d.ts
/**
* Convert HTML attributes to inline CSS styles.
*
* Supported attributes:
* - `width`: `width: ${value}${unit}` (px and %, defaults to px)
* - `height`: `height: ${value}${unit}` (px and %, defaults to px)
* - `bgcolor`: `background-color: ${value}`
* - `background`: `background-image: url('${value}')`
* - `align`: on `<table>`, `left`/`right` become `float`, `center` becomes
* `margin-left/right: auto`; on other elements, becomes `text-align`
* - `valign`: `vertical-align: ${value}`
*
* @param html HTML string to transform.
* @param attributes `true` to process the default set, an array to restrict
* to specific attribute names, `false` to disable.
* @returns The transformed HTML string.
*
* @example
* import { attributeToStyle } from '@maizzle/framework'
*
* const out = attributeToStyle('<table align="center"><tr><td bgcolor="#f00">x</td></tr></table>')
*
* // Restrict to specific attributes:
* const limited = attributeToStyle(html, ['width', 'height'])
*/
declare function attributeToStyle(html: string, attributes?: boolean | string[]): string;
/**
* DOM-form of {@link attributeToStyle} used by the internal transformer
* pipeline. Takes a parsed DOM, returns a parsed DOM — avoids redundant
* serialize/parse round-trips when chained with other transformers.
*/
declare function attributeToStyleDom(dom: ChildNode[], attributes?: boolean | string[]): ChildNode[];
//#endregion
export { attributeToStyle, attributeToStyleDom };
//# sourceMappingURL=attributeToStyle.d.ts.map