Advertisement
Guest User

WP-Syntax

a guest
Jul 5th, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. I modified your code so it accept ranges as well as single lines (ex: highlight="3,7,12-32,36"):
  2.  
  3. //START LINE HIGHLIGHT SUPPORT
  4. $highlight = array();
  5. if ( !empty($match[4]) )
  6. {
  7. $highlight = strpos($match[4],',') == false ? array($match[4]) : explode(',', $match[4]);
  8.  
  9. $h_lines = array();
  10. for($i = 0; $i < sizeof($highlight); $i++)
  11. {
  12. $h_range = explode('-', $highlight[$i]);
  13.  
  14. if(sizeof($h_range) == 2)
  15. {
  16. $h_lines = array_merge($h_lines, range($h_range[0], $h_range[1]));
  17. }
  18. else
  19. {
  20. array_push($h_lines, $highlight[$i]);
  21. }
  22. }
  23.  
  24. $geshi->highlight_lines_extra( $h_lines );
  25. }
  26. //END LINE HIGHLIGHT SUPPORT
  27.  
  28. Of course, the regex needs to be changed so it accepts dashes:
  29.  
  30. function wp_syntax_before_filter($content)
  31. {
  32. return preg_replace_callback(
  33. "/\s*<pre(?:lang=[\"']([\w-]+)[\"']|line=[\"'](\d*)[\"']|escaped=[\"'](true|false)?[\"']|highlight=[\"']((?:\d+[,-])*\d+)[\"']|\s)+>(.*)<\/pre>\s*/siU",
  34. "wp_syntax_substitute",
  35. $content
  36. );
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement