hild1.no

Kagee's random rantings

SyntaxHighlighter Evolved With Highlight-range

Update: As of SyntaxHighlighter Evolved v. 3.0.0 this functionality is included in the plugin.

One of the first plugins i installed for this brand new WordPress was SyntaxHighlighter Evolved. I love to code, and knew i would find a use for it. To test it i used a large C++ file from cpp.snippets.org and began testing.

Highlight worked fine, but i i didn't support highlighting a range of lines. This might not be so useful, as you usually want to highlight small sections, but i rewrote syntaxhighlighter.php to support ranges.

[code language="text" toolbar="true" gutter="false"]
[code language="php" firstline="740" gutter="true" highlight="748-761,765"][/code]

This expandes into

[code language="html" toolbar="true" gutter="false"]
<pre class="brush: php; auto-links: false; first-line: 740; gutter: true;
highlight: [765,748,749,750,751,752,753,754,755,756,757,758,759,760,761];
html-script: false; light: false; pad-line-numbers: false;
smart-tabs: true; tab-size: 4; toolbar: true; wrap-lines: true;">
[/code]

after beeing parsed by my (highlighted) changes

[code language="php" wraplines="true" autolinks="false" firstline="740" gutter="true" highlight="748-761,765" htmlscript="false" light="false" padlinenumbers="false" smarttabs="true" tabsize="4" toolbar="true"]
// Sanitize row highlights
if ( false != $atts['highlight'] ) {
@h@ if ( false === strpos( $atts['highlight'], ',' ) && false === strpos( $atts['highlight'], '-' ) ) {
$atts['highlight'] = (int) $atts['highlight'];
} else {
$highlights = explode( ',', $atts['highlight'] );

foreach ( $highlights as $key => $highlight ) {
// if this value is a range
if (FALSE !== strpos($highlight, '-',1)) {
// we require 1 digit before the dash,
// if not we ignore it and pass it on
$range = explode('-', $highlight);
// Around here we should probably try to cast
// to int and if-check to sanitize the values
// loop over the range and add it to highlights
for(;$range[0] <= $range[1]; $range[0]++){
$highlights[] = $range[0];
}
// unset the current (range-type) highlight
unset($highlights[$key]);
} else {
$highlights[$key] = (int) $highlight;
if ( empty($highlights[$key]) )
unset($highlights[$key]);
}
}

$atts['highlight'] = implode( ',', $highlights );
}
}
[/code]

New syntaxhighlighter.php with highlight-range-code based on SyntaxHighlighter Evolved version 2.3.8

See also Syntaxhighlighter Evolved with inline-highlight

Using BankID (Norwegian Type) in Ubuntu 10.04

Update: As of Ubuntu 10.10 this should not be nessesary, as OpenJDK in Ubuntu >= 10.10 should work with BankID.

In Ubuntu 10.04 (and probably onwards) OpenJDK Java and the Icedtea java plugin are the standard Java toolkit. BankID works with OpenJDK (just try installing Opera 10.10. Opera pre 10.5 use OpenJDK directly, without Icedtea), Icedtea is the troublemaker.

Sun Java has been pushed all the way into the Canonocal partner repository, that is not enabled as default. The following lines are a quick way to enable it and install java, even if the same is possible with lengthy GUI "click-here-then-there" tutorials.

[code language="bash" wraplines="false" autolinks="false" toolbar="false" gutter="false"]sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-plugin[/code]

Line one adds the Canonical Partner repository to you software sources. There should be no complications if it is already enabled. Line two updates the list of avalible packages, so that line three can find and install the package sun-java6-plugin and it's dependencies.

Sun Java should be the standard after this, if not, try to force it to be default with this line. And remember to restart you browser (or possibly restart your system)

[code language="bash" wraplines="false" gutter="false" toolbar="false"]sudo update-java-alternatives -s java-6-sun[/code]