Giter Site home page Giter Site logo

highlight.php's Introduction

highlight.php

Unit Tests Latest Packagist release Monthly downloads on Packagist

highlight.php is a server-side syntax highlighter written in PHP that currently supports 185 languages. It's a port of highlight.js by Ivan Sagalaev that makes full use of the language and style definitions of the original JavaScript project.

This is the README for highlight.php v10, which is currently under development. The latest stable release is the 9.18.x series.

Table of Contents

Installation + Setup

The recommended approach is to install the project through Composer.

composer require scrivo/highlight.php

If you're not using Composer, ensure that the classes defined in the Highlight namespace can be found either by inclusion or by an autoloader. A trivial autoloader for this purpose is included in this project as Highlight\Autoloader.php

Composer Version Constraints

When requiring this project in your composer.json, it is recommended you use the caret version range and use only the major and minor values; i.e. ^9.14.

It's come to our attention that a lot of tutorials and projects out there are locking themselves into highly specific versions of this project; e.g. "scrivo/highlight.php": "v9.12.0.1". Please do not do this or encourage it. We promise a reliable backward compatibility policy so there's no reason to lock yourself to such a specific version. By doing this, you are preventing yourself or your users from receiving updates to language definitions and bug fixes.

Usage

The \Highlight\Highlighter class contains the syntax highlighting functionality. You can choose between two highlighting modes:

  1. explicit mode
  2. automatic language detection mode

Explicit Mode

In explicit mode, you must define which language you will be highlighting as.

// Instantiate the Highlighter.
$hl = new \Highlight\Highlighter();
$code = file_get_contents('some_ruby_script.rb');

try {
    // Highlight some code.
    $highlighted = $hl->highlight('ruby', $code);

    echo "<pre><code class=\"hljs {$highlighted->language}\">";
    echo $highlighted->value;
    echo "</code></pre>";
}
catch (DomainException $e) {
    // This is thrown if the specified language does not exist

    echo "<pre><code>";
    echo htmlentities($code);
    echo "</code></pre>";
}

Automatic Language Detection Mode

Alternatively you can use the automatic detection mode, which highlights your code with the language the library thinks is best. It is highly recommended you explicitly choose the language or limit the number of languages to automatically detect to reduce the number of inaccuracies.

Warning: Auto-detection occurs in a brute force fashion and the language with the most accurate result will be selected. This is extremely inefficient as you supply more languages and may not always be 100% accurate if similar languages are configured.

$hl = new \Highlight\Highlighter();
$hl->setAutodetectLanguages(array('ruby', 'python', 'perl'));

$highlighted = $hl->highlightAuto(file_get_contents('some_ruby_script.rb'));

echo "<pre><code class=\"hljs {$highlighted->language}\">";
echo $highlighted->value;
echo "</code></pre>";

Default Languages

If no autodetect languages are set in the highlighter, then every language will be used and cause significant performance issues.

Stylesheets

The same stylesheets available in the highlight.js project are available in the styles directory of this project and may be included in your own CSS or made accessible to your web server.

Highlighter Utilities

The core of the project is loyal port of highlight.js and is available under the main Highlight namespace. A series of convenience functions are provided under the HighlightUtilities namespace to introduce additional functionality without the need for another dependency.

Available functions:

Versioning

This project will follow the same version numbers as the highlight.js project with regards to languages, meaning that a language definition available in highlight.js 9.12.0 will be available in highlight.php 9.12.0. However, there are times where bugs may arise in this project or its translated definition files, so there'll be one more number appended to the version number. For example, version 9.12.0.1 will contain all of the same languages as highlight.js 9.12.0 but also contain fixes solely to this project. This is done so this project can have version bumps without conflicts should highlight.js release version 9.12.1.

Backward Compatibility Promise

Despite the fact that the semantic versioning used in this project mirrors that of highlight.js, this project will adhere to Symfony's Backward Compatibility Promise. You can rest assured that there will be no breaking changes during 9.x and any deprecations will be marked with @deprecated and won't be removed until the next major release.

Some History

Geert Bergman Sep 30, 2013

JavaScript code highlighting is very convenient and in many cases just what you want to use. Especially for programming blogs I would not advice you to use otherwise. But there are occasions where you're better off with a more 'static' approach, for instance if you want to send highlighted code in an email or for API documents. For this I needed a code highlighting program preferably written in PHP.

