@hedia/html
Install
$ npm install @hedia/html -E
Usage
import { attr, comment, document, render } from "@hedia/html";
import { a, body, h1, head, html, img, meta, p, title } from "@hedia/html/elements";
import { content, name, style } from "@hedia/html/attributes";
render(
document(
html(
lang("en"),
comment("head --"),
head(
title("HTML | Hedia"),
meta(
name("description"),
content("Hedia HTML Renderer."),
),
meta(
name("keywords"),
content("hedia,html,rendering."),
),
),
body(
h1("HTML", isItMonday() && p("It is monday")),
p(style("font-weight: bold"), "Hedia HTML Renderer."),
img(
src(
"https://www.hedia.co/wp-content/uploads/2017/03/hedia_blue.png",
),
),
a(href("https://hedia.co/"), "Hedia"),
),
),
),
);
Outputs:
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML | Hedia</title>
<meta name="description" content="Hedia HTML Renderer.">
<meta name="keywords" content="hedia,html,rendering.">
</head>
<body>
<h1>HTML</h1>
<p style="font-weight: bold">Hedia HTML Renderer.</p>
<img src="https://www.hedia.co/wp-content/uploads/2017/03/hedia_blue.png">
<a href="https://hedia.co/">Hedia</a>
</body>
</html>
API
renderToBuffer
Renders the Document
, Element
or Text
node to a Buffer
with UTF-8 encoding.
import { attr, document, renderToBuffer } from "@hedia/html";
import { body, head, html, } from "@hedia/html/elements";
const buffer = renderToBuffer(
document(
html(
head(),
body(),
),
),
);
renderToReadable
Renders the Document
, Element
or Text
node to a Readable
64kb at a time.
import { document, renderToReadable } from "@hedia/html";
import { body, head, html, } from "@hedia/html/elements";
const readable = renderToReadable(
document(
html(
head(),
body(),
),
),
);
process.stdout.pipe(readable);
Build
$ npm run build
Test
$ npm test