MyBB Community Forums

Full Version: Code/syntax highlighting in post-bits.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
http://prismjs.com/

I understand that not everyone writes or looks at code, but i think enough people do for it to be a useful feature.
Currently, you can achieve something workable with MyCodes + prismjs. But there are graphical bugs when editing the postbit. (MyCodes don't seem to update when postbits are edited? I don't know if this is the real reason: https://i.imgur.com/y5QYFRM.gifv )
It would be nice, if we didn't have to load that library for every thread, even the ones which don't use syntax highlighting, but that might be a little complicated to do.
(2017-12-03, 03:41 AM)Azah Wrote: [ -> ]It would be nice, if we didn't have to load that library for every thread, even the ones which don't use syntax highlighting, but that might be a little complicated to do.

I believe the default configuration doesn't seem to have that big a footprint or at least doesn't seem that bad for me (12KB, https://i.imgur.com/VWLad7K.png). But yeah, adding additional options seems to make the library pretty big.
(2017-12-03, 03:41 AM)Azah Wrote: [ -> ]It would be nice, if we didn't have to load that library for every thread, even the ones which don't use syntax highlighting, but that might be a little complicated to do.

The showthread.php file could possibly have some kind of conditional applied within to grep for posts containing [code] blocks and dynamically include the library on pages where it's required.
Why not just use GeSHi to parse code blocks instead of relying on JavaScript?
(2017-12-04, 07:21 PM)laie_techie Wrote: [ -> ]Why not just use GeSHi to parse code blocks instead of relying on JavaScript?

Good idea.
(2017-12-03, 03:05 PM)kawaii Wrote: [ -> ]The showthread.php file could possibly have some kind of conditional applied within to grep for posts containing [code] blocks and dynamically include the library on pages where it's required.
If done in showthread, it may not work if no posts had a code tag, but one got added after an edit.
Ideally, you'd do something in the parser, flag that a script needs to be included, then load it both on page load (i.e. headerinclude template) and via AJAX (if not already loaded).
May be useful for other fancy MyCodes, but is a little specific. My opinion is that it should be a plugin.

(2017-12-04, 07:21 PM)laie_techie Wrote: [ -> ]Why not just use GeSHi to parse code blocks instead of relying on JavaScript?
Maybe push the slowness of syntax highlighting to the user instead of the server?