tailwind.config file isn’t enough — custom handlers, brand colors at runtime, or replacing built-in behavior.
createTailwindParser
Factory function that returns aTailwindParser instance:
Options
| Option | Type | Description |
|---|---|---|
colors | Record<string, Record<number, string>> | Custom color palette. Merged with built-in colors. |
fontSizes | Record<string, number> | Custom font sizes (in half-points). Merged with built-ins. |
fontFamilies | Record<string, string> | Custom font families. Merged with built-ins. |
extraHandlers | ClassHandler[] | Custom handlers prepended to the pipeline. Run before built-ins. |
replacedHandlers | Partial<Record<HandlerName, ClassHandler>> | Replace specific built-in handlers by name. |
Custom colors
# prefix.
Custom fonts
Custom handlers
AClassHandler is a function that processes a Tailwind class and writes the result:
true if the class was handled, false to pass it to the next handler.
Adding extra handlers
Extra handlers run before the built-in pipeline:Replacing built-in handlers
Override a specific handler by name. You can delegate to the original viadefaultHandlerMap:
Handler names
All built-in handlers that can be replaced:| Name | Handles |
|---|---|
textFormatting | Bold, italic, underline, strike, caps |
textColor | text-{color}-{shade} classes |
backgroundColor | bg-{color}-{shade} classes |
textAlignment | text-left, text-center, text-right, text-justify |
spacing | mt-*, mb-*, ml-*, mr-*, indent-* |
lineHeight | leading-* classes |
letterSpacing | tracking-* classes |
borders | border-* classes (width, style, color, sides) |
tableCellPadding | p-*, px-*, py-*, pt-*, pb-* |
tableCellAlignment | align-top, align-middle, align-bottom |
sizing | w-*, h-* for images |
objectFit | object-cover, object-contain, object-fill |
customAspectRatio | aspect-* classes |
arbitraryColor | text-[#hex], bg-[#hex] |
arbitraryFontSize | text-[14px], text-[12pt] |
TailwindParseResult
The result object that handlers write to:Passing to render
Pass your parser torender or renderToBuffer:
tailwind.config file automatically.