# huozhi/sugar-high architecture

> Architecture diagram of the GitHub repository huozhi/sugar-high, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/huozhi/sugar-high
- Repository: https://github.com/huozhi/sugar-high

## Overview

Sugar High is a lightweight, DOM-free syntax highlighter that parses source into tokens and renders highlighted HTML, with built-in language configurations and React and Remark integrations. The primary workflow is code input → language configuration and parsing → HTML generation or framework rendering. The repository also includes a product website and release-video composition. Edges reflect README statements or source-index references; some website internals are unsampled, so their connections are limited to documented or indexed references.

Main entry points: [`packages/react/src/code/code.tsx`](https://github.com/huozhi/sugar-high/blob/main/packages/react/src/code/code.tsx) (React Code block), [`packages/sugar-high/lib/core.js`](https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/core.js) (Parser and tokenizer), [`packages/sugar-high/lib/index.js`](https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/index.js) (Highlight API), [`apps/release-video/src/scenes`](https://github.com/huozhi/sugar-high/tree/main/apps/release-video/src/scenes) (Video scenes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_engine["Highlighting engine"]
  node_api["Highlight API<br/>[index.js]"]
  node_parser["Parser and tokenizer<br/>[core.js]"]
  node_html["Token and HTML rendering<br/>[shared.js]"]
end

subgraph group_languages["Language support"]
  node_language_map["Language aliases<br/>[lang.js]"]
  node_grammars["Language configurations"]
  node_runtime["Language runtime rules"]
end

subgraph group_integrations["Framework integrations"]
  node_react_code["React Code block<br/>[code.tsx]"]
  node_react_editor["React Editor<br/>[editor.tsx]"]
  node_react_theme["React theme styling<br/>[theme.ts]"]
  node_react_tree["React file tree<br/>[index.tsx]"]
  node_remark["Remark plugin<br/>[index.ts]"]
end

subgraph group_site["Website and media"]
  node_site_home["Product homepage<br/>[page.tsx]"]
  node_site_editor["Interactive editor<br/>[live-editor.tsx]"]
  node_site_presets["Editor theme presets"]
  node_site_capture["Code capture page<br/>[capture-client.tsx]"]
  node_site_react["React product guide<br/>[page.tsx]"]
  node_site_remark["Remark product guide<br/>[page.tsx]"]
  node_release_main["Release video timeline<br/>[main.tsx]"]
  node_release_scenes["Video scenes"]
  node_release_theme["Video theme styling<br/>[plate-css.ts]"]
end

node_developer(("Code consumer"))

node_developer -->|"calls highlight"| node_api
node_api -->|"parses source"| node_parser
node_parser -->|"renders tokens"| node_html
node_api -->|"normalizes aliases"| node_language_map
node_developer -->|"configures parse"| node_parser
node_developer -->|"selects configuration"| node_grammars
node_runtime -->|"provides token rules"| node_parser
node_react_code -->|"parses code"| node_parser
node_react_code -->|"generates markup"| node_html
node_react_editor -->|"uses code view"| node_react_code
node_react_code -->|"applies theme"| node_react_theme
node_react_tree -->|"applies theme"| node_react_theme
node_remark -->|"normalizes fences"| node_language_map
node_site_home -->|"embeds editor"| node_site_editor
node_site_home -->|"provides editor presets"| node_site_presets
node_site_capture -->|"reads theme presets"| node_site_presets
node_site_capture -->|"renders code"| node_react_code
node_site_react -->|"demonstrates component"| node_react_code
node_site_react -->|"demonstrates component"| node_react_editor
node_site_remark -->|"demonstrates plugin"| node_remark
node_release_main -->|"sequences scenes"| node_release_scenes
node_release_scenes -->|"uses token styles"| node_release_theme
node_release_scenes -->|"highlights examples"| node_api

click node_api "https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/index.js"
click node_parser "https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/core.js"
click node_html "https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/shared.js"
click node_language_map "https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/lang.js"
click node_grammars "https://github.com/huozhi/sugar-high/tree/main/packages/sugar-high/lib/lang"
click node_runtime "https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/presets/javascript-runtime.js"
click node_react_code "https://github.com/huozhi/sugar-high/blob/main/packages/react/src/code/code.tsx"
click node_react_editor "https://github.com/huozhi/sugar-high/blob/main/packages/react/src/editor/editor.tsx"
click node_react_theme "https://github.com/huozhi/sugar-high/blob/main/packages/react/src/theme.ts"
click node_react_tree "https://github.com/huozhi/sugar-high/blob/main/packages/react/src/file-tree/index.tsx"
click node_remark "https://github.com/huozhi/sugar-high/blob/main/packages/remark/src/index.ts"
click node_site_home "https://github.com/huozhi/sugar-high/blob/main/apps/site/app/page.tsx"
click node_site_editor "https://github.com/huozhi/sugar-high/blob/main/apps/site/app/live-editor.tsx"
click node_site_presets "https://github.com/huozhi/sugar-high/blob/main/apps/site/app/live-editor-presets.ts"
click node_site_capture "https://github.com/huozhi/sugar-high/blob/main/apps/site/app/capture/capture-client.tsx"
click node_site_react "https://github.com/huozhi/sugar-high/blob/main/apps/site/app/react/page.tsx"
click node_site_remark "https://github.com/huozhi/sugar-high/blob/main/apps/site/app/remark/page.tsx"
click node_release_main "https://github.com/huozhi/sugar-high/blob/main/apps/release-video/src/main.tsx"
click node_release_scenes "https://github.com/huozhi/sugar-high/tree/main/apps/release-video/src/scenes"
click node_release_theme "https://github.com/huozhi/sugar-high/blob/main/apps/release-video/src/plate-css.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_parser,node_html toneBlue
class node_language_map,node_grammars,node_runtime toneAmber
class node_react_code,node_react_editor,node_react_theme,node_react_tree,node_remark toneMint
class node_site_home,node_site_editor,node_site_presets,node_site_capture,node_site_react,node_site_remark,node_release_main,node_release_scenes,node_release_theme toneRose
class node_developer toneIndigo
```

## Components

### Highlighting engine

- [Highlight API](https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/index.js): `packages/sugar-high/lib/index.js`
- [Parser and tokenizer](https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/core.js): `packages/sugar-high/lib/core.js`
- [Token and HTML rendering](https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/shared.js): `packages/sugar-high/lib/shared.js`

### Language support

- [Language aliases](https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/lang.js): `packages/sugar-high/lib/lang.js`
- [Language configurations](https://github.com/huozhi/sugar-high/tree/main/packages/sugar-high/lib/lang): `packages/sugar-high/lib/lang`
- [Language runtime rules](https://github.com/huozhi/sugar-high/blob/main/packages/sugar-high/lib/presets/javascript-runtime.js): `packages/sugar-high/lib/presets/javascript-runtime.js`

### Framework integrations

- [React Code block](https://github.com/huozhi/sugar-high/blob/main/packages/react/src/code/code.tsx): `packages/react/src/code/code.tsx`
- [React Editor](https://github.com/huozhi/sugar-high/blob/main/packages/react/src/editor/editor.tsx): `packages/react/src/editor/editor.tsx`
- [React theme styling](https://github.com/huozhi/sugar-high/blob/main/packages/react/src/theme.ts): `packages/react/src/theme.ts`
- [React file tree](https://github.com/huozhi/sugar-high/blob/main/packages/react/src/file-tree/index.tsx): `packages/react/src/file-tree/index.tsx`
- [Remark plugin](https://github.com/huozhi/sugar-high/blob/main/packages/remark/src/index.ts): `packages/remark/src/index.ts`

### Website and media

- [Product homepage](https://github.com/huozhi/sugar-high/blob/main/apps/site/app/page.tsx): `apps/site/app/page.tsx`
- [Interactive editor](https://github.com/huozhi/sugar-high/blob/main/apps/site/app/live-editor.tsx): `apps/site/app/live-editor.tsx`
- [Editor theme presets](https://github.com/huozhi/sugar-high/blob/main/apps/site/app/live-editor-presets.ts): `apps/site/app/live-editor-presets.ts`
- [Code capture page](https://github.com/huozhi/sugar-high/blob/main/apps/site/app/capture/capture-client.tsx): `apps/site/app/capture/capture-client.tsx`
- [React product guide](https://github.com/huozhi/sugar-high/blob/main/apps/site/app/react/page.tsx): `apps/site/app/react/page.tsx`
- [Remark product guide](https://github.com/huozhi/sugar-high/blob/main/apps/site/app/remark/page.tsx): `apps/site/app/remark/page.tsx`
- [Release video timeline](https://github.com/huozhi/sugar-high/blob/main/apps/release-video/src/main.tsx): `apps/release-video/src/main.tsx`
- [Video scenes](https://github.com/huozhi/sugar-high/tree/main/apps/release-video/src/scenes): `apps/release-video/src/scenes`
- [Video theme styling](https://github.com/huozhi/sugar-high/blob/main/apps/release-video/src/plate-css.ts): `apps/release-video/src/plate-css.ts`

### Other components

- **Code consumer**

## Connections

- Code consumer → Highlight API: calls highlight (evidence: `README.md`)
- Highlight API → Parser and tokenizer: parses source (evidence: `README.md`)
- Parser and tokenizer → Token and HTML rendering: renders tokens (evidence: `packages/sugar-high/lib/core.js`)
- Highlight API → Language aliases: normalizes aliases (evidence: `README.md`)
- Code consumer → Parser and tokenizer: configures parse (evidence: `README.md`)
- Code consumer → Language configurations: selects configuration (evidence: `README.md`)
- Language runtime rules → Parser and tokenizer: provides token rules (evidence: `packages/sugar-high/lib/presets/javascript-runtime.js`)
- React Code block → Parser and tokenizer: parses code (evidence: `packages/react/src/code/code.tsx`)
- React Code block → Token and HTML rendering: generates markup (evidence: `packages/react/src/code/code.tsx`)
- React Editor → React Code block: uses code view (evidence: `packages/react/src/editor/editor.tsx`)
- React Code block → React theme styling: applies theme (evidence: `packages/react/src/code/code.tsx`)
- React file tree → React theme styling: applies theme (evidence: `packages/react/src/file-tree/index.tsx`)
- Remark plugin → Language aliases: normalizes fences (evidence: `README.md`)
- Product homepage → Interactive editor: embeds editor (evidence: `apps/site/app/page.tsx`)
- Product homepage → Editor theme presets: provides editor presets
- Code capture page → Editor theme presets: reads theme presets (evidence: `apps/site/app/capture/capture-client.tsx`)
- Code capture page → React Code block: renders code (evidence: `apps/site/app/capture/capture-client.tsx`)
- React product guide → React Code block: demonstrates component (evidence: `apps/site/app/react/page.tsx`)
- React product guide → React Editor: demonstrates component (evidence: `apps/site/app/react/page.tsx`)
- Remark product guide → Remark plugin: demonstrates plugin (evidence: `apps/site/app/remark/page.tsx`)
- Release video timeline → Video scenes: sequences scenes (evidence: `apps/release-video/src/main.tsx`)
- Video scenes → Video theme styling: uses token styles (evidence: `apps/release-video/src/scenes/theme-scene.tsx`)
- Video scenes → Highlight API: highlights examples (evidence: `apps/release-video/src/scenes/theme-scene.tsx`)
