Giter Club home page Giter Club logo

tailwindinline's Introduction

Why?

I use this library to build a document that looks like the PDF I'd like with tailwind, use the frontend framework I'm using at the moment to insert data and/or graphs (that render to svg, I recommend apache echarts for this rendering functionality) and then output pure HTML from whatever format the framework uses (in react this is accomplished with ReactDOMServer.renderToString(component)), convert it to inline styled html with this package, and then send the pure html file to a html-to-pdf api like api2pdf (which while unaffiliated seems relatively cheap).

It enables you to at runtime convert from a html string with tailwind classes to a html string inline styled. I find this easier than supplying the PDF API with two files since I haven't found the most reliable pdf generation APIs.

Questions/comments/improvements/suggestions? Contributions welcome.

Params

  • config: Optional path to your tailwind.config.js that you'd like to use with this library. Useful if you have custom theme extensions, like colors or fonts. (relative path)
  • custom: Custom css (string)

Installation

npm install tailwindinline

import TailwindToInline from 'tailwindinline'
const twi = new TailwindInline({ config: './path/to/tailwind.config', custom: ".button: { background-color: 'red' }" })

const htmlWithInlineStyles = twi.convert('<div class="pt-2 pb-[40px] border-2 border-[#0f0]"></div>')
/*
<div 
	class="pt-2 pb-[40px] border-2 border-[#0f0]" 
	style="padding-top: 0.5rem; padding-bottom: 40px; border-width: 2px; border-color: #0f0; box-sizing: border-box;"
></div>

Tailwindinline

(Tries to) append a style attribute with computed tailwind classes to the end of each html tag that contained them.

Planned additions

  • remove unneeded styles from classList.json (hover, focus)
  • fix syntax of some classnames in classList.json (ex: placeholder:moz-[...])
  • custom tailwind classes
  • add all tailwind auto-added classes (those that makes sense for this usage)
  • import and use a custom tailwindconfig
  • implement more consistent regex file
  • rewrite this readme.md

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.