All Projects → Stranger6667 → css-inline

Stranger6667 / css-inline

Licence: MIT license
Inline CSS into style attributes

Programming Languages

rust
11053 projects
python
139335 projects - #7 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to css-inline

material-yew
Yew wrapper for Material Web Components
Stars: ✭ 116 (+20.83%)
Mutual labels:  wasm
Uno.Wasm.Bootstrap
A simple nuget package to run C# code in a WASM-compatible browser
Stars: ✭ 242 (+152.08%)
Mutual labels:  wasm
SaltyNES
A NES emulator in WebAssembly
Stars: ✭ 69 (-28.12%)
Mutual labels:  wasm
wasm-bindgen-webcam-stream
A small example on how to get webcam stream on rust-wasm
Stars: ✭ 11 (-88.54%)
Mutual labels:  wasm
wasm-cn
[翻译中] WebAssembly 中文文档
Stars: ✭ 22 (-77.08%)
Mutual labels:  wasm
arima
ARIMA, SARIMA, SARIMAX and AutoARIMA models for time series analysis and forecasting in the browser and Node.js
Stars: ✭ 31 (-67.71%)
Mutual labels:  wasm
rust-monaco
Rust WASM bindings for the Monaco Editor
Stars: ✭ 23 (-76.04%)
Mutual labels:  wasm
geopattern-rs
Beautiful generative geometric images from a string, based on @jasonlong's geo_pattern, with a WASM demo
Stars: ✭ 44 (-54.17%)
Mutual labels:  wasm
zero-graphics
Application framework based on OpenGL ES 2.0. Runs on desktop machines, Android phones and the web
Stars: ✭ 72 (-25%)
Mutual labels:  wasm
Astar
The dApp hub for blockchains of the future
Stars: ✭ 533 (+455.21%)
Mutual labels:  wasm
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-79.17%)
Mutual labels:  wasm
pico-ml
A toy programming language which is a subset of OCaml.
Stars: ✭ 36 (-62.5%)
Mutual labels:  wasm
frontend-image-encode
This is script and implementation of frontend image compression, convert, rotate, resize based on codecs in Google/Squoosh. All codecs are copy from the Squoosh repo without modifying. if you want to pre-process images before uploading them to the server, please use this repo for reference
Stars: ✭ 51 (-46.87%)
Mutual labels:  wasm
proxy-wasm-cpp-host
WebAssembly for Proxies (C++ host implementation)
Stars: ✭ 55 (-42.71%)
Mutual labels:  wasm
wasp
WebAssembly module decoder in C++
Stars: ✭ 88 (-8.33%)
Mutual labels:  wasm
reactr
Function scheduler for Go & WebAssembly
Stars: ✭ 264 (+175%)
Mutual labels:  wasm
eosio-rust
EOSIO SDK for Rust – APIs for building smart contracts on EOSIO blockchains in Rust
Stars: ✭ 93 (-3.12%)
Mutual labels:  wasm
blazor-adminlte
This project adapts ADMINLTE 3 so the components can be used from dotnet core Blazor / Server / Web Assembly
Stars: ✭ 182 (+89.58%)
Mutual labels:  wasm
wasm-toolchain
WebAssembly toolchain
Stars: ✭ 34 (-64.58%)
Mutual labels:  wasm
rocket-yew-starter-pack
Example boilerplate for websites in pure Rust
Stars: ✭ 77 (-19.79%)
Mutual labels:  wasm

css-inline

ci Crates.io docs.rs gitter

A crate for inlining CSS into HTML documents. It is built with Mozilla's Servo project components.

When you send HTML emails, you need to use "style" attributes instead of "style" tags. For example, this HTML:

<html>
    <head>
        <title>Test</title>
        <style>h1 { color:blue; }</style>
    </head>
    <body>
        <h1>Big Text</h1>
    </body>
</html>

Will be turned into this:

<html>
    <head><title>Test</title></head>
    <body>
        <h1 style="color:blue;">Big Text</h1>
    </body>
</html>

To use it in your project add the following line to your dependencies section in the project's Cargo.toml file:

css-inline = "0.8"

Minimum Supported Rust Version is 1.54.

Usage

const HTML: &str = r#"<html>
<head>
    <title>Test</title>
    <style>h1 { color:blue; }</style>
</head>
<body>
    <h1>Big Text</h1>
</body>
</html>"#;

fn main() -> Result<(), css_inline::InlineError> {
    let inlined = css_inline::inline(HTML)?;
    // Do something with inlined HTML, e.g. send an email
    Ok(())
}

Features & Configuration

css-inline can be configured by using CSSInliner::options() that implements the Builder pattern:

const HTML: &str = "...";

fn main() -> Result<(), css_inline::InlineError> {
    let inliner = css_inline::CSSInliner::options()
        .load_remote_stylesheets(false)
        .build();
    let inlined = inliner.inline(HTML);
    // Do something with inlined HTML, e.g. send an email
    Ok(())
}
  • inline_style_tags. Whether to inline CSS from "style" tags. Default: true
  • remove_style_tags. Remove "style" tags after inlining. Default: false
  • base_url. Base URL to resolve relative URLs. Default: None
  • load_remote_stylesheets. Whether remote stylesheets should be loaded or not. Default: true
  • extra_css. Additional CSS to inline. Default: None

Bindings

There are bindings for Python and WebAssembly in the bindings directory.

Command Line Interface

css-inline provides a command-line interface:

css-inline --help

css-inline inlines CSS into HTML documents.

USAGE:
   css-inline [OPTIONS] [PATH ...]
   command | css-inline [OPTIONS]

ARGS:
    <PATH>...
        An HTML document to process. In each specified document
        "css-inline" will look for all relevant "style" and "link"
        tags, will load CSS from them and then inline it to the
        HTML tags, according to the corresponding CSS selectors.
        When multiple documents are specified, they will be
        processed in parallel, and each inlined file will be saved
        with "inlined." prefix. E.g., for "example.html", there
        will be "inlined.example.html".

OPTIONS:
    --inline-style-tags
        Whether to inline CSS from "style" tags. The default
        value is `true`. To disable inlining from "style" tags
        use `--inline-style-tags=false`.

    --remove-style-tags
        Remove "style" tags after inlining.

    --base-url
        Used for loading external stylesheets via relative URLs.

    --load-remote-stylesheets
        Whether remote stylesheets should be loaded or not.

    --extra-css
        Additional CSS to inline.

Extra materials

If you want to know how this library was created & how it works internally, you could take a look at these articles:

Support

If you have anything to discuss regarding this library, please, join our gitter!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].