# 88250/lute architecture

> Architecture diagram of the GitHub repository 88250/lute, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/88250/lute
- Repository: https://github.com/88250/lute

## Overview

##### Project type and purpose
- Lute is a compiler-style Markdown engine/library implemented in Go, with an accompanying JavaScript build.
- It exposes three modes of use:
1. Import as a Go library (github.com/88250/lute)
2. Run as an HTTP-service wrapper (lute-http)
3. Transpiled JS (GopherJS) for browser/Node integration

##### File structure
- Core pipeline stages live in separate packages:
- lex/           – tokenization
- parse/         – block/inline parsing into nodes
- ast/           – AST node definitions + tree walking
- render/        – pluggable renderers (HTML, JSON, MD formatter, Protyle, Echarts, Mindmap, Vditor IR/SV/WYSIWYG, sanitizer…)
- html/ contains HTML helper code for parsing/rendering
- util/ holds shared utilities (string/byte ops, URL escaping, panic handling)
- chroma-styles/ + Chroma integration for code syntax highlighting
- javascript/    – build scripts and demo for browser/Node usage
- editor/        – constants for embedding in editors (Protyle/Vditor)
- pprof/, benchmark/, test/ – performance and correctness validation

##### README for additional insights
- Implements full GFM/CommonMark spec, zero-regex, optimized for Chinese, supports formatting (AST→MD), emoji, HTML⇄MD conversion, custom render hooks
- Three usage modes underscore its dual nature as library + service + front-end component

##### Detail, don’t overthink
- Break out each render type (HTML, JSON, various Protyle/Vditor renderers) as separate sub-components
- Config/options injection point at engine instantiation (lute.New())
- How tests and benchmarks validate each stage (optional annotation)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Input Layer"
        Raw["Raw Markdown Text"]:::input
    end

    subgraph "Core Pipeline"
        lex["Lexer"]:::core
        parse["Parser"]:::core
        ast["AST Model"]:::core
        fmt["Transformer/Formatter"]:::core
        subgraph "Renderer Suite"
            htmlR["HTML Renderer"]:::core
            jsonR["JSON Renderer"]:::core
            codeBlock["Code-block Highlighter"]:::core
            echarts["Echarts Renderer"]:::core
            mindmap["Mindmap Renderer"]:::core
            protyle["Protyle Renderer Suite"]:::core
            vditor["Vditor Renderer Suite"]:::core
            sanitizer["Sanitizer"]:::core
        end
    end

    subgraph "Output Layer"
        HTML["HTML Output"]:::output
        MD["Formatted Markdown"]:::output
        JSON["JSON Output"]:::output
        IR["Other IR Outputs"]:::output
    end

    subgraph "Deployment Modes"
        GoLib["Go Library API"]:::deploy
        HTTP["HTTP Service"]:::deploy
        JS["JavaScript Bundle"]:::deploy
    end

    subgraph "External Dependencies"
        Chroma["Chroma"]:::external
        Bluemonday["Bluemonday"]:::external
    end

    Raw --> lex --> parse --> ast
    ast --> fmt --> MD
    ast --> htmlR --> HTML
    ast --> jsonR --> JSON
    ast --> codeBlock --> htmlR
    ast --> echarts --> IR
    ast --> mindmap --> IR
    ast --> protyle --> IR
    ast --> vditor --> IR
    ast --> sanitizer --> HTML

    Chroma -.-> codeBlock
    Bluemonday -.-> sanitizer

    GoLib --> lex
    HTTP --> GoLib
    JS --> GoLib

    click lex "https://github.com/88250/lute/blob/master/lex/lexer.go"
    click parse "https://github.com/88250/lute/blob/master/parse/parse.go"
    click ast "https://github.com/88250/lute/blob/master/ast/node.go"
    click fmt "https://github.com/88250/lute/blob/master/render/format_renderer.go"
    click htmlR "https://github.com/88250/lute/blob/master/render/html_renderer.go"
    click jsonR "https://github.com/88250/lute/blob/master/render/json_renderer.go"
    click codeBlock "https://github.com/88250/lute/blob/master/chroma-styles/main.go"
    click echarts "https://github.com/88250/lute/blob/master/render/echarts_json_renderer.go"
    click mindmap "https://github.com/88250/lute/blob/master/render/mindmap.go"
    click protyle "https://github.com/88250/lute/blob/master/render/protyle_renderer.go"
    click vditor "https://github.com/88250/lute/blob/master/render/vditor_ir_renderer.go"
    click sanitizer "https://github.com/88250/lute/blob/master/render/sanitizer.go"
    click GoLib "https://github.com/88250/lute/blob/master/lute.go"
    click HTTP "https://github.com/88250/lute/blob/master/pprof/main.go"
    click JS "https://github.com/88250/lute/blob/master/javascript/main.go"

    classDef input fill:#f9f,stroke:#333,stroke-width:1px
    classDef core fill:#bbf,stroke:#333,stroke-width:1px
    classDef output fill:#bfb,stroke:#333,stroke-width:1px
    classDef deploy fill:#ffb,stroke:#333,stroke-width:1px
    classDef external fill:#fbb,stroke:#333,stroke-width:1px
```
