scrivo / highlight.php

A port of highlight.js by Ivan Sagalaev to PHP
BSD 3-Clause "New" or "Revised" License
695 stars 45 forks source link

Demo took a long time to run & Normal chatacters Rander #72

Closed MX-Qulin closed 4 years ago

MX-Qulin commented 4 years ago

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('<!DOCTYPE html>...')

1 /home/judge/src/web/light/Highlight/Highlighter.php(681): Highlight\Terminators->exec('<!DOCTYPE html>...')

2 /home/judge/src/web/light/Highlight/Highlighter.php(765): Highlight\Highlighter->highlight('xml', '<!DOCTYPE html>...', false)

3 /home/judge/src/web/light/demo/demo.php(59): Highlight\Highlighter->highlightAuto('<!DOCTYPE html>...')

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.

allejo commented 4 years ago

Uncaught Error: Call to undefined function Highlight\mb_strlen() in /home/judge/src/web/light/Highlight/RegEx.php:99

This means that the mbstring extension for PHP is not enabled. Depending on your server, you will probably need to install/enable it. Typically on most Linux systems, you can install it through your package manager; e.g. there's a php-mbstring package for Debian.

Also, the demo.php file takes 9 minutes for me to fully load (it is going through 34,225 iterations of highlighting). I'd recommend looking at example.php or line-numbers.php if you just want to see the highlighting in action. If you want to see all 185 languages highlighted, then I'd recommend the compare.php file, which loads relatively faster compared to demo.php.

MX-Qulin commented 4 years ago

emmmmm... It look likes that your server is better than me:) Anyway, Thankyou for helping me.

MX-Qulin commented 4 years ago

Well, i'd like to know if there's a feature that can show LineNumbers beside the code. You know, it helps a lot for us to read and explain code. If there's no this feathre, Would you please add it and then inform me? Thank you:)

allejo commented 4 years ago

The official way to add line numbers in this project is to use HighlightUtilities\splitCodeIntoArray(). You can see its sample usage in demo/line-numbers.php.

MX-Qulin commented 4 years ago

Thank you very much!

MX-Qulin commented 4 years ago

Anyway,I've found some other problem... The model seems not able to render the normal characters. Please take a look at my screenshot.(the two below is same. Placeing them is bacause Github's pic maybe slow or unable to open) my screenshot pic Thank you:)

MX-Qulin commented 4 years ago

i use the css that is linked https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.0/styles/school-book.min.css

allejo commented 4 years ago

Moving forward, if you could please create separate issues for these separate problems/questions, that'd help anyone in the future find relevant discussions.

In fact, I'm going to close this specific issue, so could you please create a new issue with the following information?

All of this would help me replicate the problem. Since I can't gather much from the screenshot.