|
Cookbook /
SourceBlockSummary: Source code syntax highlighter for PmWiki 2.x using GeSHi
Version: 2008-09-16
Status: Stable
Prerequisites: pmwiki-2.1 and GeSHi (tested with v1.0.7.22)
Optional: Linked Resource Extras recipe for external files handling
Maintainer: Dfaure
Download: sourceblock.phpΔ
Question answered by this recipeI tried the (abandoned) Beautifier recipe to perform syntax highlighting for my source code but still wasn't very satisfied... What's next? DescriptionHere you'll find SourceBlock: a script recipe dedicated to syntax highlighting, which offers more features:
Notes and CommentsSourceBlock is based on GeSHi, an actively developed source code highlighting script, already used in several other wiki systems. Installation
MarkupOnce installed, it adds markup of the form:
and:
with the following optional PARAMETERS:
(*)Only meaningful with lang=LANGUAGE defined.
SourceBlock configures GeSHi to use In order to be a full alternative to CodeBlock, SourceBlock provides following extra markup to generate
and:
Both markups don't need to start a new line, and may be appended to list elements without altering their order. The extra "Get Code" link provides a direct access to the unformatted code. The markup also handle the related parameters:
Blocks appearance is controlled via style sheets parts overrideable in An additional:
markup form is available to list all the languages supported by the GeSHi installation. Optional external file handlingThe recipe script detects any previous installation of the Linked Resource Extras recipe and if so, provide the two more markup directive to render external files:
and:
The markup parameters have the same meaning. Please refer to Linked Resource Extras recipe page for more details on the FILE_RESOURCE specification itself. SandBox
Release Notes
See AlsoBeautifier, Linked Resource Extras. ContributorsComments Would be nice if one could render code coming from a local or uploaded file, e.g. like The feature is available in the latest version --Dfaure May 01, 2007, at 02:42 AM The [Get Code] link inserted above the code frame only works on my site if I first save the file, then open it. When clicked on, I am prompted to download a file (named: sourceblock_1.txt, type: Text Document)... If I choose Open, a file is downloaded, notepad opens and prompts "Cannot find the <path to tempInternetFiles>\sourceblock_1[1].txt file" and all I get is a blank notepad. If I choose Save, the file is saved and contains the code. I have found other sites that implement this recipe and have no problems opening the code directly from their links (not saving the file first), so it must be a configuration problem on my site and not a browser setting problem (IE6). Any ideas where to look? ejersau? April 25, 2007, at 11:48 AM I found a site where the [Get Code] link is working for my browser and copied their (:sourcecode...:) markup into my wiki sandbox then compared the HTML source of the working site with that generated by mine. The only difference (except for the beginning of the href value) was the line While writing the recipe, IE6 has been found to handle very badly 'text/plain' file fragments, so I decided to force it to download them as they were separate files... Looks like it was a late night for you :-). The fix works perfect! Much appreciated. --ejersau? May 01, 2007, at 12:51 PM
I was trying to set this script up on my site which uses a customized skin of my own design where the body colour is set to yellow. I added some python code using this recipe, but text that isn't recognized as language keywords are left uncoloured, so I ended up getting yellow-on-grey. If the site's body colour is set to the same colour as the grey div background, then half the text would be invisible! It's a simple fix though: just add a color:black line to the sourceblocktext css; here's a diff patch: sourceblock.diff.phpΔ (Note: this isn't strictly a php file, but I had to rename it as such to work around extension restrictions.) fixed in the last release --Dfaure September 10, 2007, at 03:21 AM Thank you! --nfirvine
Also, I found it kind of offputting that the end of the block is specified with "sourcend" and not "sourceend". I fought with that for hours, thinking it was permission errors or something. Just a suggestion. --nfirvine June 09, 2007, at 08:31 PM seems to be fixed in version current at 2007-08-20 (but not in version loaded against this page) Thanks again --nfirvine
How does the This parameter has been renamed as How can I use highlight option to highlight certain lines? I tried highlight='1,2,3,4,5' and it does not work. I tried it on my pmwiki 2.2.0-beta56 with geshi 1.0.7.3 and also on this page. --Roman 2007-09-10 This has been verified to work with latest version of Geshi. You may need to upgrade --Dfaure September 13, 2007, at 04:47 AM Ah, I was confused by Geshi numbering scheme. It works with 1.0.7.20. Thanks, Roman 2007-09-13
Please comment any code changes you make when releasing a new version. I'm using a somewhat modified version of SourceBlock and keeping it in sync with your code isn't the easiest task, I hope you understand. :-) --Ted 2007-09-19 You could also give me more details on your customization that I could eventually take in account in the next version --Dfaure September 19, 2007, at 08:26 AM It's nothing special in fact, you could call this "minimization"; I've removed "codeblock" markup, code d/l url, plus a few more options keeping just the basics to make recipe smaller and a bit faster. --Ted 2007-09-20 I like SourceBlock very much and without external files it works for me like a charm. But I just can't get external files running. I installed LinkedResourceExtras and as an "enduser" didn't configure anything else - although this feels a little wrong because the receipe for LinkedResourceExtras says to include_once('cookbook/extlinkedres.php'); which I couldn't find in sourceblock.php. Could you please give a complete example for an external file, e.g. http://www.gnu.org/licenses/fdl.txt?
I tried [EDIT: deleted the wrong ones]
and only get empty code blocks. Thanks for any help! Frank - October 12, 2007, 7:20 PM The LinkedResourceExtras must be includes before SourceBlock to be taken in account. Then the dedicated markup is simply Thanks very much for the fast answer, unfortunately I still can't get external files running - please give me a little more details. All I did so far:
I tried the different versions for includin an external file as mentioned above but get empty boxes - except for the case I leave out the quotation marks around the URL. Then I get the following error: When I only use the (:source ...:) (without (:sourcend:))Syntax I even don't get a code box, but the URL will be made a hyperlink leaving the rest of the text as regular text. I would really appreciate if you could give a very short example here on the page including whatever txt-File or other type that one can find on the internet, e.g. http://www.gnu.org/licenses/fdl.txt I have no clue whether this is of any relevance: I use PmWiki offline with the server provided from here (Standalone). Thanks in advance for any further help! -- Frank October 18, 2007, at 09:30 AM [EDIT] Now that I changed the server from the small one to a full server all my problems disappeared within seconds. There seems to be no need to The "regular" way to proceed is the one which gave an error message ;). The recipe has been updated to better handle this. You should also note that the standalone server seems to be unable to deliver files requested via http by the script itself (atachments and requests to external webservers have been tested to work flawlessly). Thanks for the report. --Dfaure October 18, 2007, at 07:51 AM In XHTML documents, I get validation errors on pages with "Get Code" links. Fixed in latest release. Thanks for the report. --Dfaure December 05, 2007, at 09:52 AM Thanks for this recipe. Just a heads up to others that might be experiencing problems. Initially I couldn't get this recipe to work on my company's LAN. Turnout it's simply because I forgot to update file permission/ownership of the new files/dirs that I copied. -- hua What is the recommended way of changing colors? You may either use the Bug. Impossible to mix the following : (:source -getcode lang=c:)[@ xxx @] (:source -getcode lang=c:) xxx (:sourcend:) The different Another bug. Sometimes, the sourceblock.php failed with an error on line +151 when I try to use too many (:source:) markup on big pages. Should be fixed in latest version --Dfaure June 11, 2008, at 11:54 AM It seems ok :-) |