The parser module (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/BaselAshraf81/holystitch/llms.txt
Use this file to discover all available pages before exploring further.
pipeline/parser.ts) reads a raw Stitch HTML document and extracts everything the pipeline needs to generate a React project: font links, custom CSS, the Tailwind theme config, and a full hierarchical component tree built from HTML comment markers.
parseStitchHtml
StitchParseResult.
Component extraction algorithm
Stitch embeds<!-- ComponentName --> comment markers throughout the HTML at every level of nesting. The parser uses htmlparser2 with character position tracking to locate these markers and build a component tree:
- Scan sibling nodes for uppercase HTML comments (
<!-- TopNavBar -->,<!-- HeroSection -->, etc.). - Each comment “claims” the next sibling block element as its component body.
- After claiming an element, the parser recurses into it to find nested sub-components — producing a tree, not just a flat list.
- Only root components (depth 0, no parent) appear in
pageBodyHtml. Structural wrappers like<main>and<section>that don’t have a comment marker are preserved in the page file.
| Raw comment | Normalized name |
|---|---|
TopNavBar from JSON mapping | TopNavBar |
Entry 1: Latest | Entry1 |
Bold Footer CTA | BoldFooterCta |
HeroSection - dark | HeroSection |
<div> spacers from becoming empty components.
Return type: StitchParseResult
Font links and custom CSS extracted from the
<head>.The Tailwind configuration extracted from a
<script id="tailwind-config"> block or any <script> containing tailwind.config. Returns null if no config script is found.All components extracted from the HTML, in tree order (parent before children). Each component has its direct child components replaced by
<ChildName /> placeholders in its html field.The page body HTML with all root components replaced by
<ComponentName /> placeholders. Structural wrappers (<main>, <nav>, etc.) that wrap components without their own comment marker are preserved. This becomes the JSX inside the page file’s return statement.Names of root-level components only. These are the names the page file imports — child components are imported by their parent component files instead.
Raw
<body> content, unmodified. Used as a fallback when no comment markers are found — the entire body becomes a single component named after the screen.extractGoogleFonts
<link href="..."> tags and in @import url(...) statements — and returns structured font specifications for use with next/font/google.
The function deduplicates by font family name, so a font referenced via both a <link> tag and a CSS @import is returned only once.
Return type: GoogleFontSpec[]
Human-readable font family name with spaces, e.g.
"Inter", "JetBrains Mono", "Roboto Condensed". Spaces are decoded from + in the Google Fonts URL.Array of weight strings to pass to
next/font/google. If the URL uses a variable weight range (e.g. wght@100..900), the weights default to ["400", "500", "600", "700", "800"]. If specific weights are listed (e.g. wght@400;700), those are used directly. If no weight spec is present, defaults to ["400"].Always
["latin"]. Stitch designs target Latin character sets.camelCase identifier derived from the family name — used as the variable name in the generated
layout.tsx import. The first character is lowercased and spaces are converted to camelCase:| Family | Variable |
|---|---|
Inter | inter |
JetBrains Mono | jetBrainsMono |
Roboto Condensed | robotoCondensed |
DM Sans | dMSans |
Icon font handling
Font families in the Material Symbols and Material Icons families ("Material Symbols Outlined", "Material Icons", etc.) are excluded from GoogleFontSpec results. These fonts cannot be loaded via next/font/google and must remain as CDN @import links in globals.css. The pipeline filters them out before calling extractGoogleFonts for the next/font/google optimization path.
Example
next/font/google imports in app/layout.tsx:
The
next/font/google optimization path replaces @import url(...) Google Fonts calls in globals.css entirely. The original <link> tags from the Stitch HTML are not written to the output HTML — Next.js inlines the optimized font during build instead.