Skip to content

Commit bdeb9c3

Browse files
committed
initial release
0 parents  commit bdeb9c3

362 files changed

Lines changed: 46050 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.git* export-ignore
2+
/.php-cs-fixer.dist.php export-ignore
3+
/phpstan.dist.neon export-ignore
4+
/phpunit.dist.xml export-ignore
5+
/examples/ export-ignore
6+
/docs/ export-ignore
7+
/bin/ export-ignore
8+
/tests/ export-ignore

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [smnandre]

.github/workflows/CI.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "*" ]
6+
pull_request:
7+
branches: [ "*" ]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
19+
cs:
20+
uses: phpalto/.github/.github/workflows/CS.yml@main
21+
with:
22+
php-version: '8.4'
23+
# composer-validate: true
24+
# php-cs-fixer-args: '--diff --dry-run'
25+
26+
sa:
27+
uses: phpalto/.github/.github/workflows/SA.yml@main
28+
with:
29+
php-version: '8.4'
30+
# phpstan-args: 'analyse --no-progress --memory-limit=-1'
31+
32+
tests:
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
php: ['8.4', '8.5']
37+
uses: phpalto/.github/.github/workflows/tests.yml@main
38+
with:
39+
php-version: ${{ matrix.php }}
40+
# phpunit-args: '--colors=never'

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.phpunit.cache/
2+
/var/
3+
/vendor/
4+
/.php-cs-fixer.php
5+
/.php-cs-fixer.cache
6+
/coverage.xml
7+
/composer.lock
8+
/phpstan.neon
9+
/phpunit.xml

.php-cs-fixer.dist.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
$licence = <<<'EOF'
4+
This file is part of the ALTO library.
5+
6+
© 2026–present Simon André
7+
8+
For full copyright and license information, please see
9+
the LICENSE file distributed with this source code.
10+
EOF;
11+
12+
$finder = (new PhpCsFixer\Finder())
13+
->in([
14+
__DIR__.'/src',
15+
__DIR__.'/tests',
16+
])
17+
->exclude([
18+
'Language/php',
19+
])
20+
;
21+
22+
return (new PhpCsFixer\Config())
23+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
24+
->setFinder($finder)
25+
->setRiskyAllowed(true)
26+
->setRules([
27+
'@PER-CS' => true,
28+
'@Symfony' => true,
29+
'declare_strict_types' => true,
30+
'header_comment' => ['header' => $licence],
31+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
32+
'no_unused_imports' => true,
33+
])
34+
;

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0] - Unreleased
9+
10+
### Added
11+
12+
- Semantic syntax highlighting engine with context-aware PHP parsing
13+
- 27 language parsers: PHP, HTML, SVG, XML, CSS, SCSS, JavaScript, TypeScript, Twig, Markdown, YAML, JSON, SQL, Bash, Go, Rust, Ruby, Swift, Python, Java, C#, Dockerfile, Diff, DotEnv, HTTP, INI, Makefile
14+
- Embedded language support for HTML (`<style>`/`<script>`), SVG, Markdown (fenced code blocks), and Twig (`{% block %}`)
15+
- 7 built-in themes: Alto, GitHub, Polar, Solar, CupertinoDark, Dracula, Noctis
16+
- Theme adapters for Highlight.js (240+), Prism (250+), and TextMate (.tmTheme) themes
17+
- Line numbers and line highlighting support
18+
- Zero runtime dependencies — requires only PHP 8.4+ with `ext-mbstring` and `ext-tokenizer`

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026-Present Simon André
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NOTICE

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Alto Code Highlight
2+
Copyright (c) 2026 Simon André
3+
4+
This product includes software and color schemes derived from or inspired by
5+
third-party works. The following notices apply to the bundled themes.
6+
7+
-------------------------------------------------------------------------------
8+
9+
Dracula Theme
10+
-------------
11+
Color palette inspired by the Dracula Theme, created by Zeno Rocha.
12+
13+
Original work: https://draculatheme.com
14+
Copyright (c) 2013 Zeno Rocha
15+
License: MIT
16+
17+
The MIT License applies to the original Dracula color palette. The
18+
implementation in this file is an original work by Simon André.
19+
20+
-------------------------------------------------------------------------------
21+
22+
GitHub Theme (dark and light variants)
23+
---------------------------------------
24+
Color palettes based on the GitHub Primer design system, published by GitHub.
25+
26+
Original work: https://github.com/primer/primitives
27+
Copyright (c) GitHub, Inc.
28+
License: MIT
29+
30+
The MIT License applies to the original Primer color definitions. The
31+
implementation in this file is an original work by Simon André.
32+
33+
-------------------------------------------------------------------------------
34+
35+
Noctis Theme
36+
------------
37+
Color palette inspired by the Noctis theme, created by Liviu Schera.
38+
39+
Original work: https://github.com/liviuschera/noctis
40+
Copyright (c) Liviu Schera
41+
License: MIT
42+
43+
The MIT License applies to the original Noctis color palette. The
44+
implementation in this file is an original work by Simon André.
45+
46+
-------------------------------------------------------------------------------
47+
48+
Polar Theme
49+
-----------
50+
Color palette loosely based on Nord, created by Arctic Ice Studio.
51+
52+
Original work: https://www.nordtheme.com
53+
Copyright (c) 2016-present Arctic Ice Studio
54+
License: MIT
55+
56+
The MIT License applies to the original Nord color palette. The
57+
implementation in this file is an original work by Simon André.
58+
59+
-------------------------------------------------------------------------------
60+
61+
Solar Theme
62+
-----------
63+
Color palette inspired by Solarized, created by Ethan Schoonover.
64+
65+
Original work: https://ethanschoonover.com/solarized
66+
Copyright (c) 2011 Ethan Schoonover
67+
License: MIT
68+
69+
The MIT License applies to the original Solarized color palette. The
70+
implementation in this file is an original work by Simon André.
71+
72+
-------------------------------------------------------------------------------

