Giter Club home page Giter Club logo

inline-sass's Introduction

Inline Sass

npm version Module type: ESM

Inline Sass stylesheets into HTML style attributes โ€” useful in emails and other lo-fi HTML authoring situations.

A thin wrapper for inline-css and Sass.

Use

file.html:

<!DOCTYPE html>
<html>
  <head>
    <title>Example</title>
    <link rel="stylesheet" href="sass.scss" />
  </head>
  <body>
    <div id="ex">Hello world</div>
  </body>
</html>

sass.scss:

#ex {
  color: red;
}
import inlineSass from 'inline-sass';

inlineSass('/path/to/file.html')
  .then((result) => console.log(String(result)))
  .catch(console.error);

Console:

<!DOCTYPE html>
<html>
  <head>
    <title>Example</title>
  </head>
  <body>
    <div id="ex" style="color: red;">Hello world</div>
  </body>
</html>

API

Passes through all arguments to inline-css. Plus:

deleteTempDir

Type: boolean
Default: true

Whether or not to delete the temporary directory of transpiled CSS.

How it works

inline-sass transpiles any linked .sass or .scss files into a temporary directory, re-writing the <link> tags in the HTML to refer to the temporary .css files (but storing the original href in the data-original-href attribute). At the end of the run, the temporary directory is deleted. Unless overridden by another value, the directory containing the HTML file will be passed as the url option to inline-css.

It is also possible to pass literal HTML as the first argument to inline-sass, in which case the options object must contain an url value to act as a basepath for any relative references in the <link> tags:

import inlineSass from `inline-sass`;

inlineSass(
  `<html>
    <head
      <title>Literal HTML</title>
      <link rel="stylesheet" href="styles/sass.scss"/>
    </head>
    <body>
      <div id="ex">Hello World</div>
    </body>
  </html>`,
  'file:///path/to/my'
)
  .then(result => console.log(String(result)))
  .catch(console.error);

In this case, Sass would attempt to transpile the file /path/to/my/styles/sass.scss. A concrete example of this approach can be found in @battis/inline-sass-to-clipboard.

inline-sass's People

Contributors

battis avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

atlinx

inline-sass's Issues

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.