# prismjs/prism architecture

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

- Interactive diagram: https://gitdiagram.com/prismjs/prism
- Repository: https://github.com/prismjs/prism

## Overview

Prism is a syntax-highlighting library for browsers and Node.js. Its principal workflow accepts source text or a DOM code element, resolves a language grammar, tokenizes the input, and renders highlighted output; browser helpers also process code elements. Language definitions and plugins extend the core, while optional plugins add conveniences such as autoloading, line numbers, previews, and command-line highlighting. The graph reflects documented capabilities and relationships visible in the supplied excerpts and SOURCE INDEX; unsampled implementations are represented at their supported directory paths, without asserting unverified calls.

Main entry points: [`src/core/classes/prism.js`](https://github.com/prismjs/prism/blob/v2/src/core/classes/prism.js) (Prism instance), [`src/core/highlight-element.js`](https://github.com/prismjs/prism/blob/v2/src/core/highlight-element.js) (Element highlighting), [`src/core/tokenize/tokenize.js`](https://github.com/prismjs/prism/blob/v2/src/core/tokenize/tokenize.js) (Tokenization), [`src/core/classes/token.js`](https://github.com/prismjs/prism/blob/v2/src/core/classes/token.js) (Token model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and DOM"]
  node_api["Public API<br/>[index.js]"]
  node_auto["Auto start<br/>[auto-start.js]"]
  node_highlight["Element highlighting"]
  node_all["Highlight all<br/>[highlight-all.js]"]
end

subgraph group_engine["Highlighting engine"]
  node_prism["Prism instance<br/>[prism.js]"]
  node_tokenize["Tokenization<br/>[tokenize.js]"]
  node_matching["Grammar matching<br/>[match.js]"]
  node_embedding["Embedded languages<br/>[embed.js]"]
  node_tokens["Token model<br/>[token.js]"]
  node_render["HTML stringifying<br/>[stringify.js]"]
  node_registry["Language registry<br/>[registry.js]"]
end

subgraph group_languages["Languages"]
  node_language["Language definitions"]
  node_loader["Language loading<br/>[load-languages.js]"]
end

subgraph group_extensions["Plugins and extensions"]
  node_autoloader["Autoloader plugin<br/>[autoloader.js]"]
  node_plugins["Highlight plugins"]
  node_cli["Command line<br/>[command-line.js]"]
  node_previews["Previewers<br/>[previewers.js]"]
  node_line["Line features<br/>[line-highlight.js]"]
end

subgraph group_shared["Shared utilities"]
  node_dom["DOM helpers<br/>[dom-util.js]"]
  node_stream["Token streams<br/>[token-stream.js]"]
end

node_user(("Application user"))

node_user -->|"uses"| node_api
node_api -.->|"exposes"| node_prism
node_auto -.->|"starts"| node_all
node_all -.->|"highlights elements"| node_highlight
node_highlight -->|"reads language"| node_dom
node_highlight -->|"uses"| node_prism
node_prism -.->|"tokenizes"| node_tokenize
node_prism -.->|"resolves grammars"| node_registry
node_tokenize -->|"matches patterns"| node_matching
node_tokenize -->|"handles embedding"| node_embedding
node_matching -->|"creates tokens"| node_tokens
node_embedding -->|"uses tokens"| node_tokens
node_highlight -.->|"renders output"| node_render
node_registry -.->|"resolves definitions"| node_language
node_loader -.->|"loads definitions"| node_language
node_user -.->|"requests language"| node_loader
node_autoloader -->|"uses instance"| node_prism
node_autoloader -->|"inspects elements"| node_dom
node_user -->|"enables extensions"| node_plugins
node_user -.->|"highlights files"| node_cli
node_user -.->|"requests previews"| node_previews
node_user -.->|"uses line features"| node_line
node_stream -->|"splits tokens"| node_tokens

click node_api "https://github.com/prismjs/prism/blob/v2/src/index.js"
click node_auto "https://github.com/prismjs/prism/blob/v2/src/auto-start.js"
click node_highlight "https://github.com/prismjs/prism/blob/v2/src/core/highlight-element.js"
click node_all "https://github.com/prismjs/prism/blob/v2/src/core/highlight-all.js"
click node_prism "https://github.com/prismjs/prism/blob/v2/src/core/classes/prism.js"
click node_tokenize "https://github.com/prismjs/prism/blob/v2/src/core/tokenize/tokenize.js"
click node_matching "https://github.com/prismjs/prism/blob/v2/src/core/tokenize/match.js"
click node_embedding "https://github.com/prismjs/prism/blob/v2/src/core/tokenize/embed.js"
click node_tokens "https://github.com/prismjs/prism/blob/v2/src/core/classes/token.js"
click node_render "https://github.com/prismjs/prism/blob/v2/src/core/stringify.js"
click node_registry "https://github.com/prismjs/prism/blob/v2/src/core/registry.js"
click node_language "https://github.com/prismjs/prism/tree/v2/src/languages"
click node_loader "https://github.com/prismjs/prism/blob/v2/src/load-languages.js"
click node_autoloader "https://github.com/prismjs/prism/blob/v2/src/plugins/autoloader/autoloader.js"
click node_plugins "https://github.com/prismjs/prism/tree/v2/src/plugins"
click node_cli "https://github.com/prismjs/prism/blob/v2/src/plugins/command-line/command-line.js"
click node_previews "https://github.com/prismjs/prism/blob/v2/src/plugins/previewers/previewers.js"
click node_line "https://github.com/prismjs/prism/blob/v2/src/plugins/line-highlight/line-highlight.js"
click node_dom "https://github.com/prismjs/prism/blob/v2/src/shared/dom-util.js"
click node_stream "https://github.com/prismjs/prism/blob/v2/src/util/token-stream.js"

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_auto,node_highlight,node_all,node_user toneBlue
class node_prism,node_tokenize,node_matching,node_embedding,node_tokens,node_render,node_registry toneAmber
class node_language,node_loader toneMint
class node_autoloader,node_plugins,node_cli,node_previews,node_line toneRose
class node_dom,node_stream toneIndigo
```

## Components

### Entry and DOM

- [Public API](https://github.com/prismjs/prism/blob/v2/src/index.js): `src/index.js`
- [Auto start](https://github.com/prismjs/prism/blob/v2/src/auto-start.js): `src/auto-start.js`
- [Element highlighting](https://github.com/prismjs/prism/blob/v2/src/core/highlight-element.js): `src/core/highlight-element.js`
- [Highlight all](https://github.com/prismjs/prism/blob/v2/src/core/highlight-all.js): `src/core/highlight-all.js`

### Highlighting engine

- [Prism instance](https://github.com/prismjs/prism/blob/v2/src/core/classes/prism.js): `src/core/classes/prism.js`
- [Tokenization](https://github.com/prismjs/prism/blob/v2/src/core/tokenize/tokenize.js): `src/core/tokenize/tokenize.js`
- [Grammar matching](https://github.com/prismjs/prism/blob/v2/src/core/tokenize/match.js): `src/core/tokenize/match.js`
- [Embedded languages](https://github.com/prismjs/prism/blob/v2/src/core/tokenize/embed.js): `src/core/tokenize/embed.js`
- [Token model](https://github.com/prismjs/prism/blob/v2/src/core/classes/token.js): `src/core/classes/token.js`
- [HTML stringifying](https://github.com/prismjs/prism/blob/v2/src/core/stringify.js): `src/core/stringify.js`
- [Language registry](https://github.com/prismjs/prism/blob/v2/src/core/registry.js): `src/core/registry.js`

### Languages

- [Language definitions](https://github.com/prismjs/prism/tree/v2/src/languages): `src/languages`
- [Language loading](https://github.com/prismjs/prism/blob/v2/src/load-languages.js): `src/load-languages.js`

### Plugins and extensions

- [Autoloader plugin](https://github.com/prismjs/prism/blob/v2/src/plugins/autoloader/autoloader.js): `src/plugins/autoloader/autoloader.js`
- [Highlight plugins](https://github.com/prismjs/prism/tree/v2/src/plugins): `src/plugins`
- [Command line](https://github.com/prismjs/prism/blob/v2/src/plugins/command-line/command-line.js): `src/plugins/command-line/command-line.js`
- [Previewers](https://github.com/prismjs/prism/blob/v2/src/plugins/previewers/previewers.js): `src/plugins/previewers/previewers.js`
- [Line features](https://github.com/prismjs/prism/blob/v2/src/plugins/line-highlight/line-highlight.js): `src/plugins/line-highlight/line-highlight.js`

### Shared utilities

- [DOM helpers](https://github.com/prismjs/prism/blob/v2/src/shared/dom-util.js): `src/shared/dom-util.js`
- [Token streams](https://github.com/prismjs/prism/blob/v2/src/util/token-stream.js): `src/util/token-stream.js`

### Other components

- **Application user**

## Connections

- Application user → Public API: uses (evidence: `README.md`)
- Public API → Prism instance: exposes
- Auto start → Highlight all: starts
- Highlight all → Element highlighting: highlights elements
- Element highlighting → DOM helpers: reads language (evidence: `src/core/highlight-element.js`)
- Element highlighting → Prism instance: uses (evidence: `src/core/highlight-element.js`)
- Prism instance → Tokenization: tokenizes
- Prism instance → Language registry: resolves grammars
- Tokenization → Grammar matching: matches patterns (evidence: `src/core/tokenize/tokenize.js`)
- Tokenization → Embedded languages: handles embedding (evidence: `src/core/tokenize/tokenize.js`)
- Grammar matching → Token model: creates tokens (evidence: `src/core/tokenize/match.js`)
- Embedded languages → Token model: uses tokens (evidence: `src/core/tokenize/embed.js`)
- Element highlighting → HTML stringifying: renders output
- Language registry → Language definitions: resolves definitions
- Language loading → Language definitions: loads definitions
- Application user → Language loading: requests language
- Autoloader plugin → Prism instance: uses instance (evidence: `src/plugins/autoloader/autoloader.js`)
- Autoloader plugin → DOM helpers: inspects elements (evidence: `src/plugins/autoloader/autoloader.js`)
- Application user → Highlight plugins: enables extensions (evidence: `README.md`)
- Application user → Command line: highlights files
- Application user → Previewers: requests previews
- Application user → Line features: uses line features
- Token streams → Token model: splits tokens (evidence: `src/util/token-stream.js`)
