Skip to content

Releases: Cascades-CSS/CSS-to-HTML

Version 0.8.3

04 Apr 23:38
Compare
Choose a tag to compare
Version 0.8.3 Pre-release
Pre-release
  • Updates various dependencies (a6e7b22)

Version 0.8.2

26 Feb 20:06
Compare
Choose a tag to compare
Version 0.8.2 Pre-release
Pre-release

Version 0.8.1

05 Dec 19:02
Compare
Choose a tag to compare
Version 0.8.1 Pre-release
Pre-release

Version 0.8.0

28 Sep 03:47
Compare
Choose a tag to compare
Version 0.8.0 Pre-release
Pre-release

Static Script

CSS-to-HTML can now be used as a static script.
To do so, download css-to-html.js from the assets section below. Then include the script in your site:

<script src="path/to/css-to-html.js"></script>

<script>
const css = 'p { color: purple; }';

cssToHtml(css).then(html => {
    console.log(html);
});
</script>

Make sure to check the releases page frequently for updates.

Version 0.7.1

25 Sep 20:54
Compare
Choose a tag to compare
Version 0.7.1 Pre-release
Pre-release

Version 0.7.0

09 Sep 20:03
Compare
Choose a tag to compare
Version 0.7.0 Pre-release
Pre-release

Nested Selectors

The CSS nesting module and the nesting selector are now supported. For example, the following CSS:

main {
    display: flex;

    & section {
        content: 'A';
    }

    .message:is(.warning) {
        color: orange;
    }
}

Will now produce:

<body>
    <main>
        <section>A</section>
    </main>
</body>

Version 0.6.2

20 May 19:41
Compare
Choose a tag to compare
Version 0.6.2 Pre-release
Pre-release

Updates DOMPurify dependency to 3.1.4, bringing with it support for Popover API attributes.

Version 0.6.1

15 May 21:12
Compare
Choose a tag to compare
Version 0.6.1 Pre-release
Pre-release

Fixes a bug that allowed certain element attributes to run external scripts before the element was actually added to the DOM.

Important

If you were already relying on the sanitization options provided in v0.6.0 it is recommended that you update to v0.6.1 immediately.

Version 0.6.0

14 May 10:02
Compare
Choose a tag to compare
Version 0.6.0 Pre-release
Pre-release

Sanitization

Generated HTML output is now sanitized by default. This should lower the risk of any XSS vulnerabilities arising from use with user generated or copy-pasted CSS. For example, the following CSS:

img[onload="console.log('foo')"] {
    content: 'malicious.png';
}

script {
    content: 'fetch("http://malicious.com/").then(() => alert(1));';
}

When un-sanitized will produce:

<body>
    <img src="malicious.png" onload="console.log('foo')">
    <script>
        fetch("http://malicious.com/").then(() => alert(1));
    </script>
</body>

But when sanitized will instead produce:

<body>
    <img src="malicious.png">
    <script></script>
</body>

Options

If you're using CSS-to-HTML as part of a framework or build process, elements like this may actually be desired. For cases like this, a new option has been added to configure the sanitization behaviour:

Option Values Description
sanitize all * Sanitize the generated HTML using DOMPurify.
imports Only sanitize the HTML generated from imported stylesheets.
off Don't sanitize the generated HTML.

Breaking Changes

Important

Because sanitization is enabled by default, certain CSS inputs may produce different HTML outputs than before.
It is recommended to double-check your use case before updating.

Version 0.5.0

11 Sep 05:47
0893116
Compare
Choose a tag to compare
Version 0.5.0 Pre-release
Pre-release

Async

The generator function now runs asynchronously. You can call it using the await keyword or .then():

const html = await cssToHtml(css);

Or:

cssToHtml(css).then(html => console.log(html));

Attributes

Attribute selectors are now supported. For example:

label[for="username"] input#username[type="text"][required] {
    content: 'Username';
    border-radius: 0.2em;
}

Will become:

<label for="username">
    <input id="username" type="text" placeholder="Username" required>
</label>

Imports

An imports option has been added.

Option Values Description
imports include Fetch imported stylesheets and include them in the HTML generation process.
style-only * Ignore @import rules when generating HTML.