Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2012-04-20 12:15:28

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: fox_code - A bridge to the powerful GeSHi syntax highlighter

Great. Thanks. Yeah, sorry, I should have clarified I was just talking about the basic output.

I’ll give this a whirl.

Offline

#32 2012-04-20 12:46:11

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: fox_code - A bridge to the powerful GeSHi syntax highlighter

So far so good. I notice the Geshi header instructions say dropping the DIV will cause validation problems, but keeping the div also causes extra white space… hmmm. Decisions, decisions.

Anyway, what about the inline style that’s added automatically… style="font-family:mono-space; … can I edit the code to prevent that from being inserted too? Now that you pointed out the line for the DIV, that stands out like a red clover (ha!), but I don’t notice anything that’s controlling the style attribute.

—-

Edit: Hmmm. Looks like there’s a lot more inline styles that I thought. Also within the LI elements, and within more DIV inside the LI elements. I don’t think this will work out for our needs, unfortunately. No worries, though. We’ll go to plan B. :)

Last edited by Destry (2012-04-20 13:02:18)

Offline

#33 2012-04-20 13:04:47

Gr3yFox
Plugin Author
From: Genova, Italy
Registered: 2007-06-18
Posts: 42
Website

Re: fox_code - A bridge to the powerful GeSHi syntax highlighter

If you wish to remove the inline style for the code, you have to provide a CSS instead. <fox_code> has an input parameter to enable CSS styles in GeSHi, css="1". This will make GeSHi use CSS classes instead (I think I wrote something about it in the plugin’s help). It is disabled by default, but if you don’t want to type css="1" every time you can change the line 'css' => '0', at almost the top of my code to 'css' => '1', (don’t remove the comma). That is the associative array with the default values that are applied whenever you omit to specify explicitly an option.

Unfortunately I cannot help you about the list of css classes GeSHi is going to use once you disable the inline style, I really do not remember. Maybe you can find some references at the same documentation page I linked you before, or somewhere else at the GeSHi website. You may as well look at my (really old and crappy) css.

PS: please have a look at the documentation I supplied together with my plugin, it should clarify something about the possible customizations.

Last edited by Gr3yFox (2012-04-20 13:07:13)


Gr3yFox

Offline

#34 2012-04-20 13:08:17

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: fox_code - A bridge to the powerful GeSHi syntax highlighter

Thanks, Riccardo. I’ll look at the docs closer. My fault.

Offline

#35 2012-04-20 13:09:06

Gr3yFox
Plugin Author
From: Genova, Italy
Registered: 2007-06-18
Posts: 42
Website

Re: fox_code - A bridge to the powerful GeSHi syntax highlighter

Don’t worry, no problem. You’re welcome :)


Gr3yFox

Offline

#36 2024-12-05 04:58:06

hug
Member
Registered: 2024-12-02
Posts: 11

Re: fox_code - A bridge to the powerful GeSHi syntax highlighter

Can I get advice for using fox_code 0.2.1 with Textpattern 4.8.8? I had used Textpattern about 15 years ago, then got caught up with the static-site Jekyll and Hugo, and worked my back to Txp. I’m interested in keeping server-side syntax highlighting and thought to try fox_code. The plugin shows up normally in the admin Plugin panel with the enable/disable, help, etc.

Everything is installed as below. However, it seems I have overlooked something.

My Texpattern home is /var/www/www.the-pythia.net/.

textpattern/plugins/fox_code/fox_code.php
textpattern/plugins/fox_code/help.textile
textpattern/plugins/fox_code/manifest.json
textpattern/lib/geshi.php
textpattern/lib/geshi/4cs.php
textpattern/lib/geshi/6502acme.php
textpattern/lib/geshi/ ... etc. all of the syntax highlighting files

The sample article I’m trying to highlight.

notextile..
<txp:fox_code language=“sql” >
SELECT 1 FROM DUAL;
</txp:fox_code>

The first error output could not find geshi.php. Using the hint here and this thread I added this to my webroot’s .htaccess

php_value include_path ".:/usr/lib/php:/var/www/www.the-pythia.net/textpattern/lib"

That seemed to improve things, as it appears the geshi.php file is loaded, but now I have an issue with “Call to undefined function create_function() in /var/www/www.the-pythia.net/textpattern/lib/geshi.php:4698”. Unfortunately, my PHP knowledge is very old and rusty, and I couldn’t say whether create_function() is verboten or has been superceded with a different function. Any ideas?

The first stack trace is abbreviated for not finding geshi.php. The second one is in full and supports the issue with the create_funtion() menioned above. Thank you for reading! —Hanna

Fatal error: Uncaught Error: Failed opening required 'geshi.php' (include_path='.:/usr/share/php') in /var/www/www.the-pythia.net/textpattern/plugins/fox_code/fox_code.php:67 
Stack trace: 
#0 [internal function]: fox_code() 
...
#25 /var/www/www.the-pythia.net/textpattern/index.php(186): textpattern() 
#26 {main} thrown in /var/www/www.the-pythia.net/textpattern/plugins/fox_code/fox_code.php on line 67

Stack trace after changing the PHP include path, with the create_function() error.

Fatal error: Uncaught Error: Call to undefined function create_function() 
in /var/www/www.the-pythia.net/textpattern/lib/geshi.php:4698 
Stack trace:
#0 /var/www/www.the-pythia.net/textpattern/lib/geshi.php(4621): GeSHi->_optimize_regexp_list_tokens_to_string()
#1 /var/www/www.the-pythia.net/textpattern/lib/geshi.php(1655): GeSHi->optimize_regexp_list()
#2 /var/www/www.the-pythia.net/textpattern/lib/geshi.php(2029): GeSHi->optimize_keyword_group()
#3 /var/www/www.the-pythia.net/textpattern/lib/geshi.php(2168): GeSHi->build_parse_cache()
#4 /var/www/www.the-pythia.net/textpattern/plugins/fox_code/fox_code.php(83): GeSHi->parse_code()
#5 [internal function]: fox_code()
#6 /var/www/www.the-pythia.net/textpattern/vendors/Textpattern/Tag/Registry.php(140): call_user_func()
#7 /var/www/www.the-pythia.net/textpattern/lib/txplib_publish.php(564): Textpattern\Tag\Registry->process()
#8 /var/www/www.the-pythia.net/textpattern/lib/txplib_publish.php(409): processTags()
#9 /var/www/www.the-pythia.net/textpattern/publish/taghandlers.php(2908): parse()
#10 /var/www/www.the-pythia.net/textpattern/publish/taghandlers.php(2937): txp_sandbox()
#11 [internal function]: body()
#12 /var/www/www.the-pythia.net/textpattern/vendors/Textpattern/Tag/Registry.php(140): call_user_func()
#13 /var/www/www.the-pythia.net/textpattern/lib/txplib_publish.php(559): Textpattern\Tag\Registry->process()
#14 /var/www/www.the-pythia.net/textpattern/lib/txplib_publish.php(409): processTags()
#15 /var/www/www.the-pythia.net/textpattern/lib/txplib_misc.php(3551): parse()
#16 /var/www/www.the-pythia.net/textpattern/publish.php(1162): parse_form()
#17 /var/www/www.the-pythia.net/textpattern/publish.php(1197): doArticle()
#18 /var/www/www.the-pythia.net/textpattern/publish.php(921): parseArticles()
#19 [internal function]: article()
#20 /var/www/www.the-pythia.net/textpattern/vendors/Textpattern/Tag/Registry.php(140): call_user_func()
#21 /var/www/www.the-pythia.net/textpattern/lib/txplib_publish.php(559): Textpattern\Tag\Registry->process()
#22 /var/www/www.the-pythia.net/textpattern/lib/txplib_publish.php(409): processTags()
#23 /var/www/www.the-pythia.net/textpattern/publish/taghandlers.php(3833): parse()
#24 [internal function]: if_individual_article()
#25 /var/www/www.the-pythia.net/textpattern/vendors/Textpattern/Tag/Registry.php(140): call_user_func()
#26 /var/www/www.the-pythia.net/textpattern/lib/txplib_publish.php(559): Textpattern\Tag\Registry->process()
#27 /var/www/www.the-pythia.net/textpattern/lib/txplib_publish.php(409): processTags()
#28 /var/www/www.the-pythia.net/textpattern/lib/txplib_misc.php(3626): parse()
#29 /var/www/www.the-pythia.net/textpattern/publish.php(740): parse_page()
#30 /var/www/www.the-pythia.net/textpattern/index.php(186): textpattern()
#31 {main} thrown in /var/www/www.the-pythia.net/textpattern/lib/geshi.php on line 4698

Thank you again!

Last edited by hug (2024-12-05 04:58:45)

Offline

#37 2024-12-05 10:35:18

etc
Developer
Registered: 2010-11-11
Posts: 5,681
Website GitHub

Re: fox_code - A bridge to the powerful GeSHi syntax highlighter

Hello, welcome back!

You are right, create_function() has been deprecated and removed in php 8. To replace it, you can try to replace l.4696-4700 of geshi.php with

$list = preg_replace_callback(
    '#\(\?\:((?:.\|)+.)\)#',
    function ($matches) {return "[" . str_replace("|", "", $matches[1]) . "]";},
    $list
);

but I have not tested it.

Offline

#38 2024-12-06 23:41:09

hug
Member
Registered: 2024-12-02
Posts: 11

Re: fox_code - A bridge to the powerful GeSHi syntax highlighter

Thank you, that worked the first time!

For others, this is for geshi.php version 1.0.9.0.

The original code for PHP 7 and older for lines 4696-4700 looked like this.

static $callback_2;
if (!isset($callback_2)) {
    $callback_2 = create_function('$matches', 'return "[" . str_replace("|", "", $matches[1]) . "]";');
}
$list = preg_replace_callback('#\(\?\:((?:.\|)+.)\)#', $callback_2, $list);

Comment (or delete) and replace with etc’s code for PHP 8.

$list = preg_replace_callback(
    '#\(\?\:((?:.\|)+.)\)#',
    function ($matches) {return "[" . str_replace("|", "", $matches[1]) . "]";},
    $list
);

Thanks again, —Hanna

Last edited by hug (2024-12-06 23:41:47)

Offline

#39 2024-12-07 09:47:40

etc
Developer
Registered: 2010-11-11
Posts: 5,681
Website GitHub

Re: fox_code - A bridge to the powerful GeSHi syntax highlighter

Glad it works, and you are lucky if it’s the only fix needed for php8 compatibility.

Re static sites, you might consider etc_cache. Well configured, it turns txp into dynastatic cms, serving most pages directly from disk (so up to 3-4 times faster).

Offline

Board footer

Powered by FluxBB