I couldn't found any satisfactory PHP solution so I decided to port one from JavaScript. After some comparison of different highlighting programs based on license, technology, language support highlight.js came out most favorable in my opinion.

It was my decision not to make a PHP highlighter but to do a port of highlight.js, these are different things. The goal was to make it work exactly as highlight.js to make as much use as possible of the language definitions and CSS files of the original program.

Happy coding!

License

BSD

highlight.php's People

Contributors

allejo avatar ankurk91 avatar assertchris avatar azaghal avatar cebe avatar jenbuzz avatar jonasdoebertin avatar pana1990 avatar phpfui avatar replicant64 avatar s1syphos avatar sbrl avatar scrivo avatar taufik-nurrohman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

highlight.php's Issues

HTML + JS detected as PHP???

I've just installed and set up your port which I'll be using for PHP, JS, CSS, HTML and SQL, but one of my very first test cases failed to be properly detected: <script>alert("XSS")</script> is neither detected as HTML nor as JavaScript, but instead as PHP. And the returned code uses &lt; and &gt; rather than < and > which looks rather ugly... so I was wondering if this is a feature I can turn off?

Autoloader.php

hi Scrivo,

I have installed the highlight project in my Laravel project by using Composer. Added below given snippet into the controller.

require_once "../Highlight/Autoloader.php";
spl_autoload_register("Highlight\\Autoloader::load");

When i am running the code then it is displaying with below error message.

App\Http\Controllers\AController::show(): Failed opening required '../Highlight/Autoloader.php' (include_path='.;C:\php\pear')

Can you please help me here.

Adds a line break after comments

Pretty much what the title says. Works perfectly except that it adds a line break after comments when there isn't any in the original code.

Where is highlight.php v10.x/v11.x?

For anyone curious and before anyone asks, highlight.php 10.x/11.x is planned and development will start in the coming weeks. I first need to finish off my semester and a few other commitments.

