Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
!/vendor
/vendor/*
!/vendor/easybook
!/vendor/autoload.php
!/vendor/composer
vendor/
34 changes: 34 additions & 0 deletions acp/pastebin_info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
*
* Pastebin extension for the phpBB Forum Software package.
*
* @copyright (c) 2024 Crizzo <https://www.phpBB.de>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace phpbbde\pastebin\acp;

class pastebin_info
{
function module()
{
return array(
'filename' => '\phpbbde\pastebin\acp\pastebin_info',
'title' => 'ACP_PASTEBIN_TITLE',
'modes' => array(
'pastebin_settings' => array(
'title' => 'ACP_PASTEBIN_SETTINGS',
'auth' => 'ext_phpbbde/pastebin && acl_a_board',
'cat' => array('ACP_PASTEBIN_TITLE')
),
'pastebin_languages' => array(
'title' => 'ACP_PASTEBIN_LANGUAGES',
'auth' => 'ext_phpbbde/pastebin && acl_a_board',
'cat' => array('ACP_PASTEBIN_TITLE')
),
),
);
}
}
24 changes: 24 additions & 0 deletions acp/pastebin_module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
*
* Pastebin extension for the phpBB Forum Software package.
*
* @copyright (c) 2024 Crizzo <https://www.phpBB.de>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace phpbbde\pastebin\acp;

/**
* @ignore
*/


