Skip to content

Commit ab8485e

Browse files
committed
initiail commit
0 parents  commit ab8485e

11 files changed

+873
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
/.idea

LICENSE

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

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# PHP Prettify
2+
3+
Creates a syntax highlighted version of the given PHP code.
4+
5+
```php
6+
<?php
7+
8+
use PhpPrettify\Highlight;
9+
10+
echo '<pre>', (new Highlight)->render('$name = "foobar"'), '</pre>';
11+
````
12+
13+
#### Highlighting a file
14+
```php
15+
<?php
16+
17+
use PhpPrettify\Highlight;
18+
19+
echo '<pre>', (new Highlight)
20+
->setTheme('bittr') // Sets code highlight theme.
21+
->setStyle('body {margin:0;padding:0}') // Append css to default to style.
22+
->setHighlight(22, ['style' => 'color:red']) // Add html attributes to selected line(tr).
23+
->showLineNumber(1, false) // Show line number starting from line 1 and prevent selection of line number.
24+
->render('code.txt', true),
25+
'</pre>';
26+
```
27+
28+
![alt tag](https://github.com/Ghostff/php_prettify/blob/master/images/dark.png)
29+
![alt tag](https://github.com/Ghostff/php_prettify/blob/master/images/light.png)

code.txt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Text;
5+
use PhpPrettify as Php;
6+
7+
#[AttrCommas('foo'), AttrCommas(2342)]
8+
class Text extends Namespace\TextProcess implements Php
9+
{
10+
/**
11+
* An array of the types that have been resolved.
12+
*
13+
* @var array
14+
*/
15+
protected $resolved = array();
16+
17+
public function isShared(#[Attr('foo')] string $abstract, int &$counter): bool
18+
{
19+
self::init(mt_rand(1, 55), parent::__construct(), ROOT_DIR);
20+
if (isset($this->bindings[$abstract]['shared']) && ($counter != 0))
21+
{
22+
#cast to bool
23+
(bool) $shared = $this->bindings[$abstract]['shared'];
24+
}
25+
else
26+
{
27+
$counter--;
28+
$shared = false;
29+
}
30+
31+
#smart function type dictation
32+
self::hash(hash('sha1', 'foobar'), $this->hash());
33+
return (isset($this->instances[$abstract]) || $shared === true);
34+
}
35+
}

composer.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "ghostff/php_prettify",
3+
"description": "Creates a syntax highlighted version of the given PHP code.",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"ghostff\\Highlight\\": "src"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "ghostff",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"require": {
18+
"php": ">=5.3"
19+
}
20+
}

demo.html

+80
Large diffs are not rendered by default.

images/dark.png

41 KB
Loading

images/light.png

38.8 KB
Loading

index.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
use PhpPrettify\Highlight;
3+
4+
include_once 'src/Highlight.php';
5+
6+
echo '<pre>',
7+
(new Highlight)
8+
->setTheme('bittr') // Sets code highlight theme.
9+
->setStyle('body {margin:0;padding:0}') // Append css to default to style.
10+
->setHighlight(22, ['style' => 'color:red']) // Add html attributes to selected line(tr).
11+
->showLineNumber(1, false) // Show line number starting from line 1 and prevent selection of line number.
12+
->render('code.txt', true),
13+
'</pre>';
14+
15+
?>

0 commit comments

Comments
 (0)