Plugin Directory

Changeset 666410


Ignore:
Timestamp:
02/11/2013 05:05:34 PM (13 years ago)
Author:
dwhitevisoft
Message:

Added GeSHi code block support

Location:
goodbye-syntax-highlighter/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • goodbye-syntax-highlighter/trunk/goodbye-syntax-highlighter.php

    r647604 r666410  
    44Plugin URI: https://github.com/visoft/goodbye-syntax-highlighter
    55Description: Say goodbye to syntaxhighlighter and hello to highlight.js
    6 Version: 0.1.1
     6Version: 0.1.2
    77Author: Damien White (Visoft, Inc.)
    88Author URI: http://www.visoftinc.com
     
    1111
    1212/*
    13   Copyright 2012 Visoft, Inc. <info@visoftinc.com>
     13  Copyright 2012-2013 Visoft, Inc. <info@visoftinc.com>
    1414
    1515  This file is part of goodbye-syntax-highlighter
     
    2020    (at your option) any later version.
    2121
    22     Collapsing Archives is distributed in the hope that it will be useful,
     22    Goodbye Syntax Highlighter is distributed in the hope that it will be useful,
    2323    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2424    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     
    2626
    2727    You should have received a copy of the GNU General Public License
    28     along with Collapsing Archives; if not, write to the Free Software
     28    along with Goodbye Syntax Highlighter; if not, write to the Free Software
    2929    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3030*/
     
    3535
    3636function gbsh_covert_code_blocks( $text ) {
    37     return preg_replace( '|<pre class="[\"]*brush:\s?([^;]*);[^>]*>([^<]*)</pre>|se', 'gbsh_convert_code(\'$2\',\'$1\');', $text);
     37    $text = preg_replace_callback('%<pre class="["]*brush:\s?([^;]*);[^>]*>([^<]*)</pre>%sim', 'gbsh_convert_code', $text);
     38
     39    $text = preg_replace_callback('%<pre lang="([^"]*)"[^>]*>([^<]*)</pre>%sim', 'gbsh_convert_code', $text);
     40
     41    return $text;
    3842}
    3943
    40 function gbsh_convert_code( $code, $language) {
    41     $code = stripslashes( trim( str_replace(array('&amp;', '&#039;', '&quot;'), array('&','\'','"'), $code) ) );
     44function gbsh_convert_code( $matches ) {
     45    // You can vary the replacement text for each match on-the-fly
     46    // $matches[0] holds the regex match
     47    // $matches[n] holds the match for capturing group n
     48    $code = stripslashes( trim( str_replace(array('&amp;', '&#039;', '&quot;'), array('&','\'','"'), $matches[2]) ) );
     49    $language = $matches[1];
     50
    4251    // covert csharp into cs
    4352    if ($language == 'csharp') $language = 'cs';
  • goodbye-syntax-highlighter/trunk/readme.txt

    r647604 r666410  
    22Contributors: dwhitevisoft
    33Donate link: http://www.visoftinc.com/
    4 Tags: highlight.js, syntax, code, pre, highlight, syntaxhighlighter
     4Tags: highlight.js, syntax, code, pre, highlight, syntaxhighlighter, geshi
    55Requires at least: 3.1
    66Tested up to: 3.5
    7 Stable tag: 0.1.1
     7Stable tag: 0.1.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 Say goodbye to plugins like SyntaxHighlighter Evolved and hello to highlight.js. With this plugin, you can seamlessly transition from one to another.
     11Say goodbye to plugins like SyntaxHighlighter Evolved and WP-Syntax (NEW!) and hello to [highlight.js](http://softwaremaniacs.org/soft/highlight/en/). With this plugin, you can seamlessly transition from one to another.
    1212
    1313== Description ==
     
    2525So there you have it. This WordPress plugin will go through and process your SyntaxHighlighter style blocks into ones that highlight.js works with out-of-the-box. It will also add the language that you have specified with the `brush` class and add it as a class on the `<code />` element ([following the HTML5 recommendation](http://www.w3.org/html/wg/drafts/html/master/text-level-semantics.html#the-code-element)). Nothing is changed in the DB, so if you decide to go back to SyntaxHighlighter, you can without any issues.
    2626
     27## GeSHi
     28This plugin now supports conversion of [GeSHi](http://qbnz.com/highlighter/) style code blocks! Now you can move from plugins such as [WP-Syntax](http://wordpress.org/extend/plugins/wp-syntax/) and [WP-GeSHi-Highlight](http://wordpress.org/extend/plugins/wp-geshi-highlight) to highlight.js.
     29
     30GeSHi uses the syntax that is *close* to SyntaxHighlighter, except instead of putting the language in the `class` attribute, it uses the `lang` attribute. Similar to the SyntaxHighligher conversion, it will go through and process your GeSHi style blocks into ones that highlight.js works with out-of-the-box. It will also add the language that you have specified with the `lang` attribute and add it as a `class` on the `<code />` element.
     31
    2732== Installation ==
    2833
     
    3641= 0.1.0 =
    3742* Initial release
     43
    3844= 0.1.1 =
    3945* Modified output to use the HTML5 recommended syntax highlighting class names, e.g. `language-ruby`. For more information, see [the HTML5 spec](http://www.w3.org/html/wg/drafts/html/master/text-level-semantics.html#the-code-element)
     46
     47= 0.1.2 =
     48* Added conversion of GeSHi style code blocks
Note: See TracChangeset for help on using the changeset viewer.