/**
* @package acp
*/
class pastebin_module
{

}
9 changes: 9 additions & 0 deletions assets/tempest/highlight/LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2024 Brent Roose brendt@stitcher.io

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
Binary file added assets/tempest/highlight/LICENCE.md:Zone.Identifier
Binary file not shown.
18 changes: 18 additions & 0 deletions assets/tempest/highlight/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Fast, extensible, server-side code highlighting
[![Coverage Status](https://coveralls.io/repos/github/tempestphp/highlight/badge.svg?branch=main)](https://coveralls.io/github/tempestphp/highlight?branch=main)

## Quickstart

```php
composer require tempest/highlight
```

Highlight code like this:

```php
$highlighter = new \Tempest\Highlight\Highlighter();

$code = $highlighter->parse($code, 'php');
```

Continue reading in the docs: [https://tempestphp.com/main/packages/highlight](https://tempestphp.com/main/packages/highlight).
Binary file added assets/tempest/highlight/README.md:Zone.Identifier
Binary file not shown.
48 changes: 48 additions & 0 deletions assets/tempest/highlight/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "tempest/highlight",
"description": "Fast, extensible, server-side code highlighting",
"autoload": {
"psr-4": {
"Tempest\\Highlight\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tempest\\Highlight\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "Brent Roose",
"email": "brendt@stitcher.io"
}
],
"require": {
"php": "^8.4"
},
"require-dev": {
"phpunit/phpunit": "^12.0",
"phpstan/phpstan": "^2.1",
"friendsofphp/php-cs-fixer": "^3.84",
"league/commonmark": "^2.4",
"assertchris/ellison": "^1.0.2",
"symfony/var-dumper": "^6.4|^7.0|^8.0",
"phpbench/phpbench": "^1.4"
},
"suggest": {
"assertchris/ellison": "Allows you to analyse sentence complexity",
"league/commonmark": "Adds markdown support"
},
"scripts": {
"phpunit": "vendor/bin/phpunit --display-warnings --display-skipped --display-deprecations --display-errors --display-notices",
"csfixer": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"phpstan": "vendor/bin/phpstan analyse src tests",
"qa": [
"composer csfixer",
"composer phpstan",
"composer phpunit"
],
"bench": "vendor/bin/phpbench run --report=aggregate"
},
"license": "MIT"
}
Binary file not shown.
9 changes: 9 additions & 0 deletions assets/tempest/highlight/phpbench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "./vendor/phpbench/phpbench/phpbench.schema.json",
"runner.bootstrap": "vendor/autoload.php",
"runner.path": "tests/Bench",
"runner.file_pattern": "*Bench.php",
"core.extensions": [
"Tempest\\Highlight\\Tests\\Bench\\Extension\\MarkdownExtension"
]
}
Binary file not shown.
12 changes: 12 additions & 0 deletions assets/tempest/highlight/src/After.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
final readonly class After
{
}
Binary file not shown.
12 changes: 12 additions & 0 deletions assets/tempest/highlight/src/Before.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
final readonly class Before
{
}
Binary file not shown.
48 changes: 48 additions & 0 deletions assets/tempest/highlight/src/CommonMark/CodeBlockRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\CommonMark;

use InvalidArgumentException;
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
use League\CommonMark\Node\Node;
use League\CommonMark\Renderer\ChildNodeRendererInterface;
use League\CommonMark\Renderer\NodeRendererInterface;
use Tempest\Highlight\Highlighter;
use Tempest\Highlight\WebTheme;

final readonly class CodeBlockRenderer implements NodeRendererInterface
{
public function __construct(
private Highlighter $highlighter = new Highlighter(),
) {
}

public function render(Node $node, ChildNodeRendererInterface $childRenderer)
{
if (! $node instanceof FencedCode) {
throw new InvalidArgumentException('Block must be instance of ' . FencedCode::class);
}

preg_match('/^(?<language>[\w]+)(\{(?<startAt>[\d]+)\})?/', $node->getInfoWords()[0] ?? 'txt', $matches);

$highlighter = $this->highlighter;

if ($startAt = ($matches['startAt']) ?? null) {
$highlighter = $highlighter->withGutter((int)$startAt);
}

$language = $matches['language'] ?? 'txt';

$parsed = $highlighter->parse($node->getLiteral(), $language);

$theme = $highlighter->getTheme();

if ($theme instanceof WebTheme) {
return $theme->preBefore($highlighter) . $parsed . $theme->preAfter($highlighter);
}

return '<pre data-lang="' . $language . '" class="notranslate">' . $parsed . '</pre>';
}
}
Binary file not shown.
27 changes: 27 additions & 0 deletions assets/tempest/highlight/src/CommonMark/HighlightExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\CommonMark;

use League\CommonMark\Environment\EnvironmentBuilderInterface;
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
use League\CommonMark\Extension\CommonMark\Node\Inline\Code;
use League\CommonMark\Extension\ExtensionInterface;
use Tempest\Highlight\Highlighter;

final readonly class HighlightExtension implements ExtensionInterface
{
public function __construct(
private ?Highlighter $highlighter = new Highlighter(),
) {
}

public function register(EnvironmentBuilderInterface $environment): void
{
$environment
->addRenderer(FencedCode::class, new CodeBlockRenderer($this->highlighter), 10)
->addRenderer(Code::class, new InlineCodeBlockRenderer($this->highlighter), 10)
;
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\CommonMark;

use InvalidArgumentException;
use League\CommonMark\Extension\CommonMark\Node\Inline\Code;
use League\CommonMark\Node\Node;
use League\CommonMark\Renderer\ChildNodeRendererInterface;
use League\CommonMark\Renderer\NodeRendererInterface;
use Tempest\Highlight\Highlighter;

final readonly class InlineCodeBlockRenderer implements NodeRendererInterface
{
public function __construct(
private Highlighter $highlighter = new Highlighter(),
) {
}

public function render(Node $node, ChildNodeRendererInterface $childRenderer)
{
if (! $node instanceof Code) {
throw new InvalidArgumentException('Block must be instance of ' . Code::class);
}

preg_match('/^\{(?<match>[\w]+)}(?<code>.*)/', $node->getLiteral(), $match);

$language = $match['match'] ?? 'txt';
$code = $match['code'] ?? $node->getLiteral();

return '<code>' . $this->highlighter->parse($code, $language) . '</code>';
}
}
Binary file not shown.
57 changes: 57 additions & 0 deletions assets/tempest/highlight/src/Escape.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight;

final readonly class Escape
{
public const string INJECTION_TOKEN = '❿';

private const array TOKEN_KEYS = ['❶', '❷', '❸', '❹', self::INJECTION_TOKEN];

private const array TOKEN_VALUES = ['&', '<', '>', '"', ''];

public static function injection(string $input): string
{
return self::INJECTION_TOKEN . $input . self::INJECTION_TOKEN;
}

public static function terminal(string $input): string
{
return preg_replace(
['/❷(.*?)❸/', '/❿/'],
'',
$input,
);
}

public static function html(string $input): string
{
return self::reverse(
str_replace(
['&', '<', '>', '"'],
['&amp;', '&lt;', '&gt;', '&quot;'],
$input,
),
);
}

public static function tokens(string $input): string
{
return str_replace(
self::TOKEN_VALUES,
self::TOKEN_KEYS,
$input,
);
}

private static function reverse(string $input): string
{
return str_replace(
self::TOKEN_KEYS,
self::TOKEN_VALUES,
$input,
);
}
}
Binary file not shown.
Loading