highlight.php 10 will require PHP 5.6+ (see #55)

The current estimated release of highlight.php v10/11 is Winter 2021


Why the delay?

highlight.js v10 introduced some breaking changes where grammars can no longer be represented by just JSON; grammars now support JS callbacks. While not many grammars are using this feature as of yet, I'm hesitant to dedicate myself to manually porting JS to PHP.

Does this mean highlight.php is dead?

No. Not at all. I do have some ideas for automatically translating JS to PHP to address this problem. I simply have not had time to work on this.

It's been over a year since this issue was created. Why haven't you done it yet?

I've had other projects, work, and school that have required my attention/focus/time. Feel free to sponsor me to work on this project 😄 ❤️

Theme Rendering Inconsistency on PHP codes

Hello, I'm migrating from hihglight.js to hihglight.php.
I was able to setup basic things to make it work. However I have issue with the rendering.

In my case I want to highlight some PHP codes with Paraiso Dark theme. BUT the result is bit different. Consider:

highlightjsphp rendering inconsistencies

So ones that was done with highlight.js is perfectly rendered, the enum keyword is recognized and so does the self:$key construct inside the match body.
While ones that was done with hihglight.php is not as perfect as that.

I have tried to use both manual mode and auto detect mode but no luck :

$hl=new Highlighter();

//didn't work 
$hl->setAutodetectLanguages(["php"]);
$highlight=$hl->highlightAuto($codes);

//didn't work either
$highlight=$hl->highlight("php",$codes);

This is my env:

  • PHP 8.2
  • highlight.php v9.18.1.10

help?

UPDATE
This is also affect other sources too, I've tried to highlight JS code and the rendering is different from it should be

CSS does not highlight nested `var()`

With nested var() assignment, meaning using custom property as fallback for other custom properties, the nested var is not highlighted as it should.

Example:

* {
 background: var(--red, var(--blue, green));
}

Only the first var is highlighted.

Add highlight.js' 3rd-party languages

highlight.js has 3rd-party languages that come in the format of external repositories. There is no standard repository format for said languages at the moment, see highlightjs/highlight.js#2328.

Depending on how bored I get and how quickly they come up with a standard will determine when these languages will come to highlight.php

Which language can I use to highlight the command line?

I want to highlint the command and params such as the fllowing contents

php test.php
php -r "echo 123"
mkdir test-dir
rm -rf test-dir
...more commands

I can't find it json in the path of "scrivo\highlight.php\Highlight\languages"

Update HighlightPHP to bring it even to HighlightJS

Dear @scrivo ,

I really appreciate your work and all your effort you put in into this project. Is there any chance to get highlight.php even with highlight.js (currently that's release 8.9.1)? And is this project still maintained?

The reason: I would like to use highlight.php to render code server-side and maybe let the user decide, whether he or she uses server-side generation or wants to use the original JS verison.

Allow HTML Tags in Code Snippet

The reason I use highlight.js in my blog was because it allows me to preserve HTML tags inside the code snippet. Knowing that there is a highlight.php project makes everything so perfect! But one thing is missing; that is the ability to retain HTML tags inside the code snippet. I used to add <mark> tags to explain to my readers about the important parts, and maybe some <a> tags to link some piece of code to the documentation page.

How do I keep the HTML markup in my code snippet? Disabling the “safe mode” does not work for me. It always throws “`self` is not supported at the top-level of a language.” message anyway.

By the way, I have used your project to complete my content management system extension here. This project fits my environment so well 👍

Thanks.

demo/line-numbers.php - style changed

If i use demo/line-numbers.php and set css is Dark background style then no show background Dark and text formatting missed (bad overflow, spacing, etc.) (text highlighting is ok only) .

[PHP] Highlighting `new` keyword

We render the following code snippet in the Symfony-Docs like:
CleanShot 2022-11-23 at 23 42 08@2x

Link

In this case new is a static method and should not be highlighted this way.

Could this be fixed? I am open to provide a PR if you can point me to the right direction.

Thanks

Not highlighting correctly

I posted this issue originally on the the highlight.js repository but I guess the problem is on this port rather than on the JS library itself:
highlightjs/highlight.js#3743

Describe the issue

Having something like this:

  const optionToSelect = $options.find(item => item.text ===text);

The whole optionToSelect = $options.find( gets the same color without separating the find function.
I'm not using auto-detection.

Picture:
image

image

Here's the right coloring using the latest version of the JS component highlight.js. Notice the "find" gets colored.
https://jsfiddle.net/chy5nd72/

Sample Code to Reproduce

This is how jsfiddle shows it:
image

This is how Prism.js shows it:
image

Expected behavior
It should look more like this:
image

image

Potential fixes for failing tests/skipped unit tests

-<span class="json">{<span class="hljs-attr">"status"</span>: <span class="hljs-string">"ok"</span>, <span class="hljs-attr">"extended"</span>: <span class="hljs-literal">true</span>}
-</span>'
+{"status": "ok", "extended": true}'

Looks like your sublanguage support is maybe broken somehow? Perhaps you don't support auto-detect of sublanguages? HTTP is a pretty simple syntax.

Failing Haskell Test

Likely a bug in your recursive rule support using "self"?

      hljs.COMMENT(
        '{-',
        '-}',
        {
          contains: ['self']
        }
      )

Originally posted by @yyyc514 in #66 (comment)

Demo doesn't work - max execution time limit reached

So, I just cloned the repo, did composer install, ran demo.php and:

PHP Fatal error:  Maximum execution time of 60 seconds exceeded in /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php on line 87
PHP Stack trace:
PHP   1. {main}() /Users/gostrolucky/PhpstormProjects/highlight.php/demo/demo.php:0
PHP   2. Highlight\Highlighter->highlightAuto() /Users/gostrolucky/PhpstormProjects/highlight.php/demo/demo.php:59
PHP   3. Highlight\Highlighter->highlight() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:577
PHP   4. Highlight\Highlighter->processLexeme() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:517
PHP   5. Highlight\Highlighter->processBuffer() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:315
PHP   6. Highlight\Highlighter->processSubLanguage() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:280
PHP   7. Highlight\Highlighter->setAutodetectLanguages() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:237
PHP   8. Highlight\Highlighter::registerLanguages() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:399

Fatal error: Maximum execution time of 60 seconds exceeded in /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php on line 87

Call Stack:
    0.0006     419552   1. {main}() /Users/gostrolucky/PhpstormProjects/highlight.php/demo/demo.php:0
   61.4569   36886696   2. Highlight\Highlighter->highlightAuto() /Users/gostrolucky/PhpstormProjects/highlight.php/demo/demo.php:59
   61.4964   36885896   3. Highlight\Highlighter->highlight() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:577
   61.5011   36888520   4. Highlight\Highlighter->processLexeme() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:517
   61.5012   36888520   5. Highlight\Highlighter->processBuffer() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:315
   61.5012   36888520   6. Highlight\Highlighter->processSubLanguage() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:280
   61.5039   36888712   7. Highlight\Highlighter->setAutodetectLanguages() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:237
   61.5039   36901056   8. Highlight\Highlighter::registerLanguages() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:399

Dynamic properties are deprecated in PHP 8.2

Hi, I tested the highlighter with PHP 8.2 today and found two potential issues.

Code in Highlighter::__construct() initialises two properties which don't exist in class RegExMatch:

$this->lastMatch = new RegExMatch(array());
$this->lastMatch->type = "";
$this->lastMatch->rule = null;

Code in Terminators::exec() initialises another property RegExMatch::extra, but apparently is never used:

$match->extra = array($this->mode->illegal, $this->mode->terminator_end);

Let me know if you need more information. Thanks for investigating.

Infinite loop in JsonRef::resolvePathReferences

Library version: ^9.13
PHP version: 7.3.1

I'm trying to highlight javascript code, and the highlighter gets stuck in an infinite loop while trying to resolvePathReferences. Here's a GIF of the diagnosis:

loop

The code it is compiling for is:

const copyToClipboard = function(string) {
    const element = document.createElement('textarea')
    document.body.appendChild(element)

    element.value = string
    element.select()

    // this copies currently selected input text
    document.execCommand('copy')

    document.body.removeChild(element)
}

$('[data-copy-code]').on('click', function(e) {
    copyToClipboard(this.dataset.copyCode)
})

...but I don't think the code is the problem here. I suspect a recent-ish change to the javascript syntax has caused this infinite loop behaviour.

Edit: after further investigation, I don't think think a syntax definition change is responsible, since the definition file hasn't changed recently in a way that would cause new behaviour. Still unsure of the cause.

"Invalid" regular expressions in registered languages broke autodetection

In our Language class, we have a langRe() method, which is tasked with putting together our regular expressions.

private function langRe($value, $global=false)
{
return "/{$value}/um" . ($this->caseInsensitive ? "i" : "");
}

As I was rewriting the unit tests, I noticed that the language files for 1c and ada contained the following two regular expressions:

  • \d{4}([\.\\/:-]?\d{2}){0,5} <- the / is treated as a delimiter
  • []{}%#'" <- the [ and ] aren't escaped

Since our method isn't very smart, putting these two regular expressions in between / caused E_ERRORs to be thrown. If these languages are registered in Highlighter for autodetection, then it'll fail due to the E_ERROR.

I manually modified the language files for the affected languages and tagged 9.12.0.1, but this needs a better solution. I'd be opposed to having to manually modify the language files since they're generated directly from highlight.js, so I'd favor improving our regex building in the Language class. Thoughts? Any better solutions?

/cc @S1SYPHOS

Edit: We could also add another round of patches to our get_language_definitions.php file, too I guess...

PHP code seems to be insufficiently tagged.

echo $this->highlighter
    ->highlight(
        'php',
        <<<'CODE'
        <?php
        
        $high = $dog->cat();
        $dog = new Cat();
        CODE
    )
    ->value;

This code echos:

<span class="hljs-meta">&lt;?php</span>

$high = $dog-&gt;cat();
$dog = <span class="hljs-keyword">new</span> Cat();

Is there something that I'm doing wrong that prevents.. for example.. the class name to be wrapped in a span? Only the 'new' keyword and '<?php' meta seems to be specified.

Tag latest changes

Since it might take a while until there will be another highlight.js release, would it be possible to tag a new 9.12.0.2 release so we can get the changes from my already merged PR #17 into a stable version?

Thanks for your work on highlight.php!
Jonas

Highlighter duplicating Russian characters (unicode)

Source code

<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;

$form = ActiveForm::begin([
    'id' => 'login-form',
    'options' => ['class' => 'form-horizontal'],
]) ?>
    <?= $form->field($model, 'username') ?>
    <?= $form->field($model, 'password')->passwordInput() ?>

    <div class="form-group">
        <div class="col-lg-offset-1 col-lg-11">
            <?= Html::submitButton('Вход', ['class' => 'btn btn-primary']) ?>
        </div>
    </div>
<?php ActiveForm::end() ?>

Highlight code:

$hl = new \Highlight\Highlighter();
$highlighted = $hl->highlight('php', $code);
echo "<pre><code class=\"hljs {$highlighted->language}\">{$highlighted->value}</code></pre>";

Highlighted code, look here - ('Входодд:

<pre><code class="hljs php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-keyword">use</span> <span class="hljs-title">yii</span>\<span class="hljs-title">helpers</span>\<span class="hljs-title">Html</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">yii</span>\<span class="hljs-title">widgets</span>\<span class="hljs-title">ActiveForm</span>;

$form = ActiveForm::begin([
    <span class="hljs-string">'id'</span> =&gt; <span class="hljs-string">'login-form'</span>,
    <span class="hljs-string">'options'</span> =&gt; [<span class="hljs-string">'class'</span> =&gt; <span class="hljs-string">'form-horizontal'</span>],
]) <span class="hljs-meta">?&gt;</span>
    <span class="hljs-meta">&lt;?</span>= $form-&gt;field($model, <span class="hljs-string">'username'</span>) <span class="hljs-meta">?&gt;</span>
    <span class="hljs-meta">&lt;?</span>= $form-&gt;field($model, <span class="hljs-string">'password'</span>)-&gt;passwordInput() <span class="hljs-meta">?&gt;</span>

    &lt;div <span class="hljs-class"><span class="hljs-keyword">class</span>="<span class="hljs-title">form</span>-<span class="hljs-title">group</span>"&gt;
        &lt;<span class="hljs-title">div</span> <span class="hljs-title">class</span>="<span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-<span class="hljs-title">offset</span>-1 <span class="hljs-title">col</span>-<span class="hljs-title">lg</span>-11"&gt;
            &lt;?= <span class="hljs-title">Html</span>::<span class="hljs-title">submitButton</span>('Входодд<span class="hljs-title">class</span>' =&gt; '<span class="hljs-title">btn</span> <span class="hljs-title">btn</span>-<span class="hljs-title">primary</span>']) ?&gt;
        &lt;/<span class="hljs-title">div</span>&gt;
    &lt;/<span class="hljs-title">div</span>&gt;
&lt;?<span class="hljs-title">php</span> <span class="hljs-title">ActiveForm</span>::<span class="hljs-title">end</span>() ?&gt;</span></code></pre>

Line numbers demo doesn't work with multi-line comments

I know that line numbers aren't officially supported by this project, but I wanted to flag that the line numbers demo fails on multi-line comments: Because the <span> tag wraps multiple lines, only the first line of the comment is properly styled once those lines are then placed in table cells.

Is there a way around this? If each line of the comment were wrapped in a <span> tag instead of the comment in its entirety, that would solve the problem, for example.

RFC: Minimum PHP version for highlight.php 10

It looks like highlight.js v10 is in the planning. This means per our BC policy, we'll be removing any deprecated functionality once we release a v10 of this project.

Additionally, I would like to get feedback from the community about the minimum PHP version for the next major release of this project. I typically align my projects with the LTS versions of other major projects:

  • Symfony 3.4 LTS (EOL: November 2021) PHP >= 5.5
  • Symfony 4.4 LTS (EOL: November 2023) PHP >= 7.1
  • Laravel 5.5 LTS (EOL: August 2020) PHP >= 7.0
  • Laravel 6 LTS (EOL: September 2022) PHP >= 7.2
  • Debian 8 LTS (EOL: June 2020) PHP >= 5.6
  • Debian 9 LTS (EOL: June 2022) PHP >= 7.0
  • Ubuntu 16.04 LTS (EOSS: April 2021) PHP >= 7.0
  • Ubuntu 18.04 LTS (EOSS: April 2023) PHP >= 7.2
  • WordPress PHP >= 5.6

Given this information, I'd like to hear from the users of this library as to what PHP version they're using and if it's an older version, why they're still supporting it. There's still time until highlight.php v10 but the more information I can get early the better.

There's nothing in this library that critically relies on a feature in PHP 7.x, so I don't mind keeping the minimum PHP 5.x but if there aren't enough users using an EOL'd version of PHP, I won't bother with it either.

Related

True 9.12.0 compatibility

This project is currently a full port of highlight.js 9.0.0, however, several things changed since version 9.12.0. Those changes, however, didn't make their way to highlight.php when I started contributing to this project. I mistakingly believed that 9.12.0 only involved updated language definitions but that was not the case.

  • Port 9.12.0 changes
  • Fix broken sub-language support (this is the cause of failing unit tests)

My goal is to tag these fixes as 9.12.0.4 to keep our versioning in parallel with highlight.js

PHP 8.1 deprecation messages

PHP Deprecated:  Return type of Highlight\RegExMatch::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/Highlight/RegExMatch.php on line 70
PHP Deprecated:  Return type of Highlight\RegExMatch::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/Highlight/RegExMatch.php on line 78
PHP Deprecated:  Return type of Highlight\RegExMatch::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/Highlight/RegExMatch.php on line 86
PHP Deprecated:  Return type of Highlight\RegExMatch::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/Highlight/RegExMatch.php on line 94
PHP Deprecated:  Return type of Highlight\RegExMatch::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/Highlight/RegExMatch.php on line 104
PHP Deprecated:  Return type of Highlight\RegExMatch::getIterator

demo/line-numbers.php error

demo/line-numbers.php ended error:
Parse error: syntax error, unexpected end of file in demo\line-numbers.php on line 94

Do you can fix?

Performance issue

I have a table with 25 records and on each row there is a column which needs to be highlighted.
Without highlighter it loads in 0.3 ms.
With highlighter it loads in 1 min 30 sec.

Is the performance so bad?

Thanks!

Improve typing in PHPDocs

Issue #52 was my first step in making future maintenance of this project much easier for myself by adding type hints via PHPDocs. I originally wanted these improvements to come along in the next 9.16 release but there was simply too much. So I'll delay this for a bit longer and maybe aim for a 9.17 release.

php comments

Thanks for the package, in many ways is better to hable code with php than js, Im having some problems hope you can help me, I trying this code but it doesn't divide into tags anything

<code class="hljs php">
// Instantiate the Highlighter.
$hl = new \Highlight\Highlighter();
$code = file_get_contents('some_ruby_script.rb');
</code>

Screenshot 2023-02-07 at 9 08 28 AM

Please help!

I can't get it to work, how would I debug this the best way? Also, I'd love to see this going on!

Any Plan to Convert {language}.json to {language}.php?

Any plan to convert {language}.json files to {language}.php files? So that we could predefine reusable data, and maybe to provide some comments in the file, so that we can return PHP array instead of JSON string that requires extra decoding process.

Example language file contents:

<?php

$keywords = get_foo_keywords();
$number = \Highlighter\Highlight::NUMBER;

return [
    'case_insensitive' => true,
    'keywords' => $keywords,
    // ...
];

I can help.

Get style method

Hello!
Can you add a method for getting styles?
For example, the path to the style file? Or would the method return a style sheet from a file?

Demo took a long time to run & Normal chatacters Rander

Maybe there're some bugs in the demo(i didn't use composer)
When i ran demo.php, it shows 504 and the CPU dashed to 98%.
Then i use php demo.php and it says

PHP Fatal error: Uncaught Error: Call to undefined function Highlight\mb_strlen() in /home/judge/src/web/light/Highlight/RegEx.php:99
Stack trace:
#0 /home/judge/src/web/light/Highlight/Terminators.php(98): Highlight\RegEx->exec('...')
#1 /home/judge/src/web/light/Highlight/Highlighter.php(681): Highlight\Terminators->exec('...')
#2 /home/judge/src/web/light/Highlight/Highlighter.php(765): Highlight\Highlighter->highlight('xml', '...', false)
#3 /home/judge/src/web/light/demo/demo.php(59): Highlight\Highlighter->highlightAuto('...')
#4 {main}
thrown in /home/judge/src/web/light/Highlight/RegEx.php on line 99

Can you explain why this happen or fix it?
Hope to hear from you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.