Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Generate HTML from CSS rules. Compatible with Node.js and the jsdom module to serve up your CSS stylesheets as HTML styleguides.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
docs
specs
.gitignore
README.md
css2html.js
css2html.min.js
parserlib.js

README.md

css2html

Generate HTML from CSS rules. Compatible with Node.js and the jsdom module to serve up your CSS stylesheets as HTML styleguides.

Features

  • Should support all valid CSS selectors: type, universal, attribute, class, id, pseudo, descendant, child, sibling etc.
  • Options to populate generated HTML with placeholder content.
  • 190+ unit tests with QUnit.

Syntax

css2html(css, [options])

Arguments

  1. css - (string) CSS rules.
  2. options - (object, optional) Options object.

Options

  • autoExpand - (bool: default true) Whether to expand selectors into valid DOM trees.
  • dataAttr - (bool: default false) Whether to set an HTML5 data attribute 'data-selector' with the value of the CSS selector.
  • debug - (bool: default false) Whether to log debugging/error messages to a console (if one is available).
  • out - (string: default nodes) Either 'nodes' to output HTML nodes, or 'html' to output HTML text.
  • populate - (bool: default false) Whether to populate HTML with placeholder text.

Node.js

To use with Node.js ensure the jsdom module has been installed and import into your Node.js module:

var css2html = require('./lib/css2html.js');
Something went wrong with that request. Please try again.