Sunday, July 25, 2010

Integrating SyntaxHighlighter on blogger.com

Today I integrated SyntaxHighlighter (http://alexgorbatchev.com/SyntaxHighlighter) on my blog. Adding source code to a blog works like a charm by embedding it in <pre></pre> tags.

<pre class="brush: java">
-- insert code here ---
</pre>

In order for SyntaxHighlighter to work, you need to to the following in your blogger.com account

Just after the <head> tag:
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shAutoloader.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>

Just before the </body> tag :
<script type='text/javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
</script>


One minor issue encountered with XML rendering. This doesn't seem to work properly unless replacing all left brackets with <
So currently I'm stuck with copying the code to an editor, executing a search "<" and replace with &lt; XML Snippet with left handed brackets included


org.hibernate.ejb.HibernatePersistence
be.ecs.validation.entities.Person
be.ecs.validation.entities.City
be.ecs.validation.entities.Country











XML Snippet with left handed brackets replaced with &lt;

<persistence>
<persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>be.ecs.validation.entities.Person</class>
<class>be.ecs.validation.entities.City</class>
<class>be.ecs.validation.entities.Country</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:unit-testing-jpa"/>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value="x"/>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
</properties>
</persistence-unit>
</persistence>

Rest seems to be working fine...

package be.ecs.seamdemo.beans;

import javax.persistence.EntityManager;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

import be.ecs.seamdemo.entities.Category;

@Name("categoryHome")
public class CategoryHome extends EntityHome {

private static final long serialVersionUID = 1729733881106540912L;

@In
EntityManager entityManager;

public EntityManager getEntityManager() {
return entityManager;
}

@Override
public String persist() {
super.persist();
return null;
}
}




2 comments:

  1. Nice syntax... As I thougth, i bet this will be great help to all the blogger out there! Keep posting new useful syntax.

    Heart
    My blog: rampe d'escalier 

    ReplyDelete
  2. This is awesome!
    I haven't tried it, but I am sure this will work fine.
    Can't wait for the results after I apply this codes.

    Eunice from fixation abattant WC 

    ReplyDelete