Skip to content

diyorbek/htms

Repository files navigation

HTMS - Hypertext Markup Stylesheets

A small compiler that turns SCSS-like markup into HTML. Selectors become tags, properties become inline styles, and nested rules become nested elements.

Build

Only a C++20 compiler (g++) is required. The lexer and parser are pre-generated and committed to the repo.

make

This produces an htms binary in the project root.

To regenerate the lexer/parser from lexer.l and parser.y install flex and bison (≥ 3.8), then:

make regen-clean && make

macOS note: the bundled bison is too old. Install with brew install bison and put it ahead of /usr/bin on PATH.

Usage

htms reads source from stdin and writes HTML to stdout.

echo "div { backgroud: green; span { color: white; } }" | ./htms

Output:

<div style="backgroud: green;">
  <span style="color: white;"> </span>
</div>

Syntax

selector {
  property: value;

  nested-selector {
    property: 23px;
  }
}
  • Selectors — plain identifiers become HTML tag names. .foo becomes <div class="foo">; #foo becomes <div id="foo">.
  • Propertiesname: value;. They become entries in the element's style attribute.
  • Values — strings ('…' / "…"), numbers with optional unit suffix (23px, -1), identifiers, or space-separated combinations.
  • Nested rules — emit child elements inside the parent.

Tests

make && ./test.sh

Green lines pass, red lines fail.

License

MIT

About

Hypertext Markup Stylesheets

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors