SourceBlock-Talk

back to SourceBlock

Please leave the latest message at the top.

I have problems with PHP7 (Ubuntu 16.04), if I activate sourceblock, I can't use my wiki at all, everything stays empty. Downgrade to php5 and the wiki works again. Can anybody help me?

Problem fixed: After updating PmWiki from 2.2.68 to 2.2.94 sourceblock works again :-)

PageTextVariables within a (:source:)...(:sourceend:) region are replaced-on-save, while PageTextVariables in preformatted markup [@...@] region are not.

UPDATE July 11, 2014 the use of (:source:) [@ .... @] removes this issue. I'm surprised that it is required, however. I much prefer the simple (:markup:)...(:markupend:) format.

MichaelPaulukonis July 10, 2014, at 10:07 PM

I'm getting the odd scenario where the getcode link is off-by-one. I have one sourceblock markup on the page, it renders, but the link is for num=2 -- which, predictably, displays an empty page when clicked. If I manually change the URL to num=1 the code displays as expected.

This was noted by another user some years ago:

Hi I've just done a fresh install, apart from some apache rewrites its all pretty standard so far. I'm having the strange issue that when I attempt to post a script the GetCode link has the wrong num=X, should start at 1 but they're starting at 2. Even in Site/Side bar... interestingly though num=1 works on Main/HomePage..

MichaelPaulukonis June 30, 2014, at 10:24 AM

UPDATE July 11, 2014 I believe it's a wiki-config issue, because another (non-farm) wiki running on the same host, same account does not have this problem. I will check for recipe interference....

UPDATE 2014.08.21 and 08.25 It's BlogIt. When I disable BlogIt, or use sourceblock on non-blog pages, the num=n parameters are correct. When BlogIt is enabled, the num=n params are off on all blog-pages. If one source-block is present, the first block is off-by-one (eg, 2). If two source-blocks are present, the first block is off-by-two, and the others proceed in sequence (eg, 3,4). If three source-blocks are present, the first is off-by-three, and the others proceed in sequence (eg, 4,5,6). So it's an off-byn issue, where n is the number of source-blocks present.

This is probably an issue with BlogIt, and has been brought up in greater detail @ BlogIt-Talk#offbyn.

Until now, the "get code" feature fully relies on the way the page is built. If really required this could be altered to be linked to the source content itself. --Dfaure August 26, 2014, at 05:12 AM

Change Request (to make code work with Precode):

  Any other similar options for setting 
    $geshi->set_header_type(GESHI_HEADER_??); 
 should work.
 
165c165,167
<     $geshi->set_header_type(GESHI_HEADER_DIV);
---
>     if(@$opt['headw']==='0')
>       $geshi->set_header_type(GESHI_HEADER_NONE);
>     else $geshi->set_header_type(GESHI_HEADER_DIV);

VKrishn July 23, 2012, at 02:27 AM

The feature has been implemented in last version, using the undocumented option -headw --Dfaure August 26, 2014, at 04:59 AM

Change Request:
I propose a change in sourceblock.php to make the supported languages listing more usable by sorting it. Here is the diff output: (Note this is against version 2009-01-27.)

  • instead of building only an array, use $out to hold the strings generated.
        243c243
        <   $infos = array("Geshi Version: " . GESHI_VERSION);
        ---
        >   $out = "Geshi Version: " . GESHI_VERSION;
        245c245
        <     $infos[] = "\n||border=1\n||! lang ||! full name ||";
        ---
        >     $out .= "\n||border=1\n||! lang ||! full name ||\n";
  • use $lang as the index into the $infos array so it can later be sorted
        253c253
        <           $infos[] = "|| " . $lang . " ||" . $language_data['LANG_NAME'] . " ||";
        ---
        >           $infos[$lang] = "|| " . $lang . " ||" . $language_data['LANG_NAME'] . " ||";
        255c255
        <           $infos[] = "* " . $lang . "";
        ---
        >           $infos[$lang] = "* " . $lang . "";
  • sorts $infos by it's keys, and implode into $out
        260c260,261
        <   $out = implode("\n", $infos) . "\n";
        ---
        >   ksort($infos);
        >   $out .= implode("\n", $infos) . "\n";

As you can see, it builds the precursors to the actual language list in the $out variable, and $infos just contains the rows of the table, using $lang as the index into the $infos array. Before joining into $out, the $infos array is key sorted. In addition, if there are wiki words in the language list, they are not enabled. --tamouse November 09, 2011, at 08:13 AM

on second thought, leave out the (:no/linkwikiwords:) stuff. Better to let the author decide if they want to do that rather than force something on them. --tamouse November 09, 2011, at 08:24 AM
patch supplied: sourceblock-make-changes-to-sort-languages.patch.txtΔ --tamouse April 07, 2012, at 01:30 PM
The feature has been adopted --Dfaure July 06, 2012, at 04:30 AM

Question: I found a bug, not sure where else to put it, but this will highlight the problem, if placed on a wiki with the SourceBlock recipe installed.

If highlighting is used on any source block, the last instance of that same language source block type on the same page must also use highlighting

  • Eliminating the first occurrence of either language block type will cause no highlighting to occur.
  • Eliminating the last occurrence of either language block type (or adding highlighting to the last occurrence) will cause highlighting to appear correctly.
(:source lang=XML highlight='1,2' :) [=
    <!--This
        Should be highlighted -->
=]
(:source lang=XML :) [=
    <!--This
        Should NOT be highlighted -->
=]

(:source lang=Java highlight='1' :) [=
System.out.println("highlighted");
=]
(:source lang=Java :) [=
System.out.println("not highlighted");
=]
Nice catch! Fixed in latest release --Dfaure July 06, 2012, at 08:36 AM

Question: how can I place ~~~~ (4 times the ~) in a codebox? Astrid May 31, 2011, at 10:15 AM

The 4 times '~' post markup is processed while the page is saved after editing it. The recipe don't even see it. --Dfaure July 06, 2012, at 04:30 AM

Question: Anyone got SourceBlock to work with GeSHI 1.0.8.10? I just get a blank trying to use the new version, but 1.0.8.8 works fine. Daniel Andersson 2011-04-24 08:54:47 UTC

The directory structure is different between 1.0.8.8 and 1.0.8.10, and for 1.1.2 GeSHi seems to be completey remade.
So SourceBlock needs to be remade as well I guess? Daniel Andersson 2011-04-27 08:41:55 UTC

Hi I've just done a fresh install, apart from some apache rewrites its all pretty standard so far. I'm having the strange issue that when I attempt to post a script the GetCode link has the wrong num=X, should start at 1 but they're starting at 2. Even in Site/Side bar... interestingly though num=1 works on Main/HomePage..

Just to confirm I just did a reinstall skipping any unneeded steps and I'm getting this on all my BlogIt posts. Nov 3 2010 DStark?

I encountered the problem that the Link GetCode is no longer written as GetCode but now with [$[Get Code]] ... -Markus October 12 2009

A workaround is to add SDV($SourceBlockLinkText, "Get Code"); before the include_once line. This breaks the automatic localisation. Maxim? October 31, 2009, at 07:48 AM

Question: Is there an easy way to add a little expand/collapse button to expand or collapse the source code block. I have code that has 100s of line of code and will be helpful. Thanks. -Shah April 23, 2009 at 02:18 PM

Nevermind - It was quite easy to implement, I just used Toggle - Shah

Regarding leading whitespace trimming: for many languages, the whitespace is significant and the first line might contain leading whitespace. If I change line 147 to restrict the trim characters:

  if(!@in_array('trim', (array)$opt['-'])) $block = trim($block, "\n\r");

it behaves as I'd like - it still trims line breaks so you don't have to cram the first line after the [@, so the wikisource is more readable. How about adding a variable in config.php to control this? Maxim? April 03, 2009, at 05:15 AM

SourceBlock is very nice and works well but I find that some of the colors really hard to read. I assume that id=ID, class=CLASS can be used in some way to modify the colors ... but how should they be used, I couldn't find an example of how to use it. j 2009-04-01

Provided that:
  • The recipe configures Geshi to work using classes.
  • The (:source lang=LANG class=MYCLASS:) ... markup result will (by default) be encapsulated into the following <div> hierarchy:
<div class='sourceblock MYCLASS' id='...'>
  <div class='sourceblocktext'>COLORIZED SOURCE CODE HERE</div>
  <div class='sourceblocklink'>...</div>
</div>
You may use you own CSS definition such as:
.MYCLASS .LANG .kw1 { ... }
Please refer to the Local customization files and the GeShi documentation for further details on what styles to define and how to enable them on your pages. --Dfaure April 02, 2009, at 07:35 AM

Leading whitespace on the first line is lost.

This is a feature. Use the -trim option to prevent this behavior. --Dfaure April 02, 2009, at 06:21 AM

What is the recommended way of changing colors?

You may either use the id=... or class=... parameters associated with your own stylesheet definition, or alter the $GeshStyles global variable --Dfaure June 11, 2008, at 07:54 AM

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]

(:source http://www.gnu.org/licenses/fdl.txt :)

(:source http://www.gnu.org/licenses/fdl.txt :)

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 (:source FILE_SPECIFICATION PARAMS:).--Dfaure October 14, 2007, at 04:40 AM

I get an error when I try to use lang=html for some reason. If I just sub lang=php, it will highlight html, but I'm confused, since html is in the list of languages at geshi. As an example, here http://baldwinsoftware.com/wiki/pmwiki.php?n=Public.Penwell1 I am now using lang=php, because when I try to use lang=html, I get

 
GeSHi Error: GeSHi could not find the language html (using path /home/content/29/5132729/html/wiki/cookbook/geshi/geshi/) (code 2)

tonybaldwin June 03, 2011, at 08:15 AM

This is a GeSHi idiosyncrasy. They have the file name as html4strict for html formatting. So you need to do the following:
(:source lang=html4strict:)
<html></html>
(:sourceend:)

(:source lang=html4strict:) <html></html> (:sourceend:)

--tamouse November 09, 2011, at 08:00 AM

Talk page for the SourceBlock recipe (users).