Syntaxlove-Talk
Please add your comments about the Syntaxlove recipe here. --MatthiasGünther Februray 21, 2010, at 03:40 PM
I just installed the recipe in pwmiki 2.2.97, I get html paragraph start/end tags inserted around the code, any idea why? /Johan Bengtsson 2019-02-14
Tcp/Tk support
No love for tcl/tk? tonybaldwin May 04, 2011, at 11:14 PM
No, I don't plan to implement this feature. MatthiasGünther May 13, 2011 7:29 AM ---
Perl hashes with variable keys appear incorrectly
Hello, when I try to use variables as keys of hashes in Perl, in SyntaxLove, they disappear. Could you correct it?
$hash{$key}, $hash->{$key}
. (Without dollar sign it works OK: $hash{key}
.)adam, 14-Dec-2010
Correction (solution and workaround): using the "Prevent formatting" syntax inside the code environment solves the problem. It would be reasonable for the next version of SyntaxLove to do this automatically for the whole code, i.e. to replace this
(:codestart perl:) [...] (:codeend:)
with this:
(:codestart perl:) [= [...] =] (:codeend:)
See also http://www.pmwiki.org/wiki/PITS/01236.
adam, 15-Dec-2010
Modification
I think this plugin is great, but the current SyntaxHighlighter in Syntaxlove is a little dated. So I created a package for personal use based on the latest SyntaxHighlighter fork from "outofwhatbox.com". I noticed that there are a lot of options that can't even be touched with this PmWiki plugin, so I went ahead and modified the main PHP script to default to "Plain" if no code type is defined, and I also added access to all of the options: turning off numbers, adding titles, turn off wrapping, turn on collapsing, etc. I am certain this can be done more eloquently, but I wanted more flexibility, and it wasn't currently there, so I added it in my personal copy. It would be nice if something like this was added by default to Syntaxlove. I stink at regular expression, so I am sure this can really be improved upon.
Note: code type must always be specified first; I wanted to keep it compatible with current syntax, and I didn't want to loop more than I had to to find it, so it is always first. Technically, you could give the code its own setting ID like code='php'. Then you could have this recipe find the code anywhere.
example use:
(:codestart:)
Plain style(:codeend:)
(:codestart php title='Title' highlight='[1,2,3,7]' wrap='false':)
Use PHP styling.
Add the title "Title"
highlight lines 1,2,3, and 7
turn line wrapping off
(:codeend:)
This is the modification I made to the Syntaxlove.php for use with the latest SyntaxHighlighter:
- I removed all old Syntaxhighlighter files and replaced them with the latest from outofwhatbox.com.
- I remapped the shCore.css to look for the images in the correct place
- I then modified syntaxlove.php to use all options and default to plain style if none is specified
<?php if (!defined('PmWiki')) exit(); /* Copyright 2009-2010 Matthias Guenther (matthias.guenther@wikimatze.de) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. To use this recipe just follow the instruction can be found under the recipe-site on pmwiki.org (syntaxlove)! */ $RecipeInfo['syntaxlove']['Version']='2010-10-07'; if (!isset($syntax_style)) { $syntax_style = "shThemeDefault.css"; } $HTMLHeaderFmt[] = "<script type='text/javascript' src='\$PubDirUrl/syntaxlove/scripts/shCore.js'></script>"; foreach ($Array_Syntaxlove as $key => $value){ switch ($value){ case "1": $HTMLHeaderFmt[] = "<script type='text/javascript' src='\$PubDirUrl/syntaxlove/scripts/shBrush$key.js'></script>"; } } $HTMLHeaderFmt[] = " <link type='text/css' rel='stylesheet' href='\$PubDirUrl/syntaxlove/css/shCore.css'/> <link type='text/css' rel='stylesheet' href='\$PubDirUrl/syntaxlove/css/$syntax_style'/> <script type='text/javascript'> SyntaxHighlighter.all() </script>"; Markup('code', '<fulltext', '/\\(:codestart(.*?):\\)(.*?)\\(:codeend:\\)/esi', "'<:block>'.Keep(str_replace(array(), array(), PSS('<pre class=\"'.syntaxlove_options('$1').'\">'.'$2'.'</pre>')))"); function syntaxlove_options($options) { $class = ''; $params = array('html' => 'html-script', 'lightmode' => 'light', 'wrap' => 'wrap-lines', 'gutter' => 'gutter', 'ruler' => 'ruler', 'toolbar' => 'toolbar', 'collapse' => 'collapse', 'autolinks' => 'auto-links', 'smarttabs' => 'smart-tabs', 'pad' => 'pad-line-numbers', 'title' => 'title', 'firstline' => 'first-line', 'highlight'=> 'highlight', 'tabsize' => 'tab-size'); #look to see if the code option has been specified, if not, resort to 'plain' formatting $brush = 'plain'; if(preg_match("/([^ ](\w*)[^= ])/esi",$options,$matches)) { $brush = $matches[0]; foreach($params as $k => $v) { if(preg_match("/$k/i", $matches[0], $match)){ $brush = 'plain'; } } } $class .= "brush:'".$brush."';"; #Find options and format them for html foreach ($params as $key => $value) { if (preg_match("/($key='.*?')/esi", $options,$matches)) { $class .= str_replace("$key=", "$value:", $matches[0]).";"; } } return ($class); }
facelessuser, 6-Nov-2010
Hello facelessuser, your suggestion are great. I included them and create a new version
MatthiasGünther Dec 5, 2010 6:28 PM
New Version
Any chance of getting a new version of SyntaxLove updated to the newest SyntaxHighlighter?
DaveG, 20-Sep-2009
Hello Dave, I just now read your post and will be looking to get the new version of the syntaxhighlighter working.
MatthiasGünther Dec 5, 2010 6:25 PM
Limit display
Is it possible to limit the number of lines displayed?
Thanks for the great recipe.
Steven
Hello Steve, do you mean to toggle on or off the line numbers? If yes, I still haven't found a workaround in the actual version of the recipe, but found an alternative solution under [(approve links) edit diff]. I will look, if I can implement this feature in a future version of this recipe.
MatthiasGünther May 10, 2010 9:41 AM
Problematic interactions with quoted-printable encoding
Great recipe :) I have just installed it, and one of the first source snippets I was working with logs using HTML strings. Some of these strings include quoted-printable encoding, e.g. &. The rendered output displays "&" rather than "&", as does clicking on SyntaxHighlighter's "view source" button (not the browser's "view source"!). In short the rendered source is not the contents of the codestart...codeend block verbatim.
I have produced an example test case that can expose a variety of potential encoding errors:(:codestart plain:) # Nasty example proc nasty {a b c} { if { ($a < $b) || ($a > $c) && ($b < $c) } { set d [expr { $a & $b << 2 }] } puts "<p>Evil HTML output < &</p>" puts "And some Wiki-like output -- ''italic'' and '''bold''' and some @@inline code@@ for example" } (:codeend:)The current version (20090920) displays the second to last "puts" line as
puts "<p>Evil HTML output < &</p>"rather than the expected
puts "<p>Evil HTML output < &</p>"
One reason this is important is that is should be possible for a scripting language to extract and run code from an HTML page. To do this one would extract the contents of <pre> or <code> blocks, remove the quoted-printable encoding, and eval() the resulting text as a script. If the output (as displayed in a web browser) is not a faithful representation of the input (the exact content of the codestart...codeend block) then this becomes impossible.
Recommended fix: change the Markup() call at the bottom of syntaxlove.php to the following:Markup('code', '<fulltext', '/\\(:codestart (\w*?):\\)(.*?)\\(:codeend:\\)/esi', "'<:block>'.Keep(str_replace(array(), array(), PSS('<pre class=\"brush: $1\">'.'$2'.'</pre>')))");
Thanks Twylite, your fixed markup is welcome. Without this fix you can not use SyntaxLove for most languages. The worst issue with the old markup: It generates closing tags for XML which are not given in the plain code - and that is really annoying. Example:
<xml version="1.0" encoding="ISO-8859-1"?>
Try to highlight this code line with SyntaxLove (current download version) and you know whats the problem.
Conditions need spaces
Looks like it has difficulty when things aren't spaced exactly right. In this PHP example (dummy code extracted from a larger working example), this doesn't display correctly:
function test ($t) { for ($i=0; $i<strlen($t); $i++) { $x = 1; } }
Adding spaces before and after the less than condition makes everything work.
DaveG, 20-Sep-2009
Hello DaveG, I still haven't much used this recipe in my wiki and I will add this behavior on the bug list.
MatthiasGünther September 25, 2009 6:44 AM
Simplify Markup
I like it. I'm using it here, and it looks good, thanks! Would it be possible to simplify the markup a little, so we don't have to remember the <pre> part. Usage would be like this:
(:codestart ruby:) RUBY CODE (:codeend:)
Changing the markup something like this should do it (not thoroughly tested...):
Markup('code', 'fulltext', '/\\(:codestart (\w*?):\\)(.*?)\\(:codeend:\\)/esi', "'<:block>'.Keep(str_replace(array('>', '<', '&'), array('>', '<', '&'), PSS('<pre class=\"brush: $1\">'.'$2'.'</pre>')))");
DaveG, 20-Sep-2009
Hello DaveG, thanks for using my recipe. I already thought about such a markup as you mentioned above, but I can't (or won't) remember the markup for such special things in Ruby. I will look, if your markup works correct and then include the changes in the recipe
MatthiasGünther September 25, 2009 6:42 AM
Language Inclusion Options
Nice script. Given that inclusion of all languages is over 90k of javascript to download, even if it's only the first time, do you plan on incorporating a way to include/exclude languages? Perhaps a simple true/false array would work, with a default set for all?
DaveG, 31-Aug-2009
Hello DaveG, glad you like it. I must say that I doesn't take a look at the overhead if I load all languages. The option with the array you mention will easy to integrate. In the next few days I will do it and upload a new version
MatthiasGünther 10-September, 2009 10:36 AM
No love for tcl/tk? tonybaldwin May 04, 2011, at 11:14 PM
Talk page for the Syntaxlove recipe (users).