├── .github ├── FUNDING.yml ├── highlight-2.png ├── highlight-3.png ├── highlight-4.png ├── highlight.png ├── terminal.png └── workflows │ ├── quality-assurance.yml │ └── quality-control.yml ├── .gitignore ├── .php-cs-fixer.dist.php ├── LICENCE.md ├── README.md ├── UPGRADING.md ├── composer.json ├── phpstan.neon.dist ├── phpunit.xml ├── src ├── After.php ├── Before.php ├── CommonMark │ ├── CodeBlockRenderer.php │ ├── HighlightExtension.php │ └── InlineCodeBlockRenderer.php ├── Escape.php ├── Highlighter.php ├── Injection.php ├── IsInjection.php ├── IsPattern.php ├── Language.php ├── Languages │ ├── Base │ │ ├── BaseLanguage.php │ │ ├── Injections │ │ │ ├── AdditionInjection.php │ │ │ ├── BlurInjection.php │ │ │ ├── CustomClassInjection.php │ │ │ ├── DeletionInjection.php │ │ │ ├── EmphasizeInjection.php │ │ │ ├── GutterInjection.php │ │ │ └── StrongInjection.php │ │ ├── IsHighlightInjection.php │ │ └── Patterns │ │ │ ├── AdditionEndTokenPattern.php │ │ │ ├── AdditionStartTokenPattern.php │ │ │ ├── DeletionEndTokenPattern.php │ │ │ ├── DeletionStartTokenPattern.php │ │ │ └── InjectionTokenPattern.php │ ├── Blade │ │ ├── BladeLanguage.php │ │ ├── Injections │ │ │ ├── BladeEchoInjection.php │ │ │ ├── BladeKeywordInjection.php │ │ │ ├── BladePhpInjection.php │ │ │ └── BladeRawEchoInjection.php │ │ └── Patterns │ │ │ ├── BladeCommentPattern.php │ │ │ ├── BladeComponentCloseTagPattern.php │ │ │ ├── BladeComponentOpenTagPattern.php │ │ │ └── BladeKeywordPattern.php │ ├── Css │ │ ├── CssLanguage.php │ │ └── Patterns │ │ │ ├── CssAttributePattern.php │ │ │ ├── CssCommentPattern.php │ │ │ ├── CssFunctionPattern.php │ │ │ ├── CssImportPattern.php │ │ │ ├── CssMediaQueryPattern.php │ │ │ ├── CssSelectorPattern.php │ │ │ └── CssVariablePattern.php │ ├── Diff │ │ ├── DiffLanguage.php │ │ └── Injections │ │ │ ├── DiffAdditionInjection.php │ │ │ └── DiffDeletionInjection.php │ ├── DocComment │ │ ├── DocCommentLanguage.php │ │ └── Patterns │ │ │ └── DocCommentTagPattern.php │ ├── Dockerfile │ │ ├── DockerfileLanguage.php │ │ └── Patterns │ │ │ ├── ImageAliasKeywordPattern.php │ │ │ ├── ImageAliasNamePattern.php │ │ │ ├── ImageNamePattern.php │ │ │ ├── ImageTagPattern.php │ │ │ └── KeywordPattern.php │ ├── Ellison │ │ ├── EllisonLanguage.php │ │ └── Injections │ │ │ └── ParserInjection.php │ ├── Gdscript │ │ ├── GdscriptLanguage.php │ │ └── Patterns │ │ │ ├── AnnotationPattern.php │ │ │ ├── AsTypePattern.php │ │ │ ├── ClassNamePattern.php │ │ │ ├── DoubleQuoteValuePattern.php │ │ │ ├── ExtendsPattern.php │ │ │ ├── FunctionCallPattern.php │ │ │ ├── FunctionNamePattern.php │ │ │ ├── KeywordPattern.php │ │ │ ├── OperatorPattern.php │ │ │ ├── PropertyAccessPattern.php │ │ │ ├── ReturnTypePattern.php │ │ │ ├── SingleQuoteValuePattern.php │ │ │ ├── SinglelineCommentPattern.php │ │ │ └── VarTypePattern.php │ ├── Html │ │ ├── HtmlLanguage.php │ │ └── Injections │ │ │ ├── CssAttributeInHtmlInjection.php │ │ │ ├── CssInHtmlInjection.php │ │ │ ├── JavaScriptInHtmlInjection.php │ │ │ ├── PhpInHtmlInjection.php │ │ │ └── PhpShortEchoInHtmlInjection.php │ ├── JavaScript │ │ ├── Injections │ │ │ └── JsDocInjection.php │ │ ├── JavaScriptLanguage.php │ │ ├── JsDocLanguage.php │ │ └── Patterns │ │ │ ├── JsClassNamePattern.php │ │ │ ├── JsDocParamNamePattern.php │ │ │ ├── JsDocTypePattern.php │ │ │ ├── JsDoubleQuoteValuePattern.php │ │ │ ├── JsKeywordPattern.php │ │ │ ├── JsMethodPattern.php │ │ │ ├── JsMultilineCommentPattern.php │ │ │ ├── JsNewObjectPattern.php │ │ │ ├── JsObjectPropertyPattern.php │ │ │ ├── JsPropertyPattern.php │ │ │ ├── JsSingleQuoteValuePattern.php │ │ │ ├── JsSinglelineCommentPattern.php │ │ │ ├── JsStaticClassPattern.php │ │ │ └── JsStaticPropertyPattern.php │ ├── Json │ │ ├── JsonLanguage.php │ │ └── Patterns │ │ │ ├── JsonAccoladesPattern.php │ │ │ ├── JsonArrayBracketsPattern.php │ │ │ ├── JsonDoubleQuoteValuePattern.php │ │ │ └── JsonPropertyPattern.php │ ├── Php │ │ ├── Injections │ │ │ ├── PhpAttributeInstanceInjection.php │ │ │ ├── PhpAttributePlainInjection.php │ │ │ ├── PhpDocCommentInjection.php │ │ │ ├── PhpFunctionParametersInjection.php │ │ │ ├── PhpGenericTypeInjection.php │ │ │ └── PhpHeredocInjection.php │ │ ├── Patterns │ │ │ ├── AttributeTypePattern.php │ │ │ ├── CatchTypePattern.php │ │ │ ├── ClassNamePattern.php │ │ │ ├── ClassPropertyPattern.php │ │ │ ├── ClassResolutionPattern.php │ │ │ ├── ConstantNamePattern.php │ │ │ ├── ConstantPropertyPattern.php │ │ │ ├── ConstantTypesPattern.php │ │ │ ├── DoubleQuoteValuePattern.php │ │ │ ├── EnumBackedTypePattern.php │ │ │ ├── EnumCasePattern.php │ │ │ ├── ExtendsPattern.php │ │ │ ├── FunctionCallPattern.php │ │ │ ├── FunctionNamePattern.php │ │ │ ├── GenericPattern.php │ │ │ ├── GroupedTypePattern.php │ │ │ ├── ImplementsPattern.php │ │ │ ├── InstanceOfPattern.php │ │ │ ├── KeywordPattern.php │ │ │ ├── MultilineSingleDocCommentPattern.php │ │ │ ├── NamedArgumentPattern.php │ │ │ ├── NamespacePattern.php │ │ │ ├── NestedFunctionCallPattern.php │ │ │ ├── NewObjectPattern.php │ │ │ ├── OperatorPattern.php │ │ │ ├── PhpAsymmetricPropertyPattern.php │ │ │ ├── PhpCloseTagPattern.php │ │ │ ├── PhpDocCommentGenericTypePattern.php │ │ │ ├── PhpDocCommentParamTypePattern.php │ │ │ ├── PhpDocCommentReturnTypePattern.php │ │ │ ├── PhpDocCommentReturnTypeSingleLinePattern.php │ │ │ ├── PhpDocCommentTemplateTypePattern.php │ │ │ ├── PhpDocCommentVarTypePattern.php │ │ │ ├── PhpDocCommentVariablePattern.php │ │ │ ├── PhpOpenTagPattern.php │ │ │ ├── PropertyAccessPattern.php │ │ │ ├── PropertyHookGetPattern.php │ │ │ ├── PropertyHookSetParameterTypePattern.php │ │ │ ├── PropertyHookSetPattern.php │ │ │ ├── PropertyTypesPattern.php │ │ │ ├── ReturnTypePattern.php │ │ │ ├── ShortFunctionReferencePattern.php │ │ │ ├── SingleQuoteValuePattern.php │ │ │ ├── SinglelineCommentPattern.php │ │ │ ├── StaticClassCallPattern.php │ │ │ ├── StaticPropertyPattern.php │ │ │ ├── TypeForVariablePattern.php │ │ │ ├── UntypedClassPropertyPattern.php │ │ │ ├── UseAsPattern.php │ │ │ ├── UseFunctionNamePattern.php │ │ │ ├── UseFunctionPattern.php │ │ │ ├── UsePattern.php │ │ │ └── VariablePattern.php │ │ ├── PhpDocCommentLanguage.php │ │ ├── PhpLanguage.php │ │ └── PhpTypeLanguage.php │ ├── Python │ │ ├── Patterns │ │ │ ├── PyArgumentPattern.php │ │ │ ├── PyBuiltinPattern.php │ │ │ ├── PyClassNamePattern.php │ │ │ ├── PyCommentPattern.php │ │ │ ├── PyDecoratorPattern.php │ │ │ ├── PyFunctionPattern.php │ │ │ ├── PyKeywordPattern.php │ │ │ ├── PyLogicalValuePattern.php │ │ │ ├── PyNumberPattern.php │ │ │ ├── PyOperatorPattern.php │ │ │ ├── PyTripleDoubleQuoteStringPattern.php │ │ │ └── PyTripleSingleQuoteStringPattern.php │ │ └── PythonLanguage.php │ ├── Sql │ │ ├── Patterns │ │ │ ├── SqlAsTablePattern.php │ │ │ ├── SqlDoubleQuoteValuePattern.php │ │ │ ├── SqlFromTablePattern.php │ │ │ ├── SqlFunctionPattern.php │ │ │ ├── SqlJoinTablePattern.php │ │ │ ├── SqlMultilineCommentPattern.php │ │ │ ├── SqlPropertyPattern.php │ │ │ ├── SqlSingleQuoteValuePattern.php │ │ │ ├── SqlSinglelineCommentPattern.php │ │ │ ├── SqlTableAccessPattern.php │ │ │ └── SqlTablePropertyPattern.php │ │ └── SqlLanguage.php │ ├── Text │ │ └── TextLanguage.php │ ├── Twig │ │ ├── Injections │ │ │ ├── TwigEchoInjection.php │ │ │ └── TwigTagInjection.php │ │ ├── Patterns │ │ │ ├── TwigArrayKeyPattern.php │ │ │ ├── TwigCommentPattern.php │ │ │ ├── TwigDoubleQuoteValuePattern.php │ │ │ ├── TwigFilterPattern.php │ │ │ ├── TwigKeywordPattern.php │ │ │ ├── TwigMethodPattern.php │ │ │ ├── TwigNamedArgumentPattern.php │ │ │ ├── TwigPropertyPattern.php │ │ │ ├── TwigSingleQuoteValuePattern.php │ │ │ └── TwigTokenPattern.php │ │ ├── TwigEchoLanguage.php │ │ ├── TwigLanguage.php │ │ └── TwigTagLanguage.php │ ├── Xml │ │ ├── Patterns │ │ │ ├── XmlAttributePattern.php │ │ │ ├── XmlCloseTagPattern.php │ │ │ ├── XmlCommentPattern.php │ │ │ └── XmlOpenTagPattern.php │ │ └── XmlLanguage.php │ └── Yaml │ │ ├── Patterns │ │ ├── YamlArrayBracketsPattern.php │ │ ├── YamlColonPattern.php │ │ ├── YamlCommentPattern.php │ │ ├── YamlDashPattern.php │ │ ├── YamlDoubleAccoladesValuePattern.php │ │ ├── YamlDoubleQuoteValuePattern.php │ │ ├── YamlObjectBracketsPattern.php │ │ ├── YamlPipePattern.php │ │ ├── YamlPropertyPattern.php │ │ ├── YamlSingleQuoteValuePattern.php │ │ └── YamlVariablePattern.php │ │ └── YamlLanguage.php ├── ParsedInjection.php ├── Pattern.php ├── PatternTest.php ├── TerminalTheme.php ├── Theme.php ├── Themes │ ├── Css │ │ ├── andromeeda.css │ │ ├── aurora-x.css │ │ ├── ayu-dark.css │ │ ├── catppuccin-frappe.css │ │ ├── catppuccin-latte.css │ │ ├── catppuccin-macchiato.css │ │ ├── catppuccin-mocha.css │ │ ├── dark-plus.css │ │ ├── dracula-soft.css │ │ ├── dracula.css │ │ ├── ellison.css │ │ ├── github-dark-default.css │ │ ├── github-dark-dimmed.css │ │ ├── github-dark.css │ │ ├── github-light-default.css │ │ ├── github-light.css │ │ ├── highlight-dark-lite.css │ │ ├── highlight-light-lite.css │ │ ├── highlight-tempest.css │ │ ├── houston.css │ │ ├── inspired-github.css │ │ ├── light-plus.css │ │ ├── material-theme-darker.css │ │ ├── material-theme-lighter.css │ │ ├── material-theme-ocean.css │ │ ├── material-theme-palenight.css │ │ ├── material-theme.css │ │ ├── min-dark.css │ │ ├── min-light.css │ │ ├── monokai.css │ │ ├── night-owl.css │ │ ├── nord.css │ │ ├── one-dark-pro.css │ │ ├── poimandres.css │ │ ├── red.css │ │ ├── rose-pine-dawn.css │ │ ├── rose-pine-moon.css │ │ ├── rose-pine.css │ │ ├── slack-dark.css │ │ ├── slack-ochin.css │ │ ├── solarized-dark.css │ │ ├── solarized-light.css │ │ ├── synthwave-84.css │ │ ├── tokyo-night.css │ │ ├── vesper.css │ │ ├── vitesse-black.css │ │ ├── vitesse-dark.css │ │ └── vitesse-light.css │ ├── CssTheme.php │ ├── EscapesTerminalTheme.php │ ├── EscapesWebTheme.php │ ├── InlineTheme.php │ ├── LightTerminalTheme.php │ └── TerminalStyle.php ├── Tokens │ ├── DynamicTokenType.php │ ├── GroupTokens.php │ ├── IgnoreTokenType.php │ ├── ParseTokens.php │ ├── RenderTokens.php │ ├── Token.php │ ├── TokenType.php │ └── TokenTypeEnum.php └── WebTheme.php ├── test-server.php ├── test-terminal.php └── tests ├── CommonMark ├── CodeBlockRendererTest.php ├── HighlightExtensionTest.php └── InlineCodeBlockRendererTest.php ├── HighlighterTest.php ├── Languages ├── Base │ └── Injections │ │ ├── AdditionInjectionTest.php │ │ ├── BlurInjectionTest.php │ │ ├── CustomClassInjectionTest.php │ │ ├── DeletionInjectionTest.php │ │ ├── EmphasizeInjectionTest.php │ │ ├── GutterInjectionTest.php │ │ └── StrongInjectionTest.php ├── Blade │ ├── BladeLanguageTest.php │ └── Injections │ │ ├── BladeEchoInjectionTest.php │ │ ├── BladeKeywordInjectionTest.php │ │ ├── BladePhpInjectionTest.php │ │ └── BladeRawEchoInjectionTest.php ├── Css │ ├── CssLanguageTest.php │ └── Injections │ │ ├── CssAttributeInjectionTest.php │ │ └── CssInjectionTest.php ├── Diff │ └── DiffLanguageTest.php ├── Dockerfile │ └── Patterns │ │ └── KeywordPatternTest.php ├── Ellison │ └── EllisonLanguageTest.php ├── Gdscript │ └── GdscriptLanguageTest.php ├── Html │ └── HtmlLanguageTest.php ├── JavaScript │ └── JavaScriptLanguageTest.php ├── Json │ └── JsonLanguageTest.php ├── Php │ ├── Injections │ │ ├── HeredocInjectionTest.php │ │ ├── PhpFunctionParametersInjectionTest.php │ │ ├── PhpInjectionTest.php │ │ └── PhpShortEchoInjectionTest.php │ ├── Patterns │ │ ├── ClassNamePatternTest.php │ │ ├── ConstantPropertyPatternTest.php │ │ ├── ExtendsPatternTest.php │ │ ├── FunctionCallPatternTest.php │ │ ├── FunctionNamePatternTest.php │ │ ├── KeywordPatternTest.php │ │ ├── MultilineSingleDocCommentPatternTest.php │ │ ├── NamedArgumentPatternTest.php │ │ ├── NamespacePatternTest.php │ │ ├── NestedFunctionCallPatternTest.php │ │ ├── PropertyAccessPatternTest.php │ │ ├── SinglelineDocCommentPatternTest.php │ │ └── UsePatternTest.php │ ├── PhpDocCommentLanguageTest.php │ └── PhpLanguageTest.php ├── Python │ └── PythonLanguageTest.php ├── Sql │ └── SqlLanguageTest.php ├── Text │ └── TextLanguageTest.php ├── Twig │ ├── Injections │ │ ├── TwigEchoInjectionTest.php │ │ └── TwigTagInjectionTest.php │ ├── Patterns │ │ ├── TwigKeywordPatternTest.php │ │ └── TwigTokenPatternTest.php │ └── TwigLanguageTest.php ├── Xml │ └── XmlLanguageTest.php └── Yaml │ └── YamlLanguageTest.php ├── PatternsTest.php ├── RenderTokensTest.php ├── TestsInjections.php ├── TestsPatterns.php ├── Themes ├── InlineThemeTest.php ├── LightTerminalThemeTest.php └── TerminalThemeTest.php ├── TokenTest.php ├── Tokens └── GroupTokensTest.php ├── index.php ├── stubs ├── 01.txt ├── 02.txt └── 03.txt ├── stylesheets └── ellison.css └── targets ├── ellison.md ├── gdscript.md ├── python.md ├── test-big.md └── test.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: brendt 4 | -------------------------------------------------------------------------------- /.github/highlight-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tempestphp/highlight/708861661719051a08c24ae74700f916956a605e/.github/highlight-2.png -------------------------------------------------------------------------------- /.github/highlight-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tempestphp/highlight/708861661719051a08c24ae74700f916956a605e/.github/highlight-3.png -------------------------------------------------------------------------------- /.github/highlight-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tempestphp/highlight/708861661719051a08c24ae74700f916956a605e/.github/highlight-4.png -------------------------------------------------------------------------------- /.github/highlight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tempestphp/highlight/708861661719051a08c24ae74700f916956a605e/.github/highlight.png -------------------------------------------------------------------------------- /.github/terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tempestphp/highlight/708861661719051a08c24ae74700f916956a605e/.github/terminal.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | .phpunit.result.cache 3 | composer.lock 4 | /.php-cs-fixer.cache 5 | .env 6 | .idea 7 | build/ -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2024 Brent Roose brendt@stitcher.io 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fast, extensible, server-side code highlighting 2 | [![Coverage Status](https://coveralls.io/repos/github/tempestphp/highlight/badge.svg?branch=main)](https://coveralls.io/github/tempestphp/highlight?branch=main) 3 | 4 | ## Quickstart 5 | 6 | ```php 7 | composer require tempest/highlight 8 | ``` 9 | 10 | Highlight code like this: 11 | 12 | ```php 13 | $highlighter = new \Tempest\Highlight\Highlighter(); 14 | 15 | $code = $highlighter->parse($code, 'php'); 16 | ``` 17 | 18 | Continue reading in the docs: [https://tempestphp.com/docs/highlight/01-getting-started](https://tempestphp.com/docs/highlight/01-getting-started). 19 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: 1 3 | reportUnmatchedIgnoredErrors: false 4 | paths: 5 | - src 6 | - tests -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests 15 | 16 | 17 | 18 | 19 | 20 | ./src 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/After.php: -------------------------------------------------------------------------------- 1 | addRenderer(FencedCode::class, new CodeBlockRenderer($this->highlighter), 10) 24 | ->addRenderer(Code::class, new InlineCodeBlockRenderer($this->highlighter), 10) 25 | ; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommonMark/InlineCodeBlockRenderer.php: -------------------------------------------------------------------------------- 1 | [\w]+)}(?.*)/', $node->getLiteral(), $match); 28 | 29 | $language = $match['match'] ?? 'txt'; 30 | $code = $match['code'] ?? $node->getLiteral(); 31 | 32 | return '' . $this->highlighter->parse($code, $language) . ''; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Injection.php: -------------------------------------------------------------------------------- 1 | getPattern(); 16 | 17 | if (! str_starts_with($pattern, '/')) { 18 | $pattern = "/{$pattern}/"; 19 | } 20 | 21 | $result = preg_replace_callback( 22 | pattern: $pattern, 23 | callback: function ($matches) use ($highlighter) { 24 | $content = $matches['match'] ?? ''; 25 | 26 | if (! $content) { 27 | return $matches[0]; 28 | } 29 | 30 | return str_replace( 31 | search: $content, 32 | replace: $this->parseContent($content, $highlighter), 33 | subject: $matches[0], 34 | ); 35 | }, 36 | subject: $content, 37 | ); 38 | 39 | return new ParsedInjection($result ?? $content); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/IsPattern.php: -------------------------------------------------------------------------------- 1 | getPattern(); 14 | 15 | if (! str_starts_with($pattern, '/')) { 16 | $pattern = "/$pattern/"; 17 | } 18 | 19 | preg_match_all($pattern, $content, $matches, PREG_OFFSET_CAPTURE); 20 | 21 | return $matches; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Language.php: -------------------------------------------------------------------------------- 1 | \+})/'; 21 | } 22 | 23 | public function getTokenType(): TokenType 24 | { 25 | return new IgnoreTokenType(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Base/Patterns/AdditionStartTokenPattern.php: -------------------------------------------------------------------------------- 1 | {\+)/'; 21 | } 22 | 23 | public function getTokenType(): TokenType 24 | { 25 | return new IgnoreTokenType(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Base/Patterns/DeletionEndTokenPattern.php: -------------------------------------------------------------------------------- 1 | \-})/'; 22 | } 23 | 24 | public function getTokenType(): TokenType 25 | { 26 | return new IgnoreTokenType(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Base/Patterns/DeletionStartTokenPattern.php: -------------------------------------------------------------------------------- 1 | {\-)(?!-)/'; 22 | } 23 | 24 | public function getTokenType(): TokenType 25 | { 26 | return new IgnoreTokenType(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Base/Patterns/InjectionTokenPattern.php: -------------------------------------------------------------------------------- 1 | (.|\n)*?)' . Escape::INJECTION_TOKEN; 19 | } 20 | 21 | public function getTokenType(): TokenTypeEnum 22 | { 23 | return TokenTypeEnum::INJECTION; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Languages/Blade/Injections/BladeEchoInjection.php: -------------------------------------------------------------------------------- 1 | .*)(}})'; 18 | } 19 | 20 | public function parseContent(string $content, Highlighter $highlighter): string 21 | { 22 | return $highlighter->parse($content, 'php'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Blade/Injections/BladeKeywordInjection.php: -------------------------------------------------------------------------------- 1 | .*)\)'; 18 | } 19 | 20 | public function parseContent(string $content, Highlighter $highlighter): string 21 | { 22 | return $highlighter->parse($content, 'php'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Blade/Injections/BladePhpInjection.php: -------------------------------------------------------------------------------- 1 | (.|\n)*?)\@endphp'; 18 | } 19 | 20 | public function parseContent(string $content, Highlighter $highlighter): string 21 | { 22 | return $highlighter->parse($content, 'php'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Blade/Injections/BladeRawEchoInjection.php: -------------------------------------------------------------------------------- 1 | .*)(!!})'; 18 | } 19 | 20 | public function parseContent(string $content, Highlighter $highlighter): string 21 | { 22 | return $highlighter->parse($content, 'php'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Blade/Patterns/BladeCommentPattern.php: -------------------------------------------------------------------------------- 1 | \{\{\-\-(.|\n)*?\-\-\}\})'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::COMMENT; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Blade/Patterns/BladeComponentCloseTagPattern.php: -------------------------------------------------------------------------------- 1 | ', output: 'a')] 13 | #[PatternTest(input: '', output: 'x-hello')] 14 | #[PatternTest(input: '', output: 'x-hello::world')] 15 | #[PatternTest(input: '', output: 'x-hello::world.lorem')] 16 | final readonly class BladeComponentCloseTagPattern implements Pattern 17 | { 18 | use IsPattern; 19 | 20 | public function getPattern(): string 21 | { 22 | return '<\/(?[\w\-\:\.]+)'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::KEYWORD; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Blade/Patterns/BladeComponentOpenTagPattern.php: -------------------------------------------------------------------------------- 1 | ', output: 'a')] 13 | #[PatternTest(input: '', output: 'x-hello')] 14 | #[PatternTest(input: '', output: 'x-hello::world')] 15 | #[PatternTest(input: '', output: 'x-hello::world.lorem')] 16 | final readonly class BladeComponentOpenTagPattern implements Pattern 17 | { 18 | use IsPattern; 19 | 20 | public function getPattern(): string 21 | { 22 | return '<(?[\w\-\:\.]+)'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::KEYWORD; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Blade/Patterns/BladeKeywordPattern.php: -------------------------------------------------------------------------------- 1 | \@[\w]+)\b'; 24 | } 25 | 26 | public function getTokenType(): TokenTypeEnum 27 | { 28 | return TokenTypeEnum::KEYWORD; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Languages/Css/Patterns/CssAttributePattern.php: -------------------------------------------------------------------------------- 1 | [\w\-]+):'; 27 | } 28 | 29 | public function getTokenType(): TokenTypeEnum 30 | { 31 | return TokenTypeEnum::PROPERTY; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Languages/Css/Patterns/CssCommentPattern.php: -------------------------------------------------------------------------------- 1 | \/\*(.|\n)*?\*\/)/m'; 26 | } 27 | 28 | public function getTokenType(): TokenTypeEnum 29 | { 30 | return TokenTypeEnum::COMMENT; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Languages/Css/Patterns/CssFunctionPattern.php: -------------------------------------------------------------------------------- 1 | [\w\-]+)\('; 28 | } 29 | 30 | public function getTokenType(): TokenTypeEnum 31 | { 32 | return TokenTypeEnum::KEYWORD; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Languages/Css/Patterns/CssImportPattern.php: -------------------------------------------------------------------------------- 1 | \@import)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::KEYWORD; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Css/Patterns/CssMediaQueryPattern.php: -------------------------------------------------------------------------------- 1 | \@media(.*)?){'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::KEYWORD; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Css/Patterns/CssSelectorPattern.php: -------------------------------------------------------------------------------- 1 | [\[\]\'\"\=\@\-\#\.\w\s,\n\+\:\(\)\*]+)\{'; 35 | } 36 | 37 | public function getTokenType(): TokenTypeEnum 38 | { 39 | return TokenTypeEnum::KEYWORD; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Languages/Css/Patterns/CssVariablePattern.php: -------------------------------------------------------------------------------- 1 | \-\-[\w\-]+)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::PROPERTY; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Diff/DiffLanguage.php: -------------------------------------------------------------------------------- 1 | + '); 19 | $close = Escape::tokens(''); 20 | 21 | return $open . $matches[1] . $close; 22 | }, 23 | $content 24 | ); 25 | 26 | return new ParsedInjection($content); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Diff/Injections/DiffDeletionInjection.php: -------------------------------------------------------------------------------- 1 | - '); 19 | $close = Escape::tokens(''); 20 | 21 | return $open . $matches[1] . $close; // Wraps the matched line with the span 22 | }, 23 | $content 24 | ); 25 | 26 | return new ParsedInjection($content); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/DocComment/DocCommentLanguage.php: -------------------------------------------------------------------------------- 1 | \@[\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::VALUE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Dockerfile/Patterns/ImageAliasKeywordPattern.php: -------------------------------------------------------------------------------- 1 | AS)[\s][\S]+/m"; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::KEYWORD; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Dockerfile/Patterns/ImageAliasNamePattern.php: -------------------------------------------------------------------------------- 1 | [\S]+)/m"; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VALUE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Dockerfile/Patterns/ImageNamePattern.php: -------------------------------------------------------------------------------- 1 | [\w\/]+)/m"; 25 | } 26 | 27 | public function getTokenType(): TokenTypeEnum 28 | { 29 | return TokenTypeEnum::VALUE; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Languages/Dockerfile/Patterns/ImageTagPattern.php: -------------------------------------------------------------------------------- 1 | \S+)[\s]?/m"; 25 | } 26 | 27 | public function getTokenType(): TokenTypeEnum 28 | { 29 | return TokenTypeEnum::VALUE; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Languages/Dockerfile/Patterns/KeywordPattern.php: -------------------------------------------------------------------------------- 1 | {$this->keyword})[\s].*/m"; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::KEYWORD; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Ellison/EllisonLanguage.php: -------------------------------------------------------------------------------- 1 | [a-zA-Z][a-zA-Z0-9]+)\b'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::TYPE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/ClassNamePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::TYPE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/DoubleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | .*?)"'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VALUE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/ExtendsPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::TYPE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/FunctionCallPattern.php: -------------------------------------------------------------------------------- 1 | [a-z][\w]+)\('; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::PROPERTY; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/FunctionNamePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/KeywordPattern.php: -------------------------------------------------------------------------------- 1 | {$this->keyword})\b/"; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::KEYWORD; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/OperatorPattern.php: -------------------------------------------------------------------------------- 1 | operator, '/'); 22 | 23 | return "/(?{$quoted})/"; 24 | } 25 | 26 | public function getTokenType(): TokenTypeEnum 27 | { 28 | return TokenTypeEnum::OPERATOR; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/PropertyAccessPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/ReturnTypePattern.php: -------------------------------------------------------------------------------- 1 | Bar:', output: 'Bar')] 13 | #[PatternTest(input: 'func foo() -> Bar :', output: 'Bar')] 14 | final readonly class ReturnTypePattern implements Pattern 15 | { 16 | use IsPattern; 17 | 18 | public function getPattern(): string 19 | { 20 | return '\)\s*\-\>\s*(?.+?)[\s*:\n]'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/SingleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | .*?)'"; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VALUE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/SinglelineCommentPattern.php: -------------------------------------------------------------------------------- 1 | #(.)*)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::COMMENT; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Gdscript/Patterns/VarTypePattern.php: -------------------------------------------------------------------------------- 1 | \w+)'; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::TYPE; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Html/HtmlLanguage.php: -------------------------------------------------------------------------------- 1 | (.|\n)*?)"'; 18 | } 19 | 20 | public function parseContent(string $content, Highlighter $highlighter): string 21 | { 22 | return $highlighter->parse($content, 'css'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Html/Injections/CssInHtmlInjection.php: -------------------------------------------------------------------------------- 1 | (?(.|\n)*?)<\/style>'; 18 | } 19 | 20 | public function parseContent(string $content, Highlighter $highlighter): string 21 | { 22 | return $highlighter->parse($content, 'css'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Html/Injections/JavaScriptInHtmlInjection.php: -------------------------------------------------------------------------------- 1 | (?(.|\n)*)<\/script>'; 19 | } 20 | 21 | public function parseContent(string $content, Highlighter $highlighter): string 22 | { 23 | return $highlighter->parse($content, new JavaScriptLanguage()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Languages/Html/Injections/PhpInHtmlInjection.php: -------------------------------------------------------------------------------- 1 | (.|\n)*?)\?>'; 18 | } 19 | 20 | public function parseContent(string $content, Highlighter $highlighter): string 21 | { 22 | return $highlighter->parse($content, 'php'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Html/Injections/PhpShortEchoInHtmlInjection.php: -------------------------------------------------------------------------------- 1 | .*)\s\?>/'; 18 | } 19 | 20 | public function parseContent(string $content, Highlighter $highlighter): string 21 | { 22 | return $highlighter->parse($content, 'php'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Injections/JsDocInjection.php: -------------------------------------------------------------------------------- 1 | \/\*\*(.|\n)*?\*\/)/m'; 19 | } 20 | 21 | public function parseContent(string $content, Highlighter $highlighter): string 22 | { 23 | return $highlighter->parse($content, new JsDocLanguage()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/JsDocLanguage.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::TYPE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsDocParamNamePattern.php: -------------------------------------------------------------------------------- 1 | (.*?))(\s|$)'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VALUE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsDocTypePattern.php: -------------------------------------------------------------------------------- 1 | \{(.*?)\})'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsDoubleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | "(\\\"|.)*?")'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VALUE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsKeywordPattern.php: -------------------------------------------------------------------------------- 1 | caseInsensitive = true; 24 | 25 | return $this; 26 | } 27 | 28 | public function getPattern(): string 29 | { 30 | $pattern = "/\b(?{$this->keyword})(\,|\.|\)|\;|\:|\s|\()/"; 31 | 32 | if ($this->caseInsensitive) { 33 | $pattern .= 'i'; 34 | } 35 | 36 | return $pattern; 37 | } 38 | 39 | public function getTokenType(): TokenTypeEnum 40 | { 41 | return TokenTypeEnum::KEYWORD; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsMethodPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)\('; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsMultilineCommentPattern.php: -------------------------------------------------------------------------------- 1 | \/\*(.|\n)*?\*\/)/m'; 27 | } 28 | 29 | public function getTokenType(): TokenTypeEnum 30 | { 31 | return TokenTypeEnum::COMMENT; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsNewObjectPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)(\s)*\('; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsObjectPropertyPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)\:'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::PROPERTY; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsPropertyPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsSingleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | '(\\\'|.)*?')"; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VALUE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsSinglelineCommentPattern.php: -------------------------------------------------------------------------------- 1 | \/\/(.)*)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::COMMENT; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsStaticClassPattern.php: -------------------------------------------------------------------------------- 1 | [A-Z][\w]+)\.'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/JavaScript/Patterns/JsStaticPropertyPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Json/JsonLanguage.php: -------------------------------------------------------------------------------- 1 | (\{|\}))'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Json/Patterns/JsonArrayBracketsPattern.php: -------------------------------------------------------------------------------- 1 | (\[|\]))'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Json/Patterns/JsonDoubleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | \".*?\")'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::VALUE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Json/Patterns/JsonPropertyPattern.php: -------------------------------------------------------------------------------- 1 | \"[\w\\\-]+\")(\s)*\:'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::KEYWORD; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Injections/PhpAttributeInstanceInjection.php: -------------------------------------------------------------------------------- 1 | \#\[[\w]+\((.|\n)*?\)\])'; 20 | } 21 | 22 | public function parseContent(string $content, Highlighter $highlighter): string 23 | { 24 | $theme = $highlighter->getTheme(); 25 | 26 | $parsed = '#[' . $highlighter->parse(str_replace(['#[', ')]'], '', $content), 'php') . ')]'; 27 | 28 | return Escape::injection( 29 | Escape::tokens($theme->before(TokenTypeEnum::ATTRIBUTE)) 30 | . $parsed 31 | . Escape::tokens($theme->after(TokenTypeEnum::ATTRIBUTE)) 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Languages/Php/Injections/PhpAttributePlainInjection.php: -------------------------------------------------------------------------------- 1 | \#\[[\w]+\])'; 20 | } 21 | 22 | public function parseContent(string $content, Highlighter $highlighter): string 23 | { 24 | $theme = $highlighter->getTheme(); 25 | 26 | $parsed = '#[' . $highlighter->parse(str_replace(['#[', ']'], '', $content), 'php') . ']'; 27 | 28 | return Escape::tokens($theme->before(TokenTypeEnum::ATTRIBUTE)) 29 | . $parsed 30 | . Escape::tokens($theme->after(TokenTypeEnum::ATTRIBUTE)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Languages/Php/Injections/PhpDocCommentInjection.php: -------------------------------------------------------------------------------- 1 | \/\*\*(.|\n)*?\*\/)/m'; 19 | } 20 | 21 | public function parseContent(string $content, Highlighter $highlighter): string 22 | { 23 | return $highlighter->parse($content, new PhpDocCommentLanguage()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Languages/Php/Injections/PhpFunctionParametersInjection.php: -------------------------------------------------------------------------------- 1 | (.|\n)*?)({|\)[\s]*({|;|:|=>))'; 20 | } 21 | 22 | public function parseContent(string $content, Highlighter $highlighter): string 23 | { 24 | return Escape::injection( 25 | $highlighter->parse($content, new PhpTypeLanguage()) 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/AttributeTypePattern.php: -------------------------------------------------------------------------------- 1 | [\\\\]*[A-Z][\w\\\\]+)/m'; 31 | } 32 | 33 | public function getTokenType(): TokenTypeEnum 34 | { 35 | return TokenTypeEnum::TYPE; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/CatchTypePattern.php: -------------------------------------------------------------------------------- 1 | [\w\||]+)\)'; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::TYPE; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ClassNamePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::TYPE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ClassPropertyPattern.php: -------------------------------------------------------------------------------- 1 | \\$[\w]+)'; 28 | } 29 | 30 | public function getTokenType(): TokenTypeEnum 31 | { 32 | return TokenTypeEnum::PROPERTY; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ClassResolutionPattern.php: -------------------------------------------------------------------------------- 1 | class)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::KEYWORD; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ConstantNamePattern.php: -------------------------------------------------------------------------------- 1 | [A-Z_]+)\b'; 31 | } 32 | 33 | public function getTokenType(): TokenTypeEnum 34 | { 35 | return TokenTypeEnum::PROPERTY; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ConstantPropertyPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::PROPERTY; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ConstantTypesPattern.php: -------------------------------------------------------------------------------- 1 | .+?)\s[\w]+\s='; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::TYPE; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/DoubleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | "(\\\"|.)*?")'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VALUE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/EnumBackedTypePattern.php: -------------------------------------------------------------------------------- 1 | int|string)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/EnumCasePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)(\s)*(=|;)'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::PROPERTY; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ExtendsPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::TYPE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/FunctionCallPattern.php: -------------------------------------------------------------------------------- 1 | [a-z][\w]+)\('; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::PROPERTY; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/FunctionNamePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::PROPERTY; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/GenericPattern.php: -------------------------------------------------------------------------------- 1 | pattern; 24 | } 25 | 26 | public function getTokenType(): TokenTypeEnum 27 | { 28 | return $this->tokenType; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/GroupedTypePattern.php: -------------------------------------------------------------------------------- 1 | \(\w+(&\w+)+\))'; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::TYPE; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ImplementsPattern.php: -------------------------------------------------------------------------------- 1 | [\s\,\w]+)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/InstanceOfPattern.php: -------------------------------------------------------------------------------- 1 | [\w\\\\]+)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/KeywordPattern.php: -------------------------------------------------------------------------------- 1 | caseInsensitive = true; 24 | 25 | return $this; 26 | } 27 | 28 | public function getPattern(): string 29 | { 30 | $pattern = "/\b(?)(?{$this->keyword})(\$|\,|\)|\;|\:|\s|\()/"; 31 | 32 | if ($this->caseInsensitive) { 33 | $pattern .= 'i'; 34 | } 35 | 36 | return $pattern; 37 | } 38 | 39 | public function getTokenType(): TokenTypeEnum 40 | { 41 | return TokenTypeEnum::KEYWORD; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/MultilineSingleDocCommentPattern.php: -------------------------------------------------------------------------------- 1 | \/\*(.|\n)*?\*\/)/m'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::COMMENT; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/NamedArgumentPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+):\s'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::PROPERTY; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/NamespacePattern.php: -------------------------------------------------------------------------------- 1 | [\w\\\\]+)'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::TYPE; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/NestedFunctionCallPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)\('; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::PROPERTY; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/NewObjectPattern.php: -------------------------------------------------------------------------------- 1 | [\w\\\\]+)'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::TYPE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/OperatorPattern.php: -------------------------------------------------------------------------------- 1 | {$this->operator})(\s|\()/"; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::OPERATOR; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpAsymmetricPropertyPattern.php: -------------------------------------------------------------------------------- 1 | getPattern(); 23 | 24 | if (! str_starts_with($pattern, '/')) { 25 | $pattern = "/$pattern/"; 26 | } 27 | 28 | preg_match_all($pattern, $content, $matches, PREG_OFFSET_CAPTURE); 29 | 30 | return $matches; 31 | } 32 | 33 | public function getPattern(): string 34 | { 35 | return '/(public|private|protected)\((?set)\)/'; 36 | } 37 | 38 | public function getTokenType(): TokenType 39 | { 40 | return TokenTypeEnum::KEYWORD; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpCloseTagPattern.php: -------------------------------------------------------------------------------- 1 | ', output: '?>')] 13 | final readonly class PhpCloseTagPattern implements Pattern 14 | { 15 | use IsPattern; 16 | 17 | public function getPattern(): string 18 | { 19 | return '(?\?\>+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::KEYWORD; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpDocCommentGenericTypePattern.php: -------------------------------------------------------------------------------- 1 | $className', output: 'T')] 13 | final readonly class PhpDocCommentGenericTypePattern implements Pattern 14 | { 15 | use IsPattern; 16 | 17 | public function getPattern(): string 18 | { 19 | return '\<(?[\w]+)\>'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::GENERIC; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpDocCommentParamTypePattern.php: -------------------------------------------------------------------------------- 1 | .*?) \\$'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpDocCommentReturnTypePattern.php: -------------------------------------------------------------------------------- 1 | .*?)(\*\/|$|\R)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpDocCommentReturnTypeSingleLinePattern.php: -------------------------------------------------------------------------------- 1 | .*?)(\s*\*\/|$)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpDocCommentTemplateTypePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::GENERIC; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpDocCommentVarTypePattern.php: -------------------------------------------------------------------------------- 1 | .*?)( \$|\*|$)'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::TYPE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpDocCommentVariablePattern.php: -------------------------------------------------------------------------------- 1 | \\$[\w]+)'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VARIABLE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PhpOpenTagPattern.php: -------------------------------------------------------------------------------- 1 | \<\?[=|php]+)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::KEYWORD; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PropertyAccessPattern.php: -------------------------------------------------------------------------------- 1 | (?[\w]+)'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::PROPERTY; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PropertyHookGetPattern.php: -------------------------------------------------------------------------------- 1 | ', 21 | 'get' 22 | )] 23 | #[PatternTest('get;', 'get')] 24 | final readonly class PropertyHookGetPattern implements Pattern 25 | { 26 | use IsPattern; 27 | 28 | public function getPattern(): string 29 | { 30 | return '(?get)\s*({|=>|;)'; 31 | } 32 | 33 | public function getTokenType(): TokenType 34 | { 35 | return TokenTypeEnum::KEYWORD; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PropertyHookSetParameterTypePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 23 | } 24 | 25 | public function getTokenType(): TokenType 26 | { 27 | return TokenTypeEnum::TYPE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/PropertyHookSetPattern.php: -------------------------------------------------------------------------------- 1 | ', 'set')] 20 | #[PatternTest('set (string $value', 'set')] 21 | #[PatternTest('set(string $value', 'set')] 22 | final readonly class PropertyHookSetPattern implements Pattern 23 | { 24 | use IsPattern; 25 | 26 | public function getPattern(): string 27 | { 28 | return '(?set)\s*({|;|=>|\()'; 29 | } 30 | 31 | public function getTokenType(): TokenType 32 | { 33 | return TokenTypeEnum::KEYWORD; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ReturnTypePattern.php: -------------------------------------------------------------------------------- 1 | [\w\(\)\&\|\?]+)[\s{;\n]'; 28 | } 29 | 30 | public function getTokenType(): TokenTypeEnum 31 | { 32 | return TokenTypeEnum::TYPE; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/ShortFunctionReferencePattern.php: -------------------------------------------------------------------------------- 1 | ', output: 'fn')] 13 | final class ShortFunctionReferencePattern implements Pattern 14 | { 15 | use IsPattern; 16 | 17 | public function getPattern(): string 18 | { 19 | return "(?fn)\&"; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::KEYWORD; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/SingleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | '(\\\'|.)*?')"; 31 | } 32 | 33 | public function getTokenType(): TokenTypeEnum 34 | { 35 | return TokenTypeEnum::VALUE; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/SinglelineCommentPattern.php: -------------------------------------------------------------------------------- 1 | (?:\/\/|#[^\[])(.)*)'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::COMMENT; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/StaticClassCallPattern.php: -------------------------------------------------------------------------------- 1 | [\\\\\w]+)\:\:'; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::TYPE; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/StaticPropertyPattern.php: -------------------------------------------------------------------------------- 1 | \\$[\w]+)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::PROPERTY; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/TypeForVariablePattern.php: -------------------------------------------------------------------------------- 1 | [\w\&\(\)\|\\\\\?]+)\s+(\.*)\\$'; 26 | } 27 | 28 | public function getTokenType(): TokenTypeEnum 29 | { 30 | return TokenTypeEnum::TYPE; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/UntypedClassPropertyPattern.php: -------------------------------------------------------------------------------- 1 | \\$[\w]+)'; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::PROPERTY; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/UseAsPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::TYPE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/UseFunctionNamePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+);'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/UseFunctionPattern.php: -------------------------------------------------------------------------------- 1 | [\w\\\\]+\\\\)[\w]+\;'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::TYPE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/UsePattern.php: -------------------------------------------------------------------------------- 1 | [\w\\\\]+)'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::TYPE; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Php/Patterns/VariablePattern.php: -------------------------------------------------------------------------------- 1 | \\$[\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::VARIABLE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyArgumentPattern.php: -------------------------------------------------------------------------------- 1 | \w+)s*='; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::VARIABLE; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyClassNamePattern.php: -------------------------------------------------------------------------------- 1 | \w*)(?=[\s*\:(])'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::PROPERTY; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyCommentPattern.php: -------------------------------------------------------------------------------- 1 | #.*)'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::COMMENT; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyDecoratorPattern.php: -------------------------------------------------------------------------------- 1 | @\s*\w*(?:\.\w+)*)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::PROPERTY; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyFunctionPattern.php: -------------------------------------------------------------------------------- 1 | \w*)(?=\s*\()'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyKeywordPattern.php: -------------------------------------------------------------------------------- 1 | keywords); 27 | 28 | return "\b(?(?:_(?=\s*:){$keywords}))\b"; 29 | } 30 | 31 | public function getTokenType(): TokenTypeEnum 32 | { 33 | return TokenTypeEnum::KEYWORD; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyLogicalValuePattern.php: -------------------------------------------------------------------------------- 1 | (?:False|None|True))\b'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::LITERAL; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyNumberPattern.php: -------------------------------------------------------------------------------- 1 | \b0(?:[bB](?:_?[01])+|[oO](?:_?[0-7])+|[xX](?:_?[a-fA-F0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:[eE][+-]?\d+(?:_\d+)*)?j?(?!\w))'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::NUMBER; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyOperatorPattern.php: -------------------------------------------------------------------------------- 1 | ([-+&%=]=?|!=|:=|>>=|<<=|\|=|\^=|\*\*?=?|\/\/?=?|<[<=]?|>[=>]?|[\|^~]))"; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::OPERATOR; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyTripleDoubleQuoteStringPattern.php: -------------------------------------------------------------------------------- 1 | """(.|\n)*?""")/m'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::VALUE; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Python/Patterns/PyTripleSingleQuoteStringPattern.php: -------------------------------------------------------------------------------- 1 | \'\'\'(.|\n)*?\'\'\')/m'; 18 | } 19 | 20 | public function getTokenType(): TokenTypeEnum 21 | { 22 | return TokenTypeEnum::VALUE; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlAsTablePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)/i'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlDoubleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | .*?)\"'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::VALUE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlFromTablePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)/i'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlFunctionPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)\(/i'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::PROPERTY; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlJoinTablePattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)/i'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::TYPE; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlMultilineCommentPattern.php: -------------------------------------------------------------------------------- 1 | \/\*(.|\n)*?\*\/)/m'; 27 | } 28 | 29 | public function getTokenType(): TokenTypeEnum 30 | { 31 | return TokenTypeEnum::COMMENT; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlPropertyPattern.php: -------------------------------------------------------------------------------- 1 | (\w)+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlSingleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | .*?)\''; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::VALUE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlSinglelineCommentPattern.php: -------------------------------------------------------------------------------- 1 | \-\-(.)*)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::COMMENT; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlTableAccessPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)\.'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::TYPE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Sql/Patterns/SqlTablePropertyPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Text/TextLanguage.php: -------------------------------------------------------------------------------- 1 | ({{(.|\n)*?}}))'; 20 | } 21 | 22 | public function parseContent(string $content, Highlighter $highlighter): string 23 | { 24 | return Escape::injection($highlighter->parse($content, new TwigEchoLanguage())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Twig/Injections/TwigTagInjection.php: -------------------------------------------------------------------------------- 1 | ({%(.|\n)*?%}))'; 20 | } 21 | 22 | public function parseContent(string $content, Highlighter $highlighter): string 23 | { 24 | return Escape::injection($highlighter->parse($content, new TwigTagLanguage())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigArrayKeyPattern.php: -------------------------------------------------------------------------------- 1 | [\w\-\'\"]+)\:'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::PROPERTY; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigCommentPattern.php: -------------------------------------------------------------------------------- 1 | {# foo #}', output: '{# foo #}')] 21 | final readonly class TwigCommentPattern implements Pattern 22 | { 23 | use IsPattern; 24 | 25 | public function getPattern(): string 26 | { 27 | return '(?\{#(.|\n)*?#})'; 28 | } 29 | 30 | public function getTokenType(): TokenTypeEnum 31 | { 32 | return TokenTypeEnum::COMMENT; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigDoubleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | .*?)"'; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VALUE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigFilterPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigKeywordPattern.php: -------------------------------------------------------------------------------- 1 | {$this->keyword})\b"; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::KEYWORD; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigMethodPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)\('; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigNamedArgumentPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)\='; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigPropertyPattern.php: -------------------------------------------------------------------------------- 1 | [\w]+)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigSingleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | .*?)'"; 23 | } 24 | 25 | public function getTokenType(): TokenTypeEnum 26 | { 27 | return TokenTypeEnum::VALUE; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Languages/Twig/Patterns/TwigTokenPattern.php: -------------------------------------------------------------------------------- 1 | {$this->regex})/"; 24 | } 25 | 26 | public function getTokenType(): TokenTypeEnum 27 | { 28 | return $this->type; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Languages/Twig/TwigLanguage.php: -------------------------------------------------------------------------------- 1 | ', output: 'attr')] 13 | #[PatternTest(input: '', output: 'href')] 14 | #[PatternTest(input: '', output: 'data-type')] 15 | final readonly class XmlAttributePattern implements Pattern 16 | { 17 | use IsPattern; 18 | 19 | public function getPattern(): string 20 | { 21 | return '(?[\w\-]+)="'; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::PROPERTY; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Xml/Patterns/XmlCloseTagPattern.php: -------------------------------------------------------------------------------- 1 | ', output: 'x-hello')] 13 | #[PatternTest(input: '', output: 'a')] 14 | final readonly class XmlCloseTagPattern implements Pattern 15 | { 16 | use IsPattern; 17 | 18 | public function getPattern(): string 19 | { 20 | return '<\/(?[\w\-]+)'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::KEYWORD; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Xml/Patterns/XmlCommentPattern.php: -------------------------------------------------------------------------------- 1 | 17 | test', 18 | output: '' 21 | )] 22 | #[PatternTest(input: '
', output: ['',''])] 23 | final readonly class XmlCommentPattern implements Pattern 24 | { 25 | use IsPattern; 26 | 27 | public function getPattern(): string 28 | { 29 | return '/(?\)/mU'; 30 | } 31 | 32 | public function getTokenType(): TokenTypeEnum 33 | { 34 | return TokenTypeEnum::COMMENT; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Languages/Xml/Patterns/XmlOpenTagPattern.php: -------------------------------------------------------------------------------- 1 | ', output: 'x-hello')] 13 | #[PatternTest(input: '', output: 'a')] 14 | #[PatternTest(input: '
', output: 'br')] 15 | final readonly class XmlOpenTagPattern implements Pattern 16 | { 17 | use IsPattern; 18 | 19 | public function getPattern(): string 20 | { 21 | return '<(?[\w\-]+)'; 22 | } 23 | 24 | public function getTokenType(): TokenTypeEnum 25 | { 26 | return TokenTypeEnum::KEYWORD; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Languages/Xml/XmlLanguage.php: -------------------------------------------------------------------------------- 1 | (\[|\]))'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlColonPattern.php: -------------------------------------------------------------------------------- 1 | :)/m'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::PROPERTY; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlCommentPattern.php: -------------------------------------------------------------------------------- 1 | \#(.)*)'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::COMMENT; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlDashPattern.php: -------------------------------------------------------------------------------- 1 | -)/m'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlDoubleAccoladesValuePattern.php: -------------------------------------------------------------------------------- 1 | (\{\{|\}\}))'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::VALUE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlDoubleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | .*?)\"'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::VALUE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlObjectBracketsPattern.php: -------------------------------------------------------------------------------- 1 | (\{|\}))'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlPipePattern.php: -------------------------------------------------------------------------------- 1 | \|)/m'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlPropertyPattern.php: -------------------------------------------------------------------------------- 1 | [\w-]+)\:'; 21 | } 22 | 23 | public function getTokenType(): TokenTypeEnum 24 | { 25 | return TokenTypeEnum::KEYWORD; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlSingleQuoteValuePattern.php: -------------------------------------------------------------------------------- 1 | .*?)\''; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::VALUE; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Languages/Yaml/Patterns/YamlVariablePattern.php: -------------------------------------------------------------------------------- 1 | [\w\s\.]+)\}\}'; 20 | } 21 | 22 | public function getTokenType(): TokenTypeEnum 23 | { 24 | return TokenTypeEnum::PROPERTY; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/ParsedInjection.php: -------------------------------------------------------------------------------- 1 | value; 16 | } 17 | 18 | public function canContain(TokenType $other): bool 19 | { 20 | return $this->getValue() !== $other->getValue(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Tokens/IgnoreTokenType.php: -------------------------------------------------------------------------------- 1 | value; 26 | } 27 | 28 | public function canContain(TokenType $other): bool 29 | { 30 | if ($this === $other) { 31 | return false; 32 | } 33 | 34 | return match ($this) { 35 | self::TYPE => ! in_array($other->getValue(), [self::KEYWORD->getValue(), self::PROPERTY->getValue()]), 36 | self::GENERIC => ! in_array($other->getValue(), [self::TYPE->getValue()]), 37 | self::ATTRIBUTE => true, 38 | default => false, 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/WebTheme.php: -------------------------------------------------------------------------------- 1 | withGutter(); 9 | 10 | $target = $argc > 1 11 | ? $argv[1] 12 | : 'targets' . DIRECTORY_SEPARATOR . 'test.md'; 13 | 14 | $code = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . $target); 15 | 16 | preg_match('/```(\w+)/', $code, $matches); 17 | 18 | $language = count($matches) > 0 19 | ? $matches[1] 20 | : 'html'; 21 | 22 | $code = str_replace( 23 | ['```' . $language, '```'], 24 | '', 25 | $code, 26 | ); 27 | 28 | echo PHP_EOL, $highlighter->parse($code, $language), PHP_EOL, PHP_EOL; 29 | -------------------------------------------------------------------------------- /tests/CommonMark/HighlightExtensionTest.php: -------------------------------------------------------------------------------- 1 | addExtension(new CommonMarkCoreExtension()) 22 | ->addExtension(new HighlightExtension()) 23 | ->addExtension(new FrontMatterExtension()); 24 | 25 | $markdown = new MarkdownConverter($environment); 26 | 27 | $parsed = $markdown->convert("```php 28 | class Foo {} 29 | ```"); 30 | 31 | $this->assertStringContainsString('hl-keyword', $parsed->getContent()); 32 | $this->assertStringContainsString('data-lang="php"', $parsed->getContent()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Languages/Base/Injections/AdditionInjectionTest.php: -------------------------------------------------------------------------------- 1 | class Foo 22 | TXT; 23 | 24 | $parsedInjection = (new AdditionInjection())->parse($content, new Highlighter()); 25 | 26 | $this->assertSame($expected, Escape::html($parsedInjection->content)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Languages/Base/Injections/DeletionInjectionTest.php: -------------------------------------------------------------------------------- 1 | class Foo 22 | TXT; 23 | 24 | $parsedInjection = (new DeletionInjection())->parse($content, new Highlighter()); 25 | 26 | $this->assertSame($expected, Escape::html($parsedInjection->content)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Languages/Blade/BladeLanguageTest.php: -------------------------------------------------------------------------------- 1 | assertSame( 19 | $expected, 20 | $highlighter->parse($content, 'blade'), 21 | ); 22 | } 23 | 24 | public static function data(): array 25 | { 26 | return [ 27 | ['{{-- Blade comment --}}', '{{-- Blade comment --}}'], 28 | ['{{-- if --}}', '{{-- if --}}'], 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Languages/Blade/Injections/BladeEchoInjectionTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 20 | injection: new BladeEchoInjection(), 21 | content: '{{ count($foo) }}', 22 | expectedContent: '{{ count($foo) }}', 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/Languages/Blade/Injections/BladeKeywordInjectionTest.php: -------------------------------------------------------------------------------- 1 | parse($content, $highlighter); 23 | 24 | $this->assertStringContainsString( 25 | 'count', 26 | $parsedInjection->content, 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Languages/Blade/Injections/BladePhpInjectionTest.php: -------------------------------------------------------------------------------- 1 | parse($content, $highlighter); 27 | 28 | $this->assertStringContainsString( 29 | 'count', 30 | $parsedInjection->content, 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/Languages/Blade/Injections/BladeRawEchoInjectionTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 20 | injection: new BladeRawEchoInjection(), 21 | content: '{!! count($foo) !!}', 22 | expectedContent: '{!! count($foo) !!}', 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/Languages/Css/Injections/CssAttributeInjectionTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 20 | injection: new CssAttributeInHtmlInjection(), 21 | content: '', 22 | expectedContent: '<x-slot style="color: green">' 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/Languages/Diff/DiffLanguageTest.php: -------------------------------------------------------------------------------- 1 | assertSame( 19 | $expected, 20 | $highlighter->parse($content, 'diff'), 21 | ); 22 | } 23 | 24 | public static function data(): array 25 | { 26 | return [ 27 | [<<<'TXT' 28 | + $this->newCode(); 29 | - $this->oldCode(); 30 | TXT, 31 | <<<'TXT' 32 | + $this->newCode(); 33 | - $this->oldCode(); 34 | TXT 35 | ], 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Languages/Json/JsonLanguageTest.php: -------------------------------------------------------------------------------- 1 | assertSame( 19 | $expected, 20 | $highlighter->parse($content, 'json'), 21 | ); 22 | } 23 | 24 | public static function data(): array 25 | { 26 | return [ 27 | [ 28 | '{ 29 | "key": "value", 30 | "array": ["bar"] 31 | }', 32 | '{ 33 | "key": "value", 34 | "array": ["bar"] 35 | }', 36 | ], 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Languages/Php/Injections/PhpShortEchoInjectionTest.php: -------------------------------------------------------------------------------- 1 | name ?> 21 | Hello, other ?> 22 | '; 23 | 24 | $expected = ' 25 | Hello, <?= $this->name ?> 26 | Hello, <?= $this->other ?> 27 | '; 28 | 29 | $this->assertMatches( 30 | injection: new PhpShortEchoInHtmlInjection(), 31 | content: $content, 32 | expectedContent: $expected, 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/ClassNamePatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new ClassNamePattern(), 19 | content: 'class Foo implements Bar', 20 | expected: 'Foo', 21 | ); 22 | 23 | $this->assertMatches( 24 | pattern: new ClassNamePattern(), 25 | content: 'interface Foo implements Bar', 26 | expected: 'Foo', 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/ConstantPropertyPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new ConstantPropertyPattern(), 19 | content: 'Foo::BAR', 20 | expected: 'BAR', 21 | ); 22 | 23 | $this->assertMatches( 24 | pattern: new ConstantPropertyPattern(), 25 | content: 'Foo::BAR()', 26 | expected: 'BAR', 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/ExtendsPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new ExtendsPattern(), 19 | content: 'class Foo extends Bar', 20 | expected: 'Bar', 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/FunctionCallPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new FunctionCallPattern(), 19 | content: 'foo()', 20 | expected: 'foo', 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/FunctionNamePatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new FunctionNamePattern(), 19 | content: 'function foo()', 20 | expected: 'foo', 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/KeywordPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new KeywordPattern('match'), 19 | content: 'match ()', 20 | expected: 'match', 21 | ); 22 | 23 | $this->assertMatches( 24 | pattern: new KeywordPattern('return'), 25 | content: 'return ()', 26 | expected: 'return', 27 | ); 28 | 29 | $this->assertMatches( 30 | pattern: new KeywordPattern('class'), 31 | content: 'class ()', 32 | expected: 'class', 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/MultilineSingleDocCommentPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new MultilineSingleDocCommentPattern(), 19 | content: ' 20 | use Tempest\Highlight\Token; 21 | 22 | /* world 23 | * hello 24 | */ 25 | final class PhpLanguage implements Language 26 | ', 27 | expected: '/* world 28 | * hello 29 | */', 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/NamedArgumentPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new NamedArgumentPattern(), 19 | content: '#[Foo(prop: hi)]', 20 | expected: 'prop', 21 | ); 22 | 23 | $this->assertMatches( 24 | pattern: new NamedArgumentPattern(), 25 | content: 'foo(bar: $a, baz: $b)', 26 | expected: ['bar', 'baz'], 27 | ); 28 | 29 | $this->assertMatches( 30 | pattern: new NamedArgumentPattern(), 31 | content: 'foo( 32 | bar: $a, 33 | baz: $b 34 | )', 35 | expected: ['bar', 'baz'], 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/NamespacePatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new NamespacePattern(), 19 | content: 'namespace Foo\Bar', 20 | expected: 'Foo\Bar', 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/NestedFunctionCallPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new NestedFunctionCallPattern(), 19 | content: ' foo()', 20 | expected: 'foo', 21 | ); 22 | 23 | $this->assertMatches( 24 | pattern: new NestedFunctionCallPattern(), 25 | content: '(foo()', 26 | expected: 'foo', 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/PropertyAccessPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new PropertyAccessPattern(), 19 | content: '$this->foo', 20 | expected: 'foo', 21 | ); 22 | 23 | $this->assertMatches( 24 | pattern: new PropertyAccessPattern(), 25 | content: '$this->foo()', 26 | expected: 'foo', 27 | ); 28 | 29 | $this->assertMatches( 30 | pattern: new PropertyAccessPattern(), 31 | content: '$obj->foo', 32 | expected: 'foo', 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/SinglelineDocCommentPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new SinglelineCommentPattern(), 19 | content: '$bar // foo', 20 | expected: '// foo', 21 | ); 22 | 23 | $this->assertMatches( 24 | pattern: new SinglelineCommentPattern(), 25 | content: '$bar # foo', 26 | expected: '# foo', 27 | ); 28 | 29 | $this->assertMatches( 30 | pattern: new SinglelineCommentPattern(), 31 | content: '$bar #[IncompleteAttribute', 32 | expected: null, 33 | ); 34 | 35 | $this->assertMatches( 36 | pattern: new SinglelineCommentPattern(), 37 | content: '$bar #[Attribute]', 38 | expected: null, 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Languages/Php/Patterns/UsePatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new UsePattern(), 19 | content: 'use Foo\Bar\Baz;', 20 | expected: 'Foo\Bar\Baz', 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Languages/Text/TextLanguageTest.php: -------------------------------------------------------------------------------- 1 | assertSame( 19 | $expected, 20 | $highlighter->parse($content, 'txt'), 21 | ); 22 | 23 | $this->assertSame( 24 | $expected, 25 | $highlighter->parse($content, 'text'), 26 | ); 27 | } 28 | 29 | public static function data(): array 30 | { 31 | return [ 32 | ['test', 'test'], 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Languages/Twig/Injections/TwigEchoInjectionTest.php: -------------------------------------------------------------------------------- 1 | Version {{ appVersion }}'; 20 | 21 | $expected = '<b>Version</b> {{ appVersion }}'; 22 | 23 | $this->assertMatches( 24 | injection: new TwigEchoInjection(), 25 | content: $content, 26 | expectedContent: $expected, 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Languages/Twig/Patterns/TwigKeywordPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 18 | pattern: new TwigKeywordPattern("extends"), 19 | content: "{% extends 'admin/empty_base.html.twig' %}", 20 | expected: 'extends', 21 | ); 22 | 23 | $this->assertMatches( 24 | pattern: new TwigKeywordPattern("if"), 25 | content: "{% if is_granted('IS_IMPERSONATOR') %}", 26 | expected: 'if', 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Languages/Twig/Patterns/TwigTokenPatternTest.php: -------------------------------------------------------------------------------- 1 | assertMatches( 19 | pattern: new TwigTokenPattern("^{%", TokenTypeEnum::TYPE), 20 | content: "{% extends 'admin/empty_base.html.twig' %}", 21 | expected: '{%', 22 | ); 23 | 24 | $this->assertMatches( 25 | pattern: new TwigTokenPattern("}}$", TokenTypeEnum::TYPE), 26 | content: "{{ path('app.logout') }}", 27 | expected: '}}', 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Languages/Xml/XmlLanguageTest.php: -------------------------------------------------------------------------------- 1 | assertSame( 19 | $expected, 20 | $highlighter->parse($content, 'xml'), 21 | ); 22 | } 23 | 24 | public static function data(): array 25 | { 26 | return [ 27 | [<< 29 |
30 | 31 | 32 | 33 | TXT, 34 | <<tag
attr=""> 36 | <br/> 37 | 38 | <!-- comment --> 39 | </tag> 40 | TXT], 41 | ]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/TestsInjections.php: -------------------------------------------------------------------------------- 1 | nested(); 21 | 22 | if ($currentLanguage) { 23 | $highlighter->setCurrentLanguage($currentLanguage); 24 | } 25 | 26 | $parsedInjection = $injection->parse($content, $highlighter); 27 | 28 | if (is_string($parsedInjection)) { 29 | $content = $parsedInjection; 30 | } else { 31 | $content = $parsedInjection->content; 32 | } 33 | 34 | $output = Escape::html($content); 35 | 36 | $this->assertSame( 37 | $expectedContent, 38 | $output, 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Themes/InlineThemeTest.php: -------------------------------------------------------------------------------- 1 | expectException(Exception::class); 16 | 17 | new InlineTheme('invalid/path.css'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Themes/LightTerminalThemeTest.php: -------------------------------------------------------------------------------- 1 | parse('{~}): Foo {}~}', 'php'); 19 | 20 | $this->assertStringNotContainsString(Escape::INJECTION_TOKEN, $parsed); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Themes/TerminalThemeTest.php: -------------------------------------------------------------------------------- 1 | parse($content, 'php'); 22 | 23 | $this->assertSame( 24 | "\e[34mpublic\e[0m \e[34mfunction\e[0m \e[32mbefore\e[0m", 25 | $output, 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/TokenTest.php: -------------------------------------------------------------------------------- 1 | assertTrue($a->containsOrOverlaps($b)); 30 | $this->assertFalse($b->containsOrOverlaps($a)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/stylesheets/ellison.css: -------------------------------------------------------------------------------- 1 | .hl-moderate-sentence { 2 | background-color: #fef9c3; 3 | } 4 | 5 | .hl-complex-sentence { 6 | background-color: #fee2e2; 7 | } 8 | 9 | .hl-adverb-phrase { 10 | background-color: #e0f2fe; 11 | } 12 | 13 | .hl-passive-phrase { 14 | background-color: #dcfce7; 15 | } 16 | 17 | .hl-complex-phrase { 18 | background-color: #f3e8ff; 19 | } 20 | 21 | .hl-qualified-phrase { 22 | background-color: #f1f5f9; 23 | } 24 | -------------------------------------------------------------------------------- /tests/targets/ellison.md: -------------------------------------------------------------------------------- 1 | ```ellison 2 | The app highlights lengthy, complex sentences and common errors; if you see a yellow sentence, shorten or split it. If you see a red highlight, your sentence is so dense and complicated that your readers will get lost trying to follow its meandering, splitting logic — try editing this sentence to remove the red. 3 | 4 | You can utilize a shorter word in place of a purple one. Click on highlights to fix them. 5 | 6 | Adverbs and weakening phrases are helpfully shown in blue. Get rid of them and pick words with force, perhaps. 7 | 8 | Phrases in green have been marked to show passive voice. 9 | ``` 10 | -------------------------------------------------------------------------------- /tests/targets/gdscript.md: -------------------------------------------------------------------------------- 1 | ```gdscript 2 | extends CharacterBody2D 3 | class_name GamePlayer 4 | 5 | @export var navigation : NavigationRegion2D 6 | @export var speed : int = 75 7 | 8 | @onready var agent := %Agent as NavigationAgent2D 9 | 10 | func _ready() -> void: 11 | agent.max_speed = speed 12 | 13 | agent.connect("velocity_computed", func(new_velocity: Vector2): 14 | # use velocity_computed so that obstacles are avoided 15 | if not agent.is_navigation_finished(): 16 | velocity = new_velocity 17 | move_and_slide() 18 | ) 19 | 20 | func _physics_process(_delta) -> void: 21 | var next_location = agent.get_next_path_position() 22 | 23 | if global_position.distance_to(next_location) > 1: 24 | update_navigation() 25 | 26 | if not agent.is_navigation_finished(): 27 | var next_move_position = agent.get_next_path_position() - global_position 28 | agent.velocity = next_move_position * speed 29 | 30 | if Input.is_action_pressed("ui_move"): 31 | agent.target_position = get_global_mouse_position() 32 | 33 | func update_navigation() -> void: 34 | # move the navigation region so that the player is always in the center 35 | navigation.global_position = global_position - (get_viewport().get_visible_rect().size / 2) 36 | navigation.bake_navigation_polygon() 37 | ``` 38 | -------------------------------------------------------------------------------- /tests/targets/python.md: -------------------------------------------------------------------------------- 1 | ```py 2 | # Python program to check if the input number is odd or even. 3 | # A number is even if division by 2 gives a remainder of 0. 4 | # If the remainder is 1, it is an odd number. 5 | 6 | num = int(input("Enter a number: ")) 7 | if (num % 2) == 0: 8 | print("{0} is Even".format(num)) 9 | else: 10 | print("{0} is Odd".format(num)) 11 | ``` -------------------------------------------------------------------------------- /tests/targets/test.md: -------------------------------------------------------------------------------- 1 | ```php 2 | public function __construct( 3 | private(set) Author $author, 4 | ) {} 5 | ``` --------------------------------------------------------------------------------