Simple Java HTML syntax highlighter for XML code
This simple code snippet will generate better looking html for <pre>
elements with XML snippets in them. It may be dirty, but it's simple and effective.
public final String highlight(String source)
{
source = source.replaceAll("<([^>/]*)/>", "<~blue~1ドル~/~/>");
source = source.replaceAll("<([^>]*)>", "<~blue~1ドル~/~>");
source = source.replaceAll("([\\w]+)=\"([^\"]*)\"", "~red~1ドル~/~~black~=\"~/~~green~2ドル~/~~black~\"~/~");
source = source.replaceAll("~([a-z]+)~", "<span style=\"color: 1ドル;\">");
source = source.replace("~/~", "</span>");
return source;
}
Written by Wouter Lievens
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Xml
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#