Création d'un plugin SHJS pour PluXML

SHJS - coloration syntaxique en JavaScript


Je souhaite utiliser un plugin pour la coloration syntaxique sous pluXml.
Après quelques recherche sur le forum de PluXml, je n'ai pas trouvé de plugin correspondant à mes attentes.
J'ai fouiné sur le net et j'ai découvert SHJS :

SHJS est un programme JavaScript de coloration syntaxique de code source dans les documents HTML.
Avec SHJS vos documents source sont mis en évidence par le navigateur Web côté client.
SHJS utilise des définitions de langage de GNU Source-highlight.. Cela donne à SHJS la capacité de mettre en évidence le code source écrit en plusieurs langages :

 


Bison
C
C++
C#
ChangeLog
CSS
Desktop files
Diff
Flex
GLSL
Haxe
HTML
Java
Class
sh_bison
sh_c
sh_cpp
sh_csharp
sh_changelog
sh_css
sh_desktop
sh_diff
sh_flex
sh_glsl
sh_haxe
sh_html
sh_java

Java properties files
JavaScript
JavaScript with DOM
LaTeX
LDAP files
Log files
LSM (Linux Software Map) files
M4
Makefile
Objective Caml
Oracle SQL
Pascal
Perl
Class
sh_properties
sh_javascript
sh_javascript_dom
sh_latex
sh_ldap
sh_log
sh_lsm
sh_m4
sh_makefile
sh_caml
sh_oracle
sh_pascal
sh_perl

PHP
Prolog
Python
RPM spec files
Ruby
S-Lang
Scala
Shell
SQL
Standard ML
Tcl
XML
Xorg configuration files
Class
sh_php
sh_prolog
sh_python
sh_spec
sh_ruby
sh_slang
sh_scala
sh_sh
sh_sql
sh_sml
sh_tcl
sh_xml
sh_xorg


J'ai créé un plugin pour PluXml afin de pouvoir utiliser SHJS dans mes articles
Si vous souhaitez utiliser ce plugin il vous suffit de Télécharger le plugin shjs pour PluXml et l'installer dans PluXml
Décompresser le zip dans le dossier plugins de PluXml, activer le depuis l'interface d'administration et configuré le style que vous souhaitez utiliser.

Exemple d'utilisation, vous pouvez changer le style appliqué à la coloration syntaxique :

 

#include <iostream>

using namespace std;

int main(int argc, char ** argv) {
  cout << "Hello world" << endl;
  return 0;
}

Pour obtenir le résultat ci dessus insérer votre code dans un article avec la balise <pre> en indiquant la classe à utilisée pour le langage :

<pre class="sh_cpp">
#include &lt;iostream&gt;

using namespace std;

int main(int argc, char ** argv) {
  cout &lt;&lt; "Hello world" &lt;&lt; endl;
  return 0;
}
</pre>

Test avec python

#!/usr/bin/python2
# -*- coding: utf-8; -*-
"""
Copyright (C) 2007-2012 Lincoln de Sousa <lincoln@minaslivre.org>
Copyright (C) 2007 Gabriel Falcão <gabrielteratos@gmail.com>

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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
"""
from __future__ import absolute_import

import pygtk
import gobject
pygtk.require('2.0')
gobject.threads_init()

import gtk
import vte
from pango import FontDescription
import pynotify
import gconf
import dbus
from xdg.DesktopEntry import DesktopEntry
import xdg.Exceptions

import os
import sys
import signal
from thread import start_new_thread
from time import sleep
import posix
from urllib import url2pathname
from urlparse import urlsplit

import guake.globalhotkeys
from guake.simplegladeapp import SimpleGladeApp, bindtextdomain
from guake.prefs import PrefsDialog, LKEY, GKEY
#from guake.dbusiface import DbusManager, DBUS_NAME, DBUS_PATH
from guake.common import test_gconf, pixmapfile, gladefile, ShowableError, _
from guake.common import shell_quote
from guake.globals import NAME, VERSION, LOCALE_DIR, KEY, GCONF_PATH, \\
    TERMINAL_MATCH_EXPRS, TERMINAL_MATCH_TAGS, \\
    ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER

import dbus.service
import dbus.glib
# import guake.common
dbus.glib.threads_init()
#############################################################################################################################
# Remplace
# from guake.dbusiface import DbusManager, DBUS_NAME, DBUS_PATH
DBUS_PATH = '/org/guake/RemoteControl2'
DBUS_NAME = 'org.guake.RemoteControl2'

class DbusManager(dbus.service.Object):
    def __init__(self, guakeinstance):
        self.guake = guakeinstance
        self.bus = dbus.SessionBus()
        bus_name = dbus.service.BusName(DBUS_NAME, bus=self.bus)
        super(DbusManager, self).__init__(bus_name, DBUS_PATH)

    @dbus.service.method(DBUS_NAME)
    def show_hide(self):
        self.guake.show_hide()

    @dbus.service.method(DBUS_NAME, in_signature='s')
    def add_tab(self, directory=''):
        self.guake.add_tab(directory)

    @dbus.service.method(DBUS_NAME, in_signature='i')
    def select_tab(self, tab_index=0):
        self.guake.select_tab(int(tab_index))

    @dbus.service.method(DBUS_NAME, out_signature='i')
    def get_selected_tab(self):
        return self.guake.get_selected_tab()

    @dbus.service.method(DBUS_NAME, in_signature='s')
    def execute_command(self, command):
        self.guake.execute_command(command)

    @dbus.service.method(DBUS_NAME, in_signature='s')
    def rename_current_tab(self, new_text):
        self.guake.rename_current_tab(new_text)

    @dbus.service.method(DBUS_NAME)
    def show_about(self):
        self.guake.show_about()

    @dbus.service.method(DBUS_NAME)
    def show_prefs(self):
        self.guake.show_prefs()

    @dbus.service.method(DBUS_NAME)
    def quit(self):
        self.guake.quit()
#############################################################################################################################



popup_works = True
if not pynotify.init('Guake!') or pynotify.get_server_info() == None :
    popup_works = False
    print "WARNING: could not use popup notification"

GNOME_FONT_PATH = '/desktop/gnome/interface/monospace_font_name'
Vus : 2206
Publié par Zeph : 15