Crystal bindings for css-inline — a high-performance library for inlining CSS into HTML. Perfect for preparing HTML emails or embedding HTML into third-party web pages.
- Rust toolchain (the C library is compiled from source during installation)
Add the dependency to your shard.yml:
dependencies:
css-inline:
github: osbre/css-inlineRun shards install — this will automatically build the native library.
require "css-inline"
# Inline CSS from <style> tags
html = "<html><head><style>h1 { color: blue; }</style></head><body><h1>Hello</h1></body></html>"
result = CssInline.inline(html)
# => <html><head></head><body><h1 style="color: blue;">Hello</h1></body></html>
# Inline a CSS fragment
result = CssInline.inline_fragment("<h1>Hello</h1>", "h1 { color: blue; }")
# => <h1 style="color: blue;">Hello</h1>inliner = CssInline::CSSInliner.new(
keep_style_tags: true,
extra_css: "h1 { font-size: 2em; }",
minify_css: true,
)
result = inliner.inline(html)All available options:
Reuse parsed stylesheets across multiple calls:
cache = CssInline::StylesheetCache.new(size: 64)
inliner = CssInline::CSSInliner.new(cache: cache)
inliner.inline(html1)
inliner.inline(html2) # reuses cached stylesheets- Fork it (https://github.com/osbre/css-inline/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
- Ostap Brehin - creator and maintainer
