HCL Landing Page Snippet Extractor (lib/example.ts)

clawpatrol · site/src/lib/example.ts · typescript · MIT
dev-tools, infra, lang:hcl, tag:snippet

Strips harness scaffolding from HCL example files to render clean display snippets on landing pages. Use when displaying documentation code samples.

// Source: https://github.com/denoland/clawpatrol | License: MIT | Copyright 2026 Deno Land Inc
// Provided via justclaw.it.com; keep this notice with the code.
// Strip the harness portion from an HCL example file.
// Landing-page snippets in examples/ contain a display snippet
// followed by a "# ===== harness =====" marker and config
// scaffolding that makes the file pass `clawpatrol validate`.
// Landing page sections render only what’s above the marker.

export function snippet(source: string): string {
  const i = source.indexOf("# ===== harness =====");
  return (i === -1 ? source : source.slice(0, i)).trim();
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key