Skip to content

Commit 4782063

Browse files
authored
Merge pull request #4 from demyanovs/release-2.0.0
Release 2.0.0
2 parents b9fbee2 + 101f8e3 commit 4782063

29 files changed

+871
-2507
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
language: php
22

33
php:
4-
- 7.1
5-
- 7.2
6-
- 7.3
4+
- 8.1
5+
- 8.2
76

87
before_script:
98
- travis_retry composer update
109

1110
script:
12-
- vendor/bin/phpunit
11+
- ./vendor/bin/phpunit
1312

1413
jobs:
1514

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [1.0.0] - 2019-05-20
8-
- Inital release
8+
- Initial release
99

1010
## [1.0.1] - 2019-06-03
1111
- Replaced theme css by class
@@ -19,3 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
## [1.1.1] - 2020-01-15
2121
- Added c64 theme
22+
23+
## [2.0.0] - 2023-06-03
24+
- Completely redesigned project structure
25+
- Updated syntaxes to PHP 8.1
26+
- Updated examples

README.md

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# PHPHighlight
22

3-
PHPHighlight is a PHP library for highlighting syntax that can be easily configured and extended.
3+
PHPHighlight is a PHP syntax highlighting library that can be easily customized and extended.
44

5-
The library parses the text, finds the tag \<pre>, read attributes (data-lang, data-file, data-theme), and for this reason decides how to highlight the syntax of this block.
6-
Supports style customization.
5+
## How it works
6+
The library parses the text, finds the \<pre> tag, reads the attributes (data-lang, data-file, data-theme) and highlights the syntax of the code block.
77

8-
Here are examples of styling:
8+
Supports style customization. Here are examples of styling:
99

10-
<img width="757" height="309" src="https://demyanov.dev/sites/default/files/images/phphighlight2.png">
10+
<img width="757" height="309" src="https://demyanov.dev/sites/default/files/images/phphighlight2.png" alt="styling example">
1111

1212
## Requirements
13-
PHP 7.1+
13+
PHP 8.1+
1414

1515
## Installation
1616
You can install package via composer
@@ -19,7 +19,7 @@ $ composer require demyanovs/php-highlight
1919
```
2020

2121
## Usage
22-
See examples here [index.php](../master/examples/index.php)
22+
See full example here [index.php](../master/examples/index.php)
2323
```php
2424
<?php
2525

@@ -29,12 +29,11 @@ use Demyanovs\PHPHighlight\Highlighter;
2929

3030
$text = '
3131
<pre data-file="php-highlight/examples/index.php" data-lang="php">
32+
&lt;?php
3233
abstract class AbstractClass
3334
{
3435
/**
3536
* Our abstract method only needs to define the required arguments
36-
* @param string $name
37-
* @return string
3837
*/
3938
abstract protected function prefixName(string $name): string;
4039
}
@@ -43,20 +42,19 @@ class ConcreteClass extends AbstractClass
4342
{
4443
/**
4544
* Our child class may define optional arguments not in the parent\'s signature
46-
* @param string $name
47-
* @param string $separator
48-
* @return string
4945
*/
50-
public function prefixName(string $name, string $separator = ".") : string
46+
public function prefixName(string $name): string
5147
{
52-
if ($name == "Pacman") {
53-
$prefix = "Mr";
54-
} elseif ($name == "Pacwoman") {
55-
$prefix = "Mrs";
48+
$prefix = "";
49+
if ($name === "Pacman") {
50+
$prefix = "Mr.";
51+
} elseif ($name === "Pacwoman") {
52+
$prefix = "Mrs.";
5653
} else {
57-
$prefix = "";
54+
5855
}
59-
return "{$prefix}{$separator} {$name}";
56+
57+
return $prefix . " " . $name;
6058
}
6159
}
6260

@@ -66,13 +64,44 @@ echo $class->prefixName("Pacwoman"), "\n";
6664
</pre>
6765
';
6866

69-
$highlighter = new Highlighter($text, 'railscasts');
67+
$highlighter = new Highlighter($text, ObsidianTheme::TITLE);
7068
// Configuration
71-
$highlighter->setShowLineNumbers(true);
72-
$highlighter->setShowActionPanel(true);
69+
$highlighter->showLineNumbers(true);
70+
$highlighter->showActionPanel(true);
7371
echo $highlighter->parse();
7472
```
75-
### Language syntax support
73+
74+
### Customization
75+
```php
76+
$highlighter->showLineNumbers(true);
77+
$highlighter->showActionPanel(true);
78+
```
79+
80+
You can set following attributes in \<pre> tag
81+
\<pre data-lang="php" data-file="example.php" data-theme="drakuala">
82+
* lang - a language of the text. This affects how the parser will highlight the syntax.
83+
* file - show file name in action panel.
84+
* theme - allows to overwrite the global theme.
85+
86+
### How to create a custom theme
87+
To create a custom theme you need to create an instance of Demyanovs\PHPHighlight\Themes\Theme class
88+
and pass it to Highlighter as a third argument:
89+
```php
90+
$defaultColorSchemaDto = new DefaultColorSchemaDto(...);
91+
$PHPColorSchemaDto = new PHPColorSchemaDto(...);
92+
$XMLColorSchemaDto = new XMLColorSchemaDto(...);
93+
94+
$myTheme = new Theme(
95+
'myThemeTitle',
96+
$defaultColorSchemaDto,
97+
$PHPColorSchemaDto,
98+
$XMLColorSchemaDto
99+
);
100+
101+
$highlighter = new Highlighter($text, 'myThemeTitle', [$myTheme]);
102+
```
103+
104+
### Supports language syntax
76105
* PHP
77106
* JavaScript
78107
* XML/HTML
@@ -89,20 +118,6 @@ echo $highlighter->parse();
89118
* vs2015
90119
* c64
91120

92-
### Customization
93-
```php
94-
// Show line numbers
95-
$highlighter->setShowLineNumbers(true);
96-
// Show action panel
97-
$highlighter->setShowActionPanel(true);
98-
```
99-
100-
You can set following attributes in \<pre> tag
101-
\<pre data-lang="php" data-file="example.php" data-theme="drakuala">
102-
* lang - a language of the text. This affects how the parser will highlight the syntax.
103-
* file - show file name in action panel.
104-
* theme - allows to overwrite the global theme.
105-
106121
## Contributing
107122
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
108123

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
}
3030
},
3131
"require-dev": {
32-
"phpunit/phpunit": "^7.1",
32+
"phpunit/phpunit": "^10.2",
3333
"squizlabs/php_codesniffer": "*",
34-
"doctrine/coding-standard": "^6.0"
34+
"doctrine/coding-standard": "^12.0"
3535
}
3636
}

0 commit comments

Comments
 (0)