This blogs is a part-2 of How to add SyntaxHighlighter to Blogger where I will be testing the syntax highlighting abilities of this library.
SyntaxHighlighter provides various configuration parameters to be used with the <pre> tag.
SyntaxHighlighter provides various configuration parameters to be used with the <pre> tag.
Java (With Rulers -- not working?)
<pre code="brush: java; ruler: true;">
import java.io.*;
public class HelloWorld{
  public static void main(String[] args){
      System.out.println("Hello World!");
  }
}
</pre>
import java.util.*;
import java.io.*;
public class HelloWorld{
  public static void main(String[] args){
      System.out.println("Hello World!");
  }
}Python (With the first line number set to 100)
<pre class="brush: python; first-line: 100">
import os
import sys
import time
class Box:
   def method1(self, x, y):
      try:
          print x, y
      except:
          pass
</pre>
import os
import sys
import time
class Box:
   def method1(self, x, y):
      try:
          print x, y
      except:
          passXML (With lines 4 and 6 highlighted)
<pre class="brush: xml;highlight: [4, 6]"> <html> <head> <title>Test page</title> </head> <body> Welcome to the test page. </body> </html> </pre>
<html> <head> <title>Test page</title> </head> <body> Welcome to the test page. </body> </html>
Real World Code snippet: OpenStack FWaaS Plugin
<pre class="brush: python; ruler: true; gutter: true; first-line: 10; highlight: [37,38]; smart-tabs: true; toolbar: true">
from neutron_fwaas.common import exceptions
from neutron_fwaas.common import fwaas_constants
from neutron_fwaas.extensions.firewall_v2 import Firewallv2PluginBase
from neutron_fwaas.services.firewall.service_drivers import driver_api
from neutron_fwaas.services.logapi.agents.drivers.iptables \
    import driver as logging_driver
LOG = logging.getLogger(__name__)
@registry.has_registry_receivers
class FirewallPluginV2(Firewallv2PluginBase):
    """Firewall v2 Neutron service plugin class"""
    supported_extension_aliases = [firewall_v2.ALIAS]
    path_prefix = firewall_v2.API_PREFIX
    def __init__(self):
        super(FirewallPluginV2, self).__init__()
        """Do the initialization for the firewall service plugin here."""
        # Initialize the Firewall v2 service plugin
        service_type_manager = st_db.ServiceTypeManager.get_instance()
        service_type_manager.add_provider_configuration(
            fwaas_constants.FIREWALL_V2,
            provider_conf.ProviderConfiguration('neutron_fwaas'))
        # Load the default driver
        drivers, default_provider = service_base.load_drivers(
            fwaas_constants.FIREWALL_V2, self)
        LOG.info("Firewall v2 Service Plugin using Service Driver: %s",
                 default_provider)
</pre>
from neutron_fwaas.common import exceptions
from neutron_fwaas.common import fwaas_constants
from neutron_fwaas.extensions.firewall_v2 import Firewallv2PluginBase
from neutron_fwaas.services.firewall.service_drivers import driver_api
from neutron_fwaas.services.logapi.agents.drivers.iptables \
    import driver as logging_driver
LOG = logging.getLogger(__name__)
@registry.has_registry_receivers
class FirewallPluginV2(Firewallv2PluginBase):
    """Firewall v2 Neutron service plugin class"""
    supported_extension_aliases = [firewall_v2.ALIAS]
    path_prefix = firewall_v2.API_PREFIX
    def __init__(self):
        super(FirewallPluginV2, self).__init__()
        """Do the initialization for the firewall service plugin here."""
        # Initialize the Firewall v2 service plugin
        service_type_manager = st_db.ServiceTypeManager.get_instance()
        service_type_manager.add_provider_configuration(
            fwaas_constants.FIREWALL_V2,
            provider_conf.ProviderConfiguration('neutron_fwaas'))
        # Load the default driver
        drivers, default_provider = service_base.load_drivers(
            fwaas_constants.FIREWALL_V2, self)
        LOG.info("Firewall v2 Service Plugin using Service Driver: %s",
                 default_provider)
Comments