npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

html-styles-inliner-cli

v1.2.5

Published

Command line tool, that inlines styles from the provided html file. This tool inlines styles from both <styles /> and <link /> tags

Downloads

3

Readme

html-styles-inliner-cli

CLI tool, that makes it possible to inline styles inside of the html file. html-styles-inliner-cli inlines the styles with the usage of both <link> and <style/> tags.

Table of contents

Instalation

using npm:

npm install html-css-inliner-cli

Usage

inline --input <path to html file> --output <path, where the file will be generated>

Example

inline --input ./index.html --output ./build/another-directory/inlinedIndex.html

Note

You can eiter use command using either the inline and html-styles-inliner-cli as the name of the command. eg.:

inline --input ./index.html --output ./inlined.html
html-styles-inliner-cli --input ./index.html --output ./inlined.html

The execution of those 2 commands will have the exact same results.

Options

-i, --input <path> (required)

path to the html file, which styles you need to inline.

-o, --output <path> (optional)

path, where the html file, with inlined styles, will be generated.

Note

If no path is specified, then the file will be generated in the same directory as the original file. Generated file will have the same name as the original file, but with the prefix of "inlined-".

For example, if the input file path is ./public/index.html then the file will be generated as ./public/inlined-index.html

So the following command:

inline --input ./public/index.html

has the same results as

inline --input ./public/index.html --output ./public/inlined-index.html

Examples

file structure:

- partials
    > index.html
    > styles
        > main.css

index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Example usage of html-styles-inliner-cli</title>
    <link rel="stylesheet" href="./styles/main.css" />
  </head>
  <body>
    <div class="container">
      <p class="container--text">Example</p>
    </div>
  </body>
</html>

main.css:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  background-color: #192841;
  color: #fff;
}

.container {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 0.75rem 1rem;
  transform: translate(-50%, -50%);
  background-color: #2a3f64;
  border-radius: 0.5rem;
}

.container--text {
  font-size: 1.15rem;
}

Command:

inline --input partials/index.html --output public/inlined-index.html

Will result in:

file structure:

- partials
    > index.html
    > styles
        > main.css
- public
    > inlined-index.html

Generated inlined-index.html:

<!DOCTYPE html>
<html lang="en" style="box-sizing: border-box; margin: 0; padding: 0;">
  <head style="box-sizing: border-box; margin: 0; padding: 0;">
    <meta
      charset="UTF-8"
      style="box-sizing: border-box; margin: 0; padding: 0;"
    />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0"
      style="box-sizing: border-box; margin: 0; padding: 0;"
    />
    <title style="box-sizing: border-box; margin: 0; padding: 0;">
      Example usage of html-styles-inliner-cli
    </title>
  </head>
  <body
    style="background-color: #192841; box-sizing: border-box; color: #fff; margin: 0; min-height: 100vh; padding: 0;"
  >
    <div
      class="container"
      style="background-color: #2a3f64; border-radius: 0.5rem; box-sizing: border-box; left: 50%; margin: 0; padding: 0.75rem 1rem; position: absolute; top: 50%; transform: translate(-50%, -50%);"
    >
      <p
        class="container--text"
        style="box-sizing: border-box; font-size: 1.15rem; margin: 0; padding: 0;"
      >
        Example
      </p>
    </div>
  </body>
</html>

Current support

Currently html-css-inliner-cli does not support inlining styles, that are being imported with the url, not the local path.

For example, if the file contains link tag like that: <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">, then it won't work.

But if the link tag looks like that: <link rel="stylesheet" href="styles/bootstrap/4.3.1/css/bootstrap.min.css">, then it should work.

Future changes

  • Allowing inlining of the styles with the URL import,
  • Better error detection,
  • ~~Optimization of the args reading~~ ✔️,
  • ~~Shorter substitute for the CLI options. Eg.: --input would be also allowed as -i~~ ✔️,
  • Tests for the development purposes.

License

html-css-inliner-cli is released under the MIT License.