Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I modified your code so it accept ranges as well as single lines (ex: highlight="3,7,12-32,36"):
- //START LINE HIGHLIGHT SUPPORT
- $highlight = array();
- if ( !empty($match[4]) )
- {
- $highlight = strpos($match[4],',') == false ? array($match[4]) : explode(',', $match[4]);
- $h_lines = array();
- for($i = 0; $i < sizeof($highlight); $i++)
- {
- $h_range = explode('-', $highlight[$i]);
- if(sizeof($h_range) == 2)
- {
- $h_lines = array_merge($h_lines, range($h_range[0], $h_range[1]));
- }
- else
- {
- array_push($h_lines, $highlight[$i]);
- }
- }
- $geshi->highlight_lines_extra( $h_lines );
- }
- //END LINE HIGHLIGHT SUPPORT
- Of course, the regex needs to be changed so it accepts dashes:
- function wp_syntax_before_filter($content)
- {
- return preg_replace_callback(
- "/\s*<pre(?:lang=[\"']([\w-]+)[\"']|line=[\"'](\d*)[\"']|escaped=[\"'](true|false)?[\"']|highlight=[\"']((?:\d+[,-])*\d+)[\"']|\s)+>(.*)<\/pre>\s*/siU",
- "wp_syntax_substitute",
- $content
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement