MCPcopy Create free account
hub / github.com/Alphanimble/htmlstream / rehtml

Function rehtml

src/rehtml/index.ts:50–88  ·  view source on GitHub ↗
(
  input: string,
  options?: RehtmlOptions,
)

Source from the content-addressed store, hash-verified

48 * 3. Split into stable blocks + live tail for incremental rendering
49 */
50export function rehtml(
51 input: string,
52 options?: RehtmlOptions,
53): RehtmlResult {
54 const opts = { ...defaultOptions, ...options };
55
56 if (!input || typeof input !== "string") {
57 return {
58 html: "",
59 stable: [],
60 live: "",
61 hadIncompleteTag: false,
62 };
63 }
64
65 let html = input;
66 let hadIncompleteTag = false;
67
68 if (opts.stripIncomplete) {
69 const stripped = stripIncompleteTag(html);
70 hadIncompleteTag = stripped.length !== html.length;
71 html = stripped;
72 }
73
74 // Split before auto-closing — only genuinely closed blocks become stable
75 const { stable, live } = opts.splitBlocks
76 ? splitHtmlIntoBlocks(html)
77 : { stable: [] as string[], live: html };
78
79 const close = (chunk: string) =>
80 opts.closeTags ? closeOpenTags(chunk) : chunk;
81
82 return {
83 html: close(html),
84 stable: stable.map(close),
85 live: close(live),
86 hadIncompleteTag,
87 };
88}
89
90/** Re-export DOMPurify config type for convenience */
91export type SanitizeConfig = Config;

Callers 8

StreamHtmlFunction · 0.90
rehtml.test.tsFile · 0.90
streamSnapshotsFunction · 0.90

Calls 3

stripIncompleteTagFunction · 0.90
splitHtmlIntoBlocksFunction · 0.90
closeFunction · 0.85

Tested by

no test coverage detected