Skip to content

Commit

Permalink
feat(hiccup): add XML_PROC & DOCTYPE_HTML constants
Browse files Browse the repository at this point in the history
- update tests
  • Loading branch information
postspectacular committed Aug 27, 2023
1 parent 19f290f commit 4ec98fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/hiccup/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ export const COMMENT = "__COMMENT__";
/** @internal */
export const CDATA = "!CDATA";

/**
* XML processing instruction in hiccup format.
*
* @remarks
* Translates to `<?xml version="1.0" encoding="UTF-8"?>`
*/
export const XML_PROC = ["?xml", { version: "1.0", encoding: "UTF-8" }];

/**
* `<!DOCTYPE html>` in hiccup format
*/
export const DOCTYPE_HTML = ["!DOCTYPE", "html"];

/** @internal */
export const NO_SPANS: {
[id: string]: number;
Expand Down
5 changes: 3 additions & 2 deletions packages/hiccup/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Atom } from "@thi.ng/atom";
import { foaf } from "@thi.ng/prefixes";
import { group } from "@thi.ng/testament";
import * as assert from "assert";
import { serialize } from "../src/index.js";
import { DOCTYPE_HTML, XML_PROC, serialize } from "../src/index.js";

const _check = (a: any, b: any) => assert.strictEqual(serialize(a), b);

Expand Down Expand Up @@ -331,8 +331,9 @@ group("serialize", {
`<a><b>bbb</b></a>`
),

...check("doctype", ["!DOCTYPE", "html"], "<!DOCTYPE html>\n"),
...check("doctype_html", DOCTYPE_HTML, "<!DOCTYPE html>\n"),

...check("xml_proc", XML_PROC, `<?xml version="1.0" encoding="UTF-8"?>\n`),
...check(
"?xml",
["?xml", { version: "1.0", standalone: "yes" }],
Expand Down

0 comments on commit 4ec98fd

Please sign in to comment.