README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# ALTO \ Code Highlight
2+
3+
**Syntax highlighting for PHP projects**
4+
5+
Server-side highlighting for the full PHP stack: [27 languages](#languages)
6+
covering PHP, HTML, Twig, JavaScript, CSS, YAML, and
7+
more. [Zero dependencies](#install), [semantic PHP syntax](#features)
8+
understanding definitions vs. calls, [embedded language support](#embeddings),
9+
and [490+ compatible themes](#compatibility). Works
10+
in [Twig templates](#integrations), Laravel Blade, Symfony controllers—anywhere
11+
PHP runs.
12+
13+
[![Tests](https://img.shields.io/badge/tests-463%20passed-success)](https://github.com/phpalto/code-highlight)
14+
[![PHPStan](https://img.shields.io/badge/PHPStan-level%2010-brightgreen)](https://github.com/phpalto/code-highlight)
15+
[![PHP](https://img.shields.io/badge/PHP-8.4+-777BB4?logo=php&logoColor=white)](https://www.php.net)
16+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
17+
18+
## Features
19+
20+
- **Built for PHP ecosystems:** Highlight the full stack—PHP, HTML, Twig,
21+
JavaScript, CSS, SQL, YAML, and 20+ more languages in a single library.
22+
- **Zero dependencies:** No Node.js, Python, or external processes. Just
23+
Composer. Works in any PHP 8.4+ environment.
24+
- **Full PHP syntax:** Semantic parser that understands context—distinguishes
25+
`class User` (definition) from `new User()` (usage), `function greet()` (
26+
definition) from `greet()` (call).
27+
- **Embedded languages:** Automatically switches parsers for `<style>` and
28+
`<script>` tags in HTML, fenced code blocks in Markdown, and `{% block css %}`
29+
in Twig.
30+
- **Dark mode support:** Multiple dark themes included out of the box (
31+
CupertinoDark, Dracula, Noctis) plus compatibility with 490+ Highlight.js and
32+
Prism themes.
33+
34+
## Install
35+
36+
```bash
37+
composer require alto/code-highlight
38+
```
39+
40+
## Usage
41+
42+
```php
43+
use Alto\Code\Highlight\Highlighter;
44+
use Alto\Code\Highlight\Theme\GitHubTheme;
45+
46+
// 1. Initialize with a theme
47+
$highlighter = new Highlighter(new GitHubTheme());
48+
49+
// 2. Output the theme's CSS (typically in your <head>)
50+
echo "<style>" . $highlighter->getTheme()->getStylesheet() . "</style>";
51+
52+
// 3. Highlight your code
53+
echo $highlighter->highlight($code, 'php');
54+
```
55+
56+
## Languages
57+
58+
### PHP
59+
60+
Alto uses a semantic parser for PHP that goes beyond pattern matching to
61+
understand code context. It correctly distinguishes between:
62+
63+
- **Definitions vs. usage:** `class User` vs. `new User()`, `function greet()`
64+
vs. `greet()`
65+
- **Context-aware scoping:** Variables, function calls, class instantiation,
66+
method calls
67+
68+
### Embeddings
69+
70+
Four languages support automatic embedded language detection:
71+
72+
- **HTML** — CSS in `<style>` tags, JavaScript in `<script>` tags
73+
- **SVG** — CSS in `<style>` tags, JavaScript in `<script>` tags
74+
- **Markdown** — Any language in fenced code blocks (` ```language `)
75+
- **Twig** — Languages via block names (`{% block css %}`,
76+
`{% block javascript %}`)
77+
78+
### Full list
79+
80+
| Category | Languages |
81+
|-----------------|----------------------------------------------------------------------------|
82+
| **Programming** | Bash, C#, Go, Java, JavaScript, PHP, Python, Ruby, Rust, Swift, TypeScript |
83+
| **Markup** | HTML, SVG, XML |
84+
| **Data** | Diff, DotEnv, HTTP, JSON, YAML |
85+
| **Prose** | Markdown |
86+
| **Query** | SQL |
87+
| **Stylesheet** | CSS, SCSS |
88+
| **Template** | Twig |
89+
| **Config** | Dockerfile, INI, Makefile |
90+
91+
## Themes
92+
93+
### Built-in themes
94+
95+
Alto includes 7 built-in themes ready to use:
96+
97+
- **Light themes:** `Alto`, `GitHub`, `Polar`, `Solar`
98+
- **Dark themes:** `CupertinoDark`, `Dracula`, `Noctis`
99+
100+
```php
101+
use Alto\Code\Highlight\Theme\DraculaTheme;
102+
103+
$highlighter = new Highlighter(new DraculaTheme());
104+
```
105+
106+
### Dark mode
107+
108+
Three dark themes are included out of the box:
109+
110+
- **CupertinoDark** — macOS-inspired dark theme
111+
- **Dracula** — Popular dark theme with vibrant colors
112+
- **Noctis** — Low-contrast dark theme for extended coding sessions
113+
114+
### Compatibility
115+
116+
Use existing CSS from the **Highlight.js** (240+ themes), **Prism** (250+
117+
themes), or **TextMate** (.tmTheme) ecosystems:
118+
119+
```php
120+
use Alto\Code\Highlight\Adapter\HighlightJsThemeAdapter;
121+
122+
$theme = HighlightJsThemeAdapter::fromFile('/path/to/github-dark.css');
123+
$highlighter = new Highlighter($theme);
124+
```
125+
126+
```php
127+
use Alto\Code\Highlight\Adapter\TextMateThemeAdapter;
128+
129+
$theme = TextMateThemeAdapter::fromFile('/path/to/monokai.tmTheme', isDark: true);
130+
$highlighter = new Highlighter($theme);
131+
```
132+
133+
## Integrations
134+
135+
### Twig Extension
136+
137+
**[Twig Extension](https://github.com/phpalto/twig-code-highlight)** — Highlight
138+
code directly in Twig templates using blocks or filters.
139+
140+
## Contributing
141+
142+
Contributions are welcome! Please feel free
143+
to [submit issues](https://github.com/phpalto/code-highlight/issues)
144+
or [pull requests](https://github.com/phpalto/code-highlight/pulls).
145+
146+
## License
147+
148+
Released by the [Alto project](https://github.com/phpalto) under the MIT
149+
License.
150+
See the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)