@thi.ng/hiccup 5.2.25 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2025-01-21T15:46:53Z
3
+ - **Last updated**: 2025-01-22T08:39:43Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,15 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [5.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.3.0) (2025-01-22)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add special `INLINE` tag & `__escape` behavior attrib ([42e7717](https://github.com/thi-ng/umbrella/commit/42e7717))
17
+ - add `INLINE` tag & handling for embedded markup
18
+ - add `__escape` control attrib to enable/disable entity escaping (per element)
19
+ - add tests
20
+
12
21
  ### [5.2.11](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup@5.2.11) (2024-08-23)
13
22
 
14
23
  #### 🩹 Bug fixes
package/README.md CHANGED
@@ -37,6 +37,7 @@
37
37
  - [Component objects](#component-objects)
38
38
  - [Behavior control attributes](#behavior-control-attributes)
39
39
  - [Comments](#comments)
40
+ - [Inlined/embedded markup](#inlinedembedded-markup)
40
41
  - [XML / DTD processing instructions](#xml--dtd-processing-instructions)
41
42
  - [API](#api)
42
43
  - [serialize()](#serialize)
@@ -183,7 +184,7 @@ For Node.js REPL:
183
184
  const h = await import("@thi.ng/hiccup");
184
185
  ```
185
186
 
186
- Package sizes (brotli'd, pre-treeshake): ESM: 2.20 KB
187
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.24 KB
187
188
 
188
189
  ## Dependencies
189
190
 
@@ -391,7 +392,9 @@ serialize([div, {id: "foo"}, "bar"]);
391
392
 
392
393
  Also see
393
394
  [@thi.ng/hiccup-svg](https://github.com/thi-ng/umbrella/tree/develop/packages/hiccup-svg)
394
- for related functionality.
395
+ and
396
+ [@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/develop/packages/geom)
397
+ for related (and more advanced) functionality.
395
398
 
396
399
  ```ts tangle:export/readme-circles.js
397
400
  import { serialize } from "@thi.ng/hiccup";
@@ -554,11 +557,10 @@ Re-formatted HTML output:
554
557
 
555
558
  The sibling library
556
559
  [@thi.ng/hdom](https://github.com/thi-ng/umbrella/tree/develop/packages/hdom)
557
- supports components with basic life cycle methods (init, render,
558
- release). In order to support serialization of hdom component trees,
559
- hiccup too supports such components since version 2.0.0. However, for
560
- static serialization only the `render` method is of interest and others
561
- are ignored.
560
+ supports components with basic life cycle methods (init, render, release). To
561
+ support serialization of hdom component trees, hiccup too supports such
562
+ components since version 2.0.0. For static serialization only the `render`
563
+ method is of interest and others are ignored.
562
564
 
563
565
  ```js
564
566
  const component = {
@@ -573,6 +575,7 @@ serialize([component, "Hello world", "Body"]);
573
575
  The following attributes can be used to control the serialization
574
576
  behavior of individual elements / tree branches:
575
577
 
578
+ - **`__escape`** - boolean flag to enable/disable entity escaping
576
579
  - **`__skip`** - if true, skips serialization (also used by
577
580
  [@thi.ng/hdom](https://github.com/thi-ng/umbrella/tree/develop/packages/hdom))
578
581
  - **`__serialize`** - if false, skips serialization (hiccup only)
@@ -585,7 +588,7 @@ serialize(["div.container", ["div", { __skip: true }, "ignore me"]]);
585
588
  ### Comments
586
589
 
587
590
  Single or multiline comments can be included using the special `COMMENT`
588
- tag (`__COMMENT__`) (always WITHOUT attributes!).
591
+ tag (or `__COMMENT__`, always WITHOUT attributes!).
589
592
 
590
593
  ```ts
591
594
  import { COMMENT } from "@thi.ng/hiccup";
@@ -601,6 +604,22 @@ import { COMMENT } from "@thi.ng/hiccup";
601
604
  // -->
602
605
  ```
603
606
 
607
+ ### Inlined/embedded markup
608
+
609
+ Pre-serialized markup can be inlined without any further processing using the
610
+ special `INLINE` tag (or `__INLINE__`, always WITHOUT attributes!):
611
+
612
+ ```js
613
+ import { INLINE, serialize } from "@thi.ng/hiccup";
614
+
615
+ serialize(
616
+ ["div", {}
617
+ [INLINE, "<h3>Inlined &amp; Embedded</h3><p>Lorem ipsum...</p>"]
618
+ ]
619
+ );
620
+ // <div><h3>Inlined &amp; Embedded</h3><p>Lorem ipsum...</p></div>
621
+ ```
622
+
604
623
  ### XML / DTD processing instructions
605
624
 
606
625
  Currently, the only processing / DTD instructions supported are:
package/api.d.ts CHANGED
@@ -7,6 +7,8 @@ export declare const RE_TAG: RegExp;
7
7
  /** @internal */
8
8
  export declare const COMMENT = "__COMMENT__";
9
9
  /** @internal */
10
+ export declare const INLINE = "__INLINE__";
11
+ /** @internal */
10
12
  export declare const CDATA = "!CDATA";
11
13
  /** @internal */
12
14
  export declare const DOCTYPE = "!DOCTYPE";
package/api.js CHANGED
@@ -7,6 +7,7 @@ const PROC_TAGS = {
7
7
  };
8
8
  const RE_TAG = /^([^\s.#]+)(?:#([^\s.#]+))?(?:\.([^\s#]+))?$/;
9
9
  const COMMENT = "__COMMENT__";
10
+ const INLINE = "__INLINE__";
10
11
  const CDATA = "!CDATA";
11
12
  const DOCTYPE = "!DOCTYPE";
12
13
  const XML_PROC = ["?xml", { version: "1.0", encoding: "UTF-8" }];
@@ -42,6 +43,7 @@ export {
42
43
  COMMENT,
43
44
  DOCTYPE,
44
45
  DOCTYPE_HTML,
46
+ INLINE,
45
47
  NO_CLOSE_EMPTY,
46
48
  NO_SPANS,
47
49
  PROC_TAGS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/hiccup",
3
- "version": "5.2.25",
3
+ "version": "5.3.0",
4
4
  "description": "HTML/SVG/XML serialization of nested data structures, iterables & closures",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -132,5 +132,5 @@
132
132
  ],
133
133
  "year": 2016
134
134
  },
135
- "gitHead": "22f6d518aed5951bb37b406c8ae85a6c3e6be517\n"
135
+ "gitHead": "363db3998a14ddfd7a82f3039d8ca9681581e284\n"
136
136
  }
package/serialize.js CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  ATTRIB_JOIN_DELIMS,
12
12
  CDATA,
13
13
  COMMENT,
14
+ INLINE,
14
15
  NO_CLOSE_EMPTY,
15
16
  NO_SPANS,
16
17
  PROC_TAGS,
@@ -38,13 +39,14 @@ const __serializeElement = (tree, opts, path) => {
38
39
  tag.render.apply(null, [opts.ctx, ...tree.slice(1)]),
39
40
  opts,
40
41
  path
41
- ) : tag === COMMENT ? __serializeComment(tree) : tag == CDATA ? __serializeCData(tree) : isString(tag) ? __serializeTag(tree, opts, path) : isNotStringAndIterable(tree) ? __serializeIter(tree, opts, path) : illegalArgs(`invalid tree node: ${tree}`);
42
+ ) : tag === COMMENT ? __serializeComment(tree) : tag === INLINE ? __serializeInline(tree) : tag == CDATA ? __serializeCData(tree) : isString(tag) ? __serializeTag(tree, opts, path) : isNotStringAndIterable(tree) ? __serializeIter(tree, opts, path) : illegalArgs(`invalid tree node: ${tree}`);
42
43
  };
43
44
  const __serializeTag = (tree, opts, path) => {
44
45
  tree = normalize(tree);
45
46
  const attribs = tree[1];
46
47
  if (attribs.__skip || attribs.__serialize === false) return "";
47
48
  opts.keys && attribs.key === void 0 && (attribs.key = path.join("-"));
49
+ if (attribs.__escape != null) opts = { ...opts, escape: attribs.__escape };
48
50
  const tag = tree[0];
49
51
  const body = tree[2] ? __serializeBody(tag, tree[2], opts, path) : !VOID_TAGS[tag] && !NO_CLOSE_EMPTY[tag] ? `></${tag}>` : PROC_TAGS[tag] || "/>";
50
52
  return `<${tag}${__serializeAttribs(attribs, opts)}${body}`;
@@ -93,6 +95,7 @@ ${tree.slice(1).map((x) => " " + x).join("\n")}
93
95
  ` : `
94
96
  <!-- ${tree[1]} -->
95
97
  `;
98
+ const __serializeInline = (tree) => tree.slice(1).join("");
96
99
  const __serializeCData = (tree) => `<![CDATA[
97
100
  ${tree.slice(1).join("\n")}
98
101
  ]]>`;