The Code2Html Plugin
Someone erased this page? Oh there is so many bad boys!
Chinese Instruction Code2Html_zh_CN
This plugin using the jEdit(jedit.org)'s syntax engine to parse source code and rederered it to HTML output,
it supports up to 130 different syntaxts as much as the jEdit supports. See readme.txt
for the fully instruction.
Install: unzip CodePluginBin.zip
to your jspwiki web app install dir and then restart the web app server or reload the app.
For newer version, please also unzip CodePluginBinPatch.zip
to your jspwiki web app install dir, and don't forget the change the WEB-INF/code2html.properties.
Update:
Dec 8 2006 Code2Html Plugin 1.1
We realeased a new version of Code2Html plugin, thanks Jürgen Weber and Venk to testing it and give me some great ideas.
This version supports reading from attachment file(like the core Image plugin) and local file system(while, there is a security issue, but I use a config file to determine whether allow the plugin to access local file system). The source code is here: Code.java
Dec 5 2006
CodePluginBinPatch.zip
is a file contains the plugin file with a package name. I have compiled a packaged version for that, just extract this patch file to the wiki root dir. This class now is beansoft.jspwiki.plugins.Code.
Change the jspwiki.properties file for the property called:
jspwiki.plugin.searchPath = beansoft.jspwiki.plugins,...other packages
or use full class name:
[{beansoft.jspwiki.plugins.Code ...
}]
Wanna change output color format? Just edit the css file css/syntax.css and u'll got it.
Usage:
[{Code lang='language name' src='attachment file src' version='attachment file version'
file = 'file path of local file system(on the server)' encoding='UTF-8,etc' showsrc='true/false'
<CR or LN, just a empty line here>
--- The source code body here, might have multi lines. ---
}]
Parameters:
- lang(optional):language name, default value is java, remember don't use values that not exists in the language list:
java jsp actionscript ada95 antlr apacheconf apdl applescript asp aspect-j assembly-m68k assembly-macro32 assembly-r2000 assembly-parrot assembly-x86 awk b batch bbj bcel beanshell bibtex c chill cil cobol coldfusion c++ c# css cvs-commit d doxygen dsssl embperl erlang eiffel factor forth fortran foxpro freemarker gettext groovy haskell hex html i4gl icon idl inform inno-setup ini interlis io javascript jcl jhtml jmk latex lilypond lisp literate-haskell lotos lua mail makefile maple ml modula3 moin mqsc netrexx nqc nsis2 objective-c objectrexx occam omnimark pascal patch perl php pike pl-sql pl1 pop11 postscript powerdynamo povray prolog progress properties psp ptl pvwave pyrex python rebol redcode relax-ng-compact renderman-rib rd rest rhtml rpm-spec rtf ruby rview s+ s# sas scheme sgml shellscript shtml slate smalltalk sdl/pr smi-mib sqr squidconf svn-commit swig tcl texinfo tex text tpl transact-sql twiki uscript vbscript velocity verilog vhdl xml xsl zpt
- source code (optional), is putting in the body of that Tag(all JSPWiki Plugin supports a special parameter called '_body'), the first line must be an empty line.
- src(optional):the attachment's src on the wiki, might with full path or not, eg: Code2Html/Code.java or Code.java
- version(optional):only in case you use a src, then this will specify the attachment's version, default is latest, eg: 0,1
- file(optional):file path on the local file system you want to read, eg: c:
\My.java or c:/My.java, by default this is not opened
- encoding(optional):the content's encoding of attachment or local file, default to server file system's encoding
- showsrc(optional):whether display the file/attachment's src to the output, default value is "true"
We load the code content in following sequence: _body > src > file
- Security issue:
allowReadLocalFile = false to allowReadLocalFile = true
Eg:
[{Code lang=javascript
/** A JavaScript function */
function test() {
var a = "abc";
}
}]
The result like this:
More egs: Read attachment from same page: [{Code src='Code.java'}] Read local files: [{Code file='E:\\OpenSource\\JSPWikiPlugins\\src\\Test.java' showsrc=false}]
Touch me: beansoftstudio@msn.com
I am getting lots extra spaces in the code output. I have tried with both XML and Java and if a word is highlighted in some way, it also looks like its getting padded. I used the bin dist available here on Tomcat 5.5.20 with JSPWiki 2.4.71
--AnonymousCoward, 08-Nov-2006
I just output the original source code like this:
<link rel='stylesheet' type='text/css' href='css/syntax.css'/><pre><span class=comment>/* comment here</span> </pre>
Also I've tested on v2.4.71, using the default css both under IE and Firefox, it looks same, I think your problem might is:
1. source code include too many tab chars(one tab take 8 spaces);
2. the css template difines the span's padding.
Maybe you can see the css file or might change span output to div by change the source code of studio.beansoft.syntax.sample.HtmlOutputTokenHandler.
--Jacky Liu, 08-Nov-2006
The Code2Html Plugin is great.
What about adding the feature to code2html files in the filesystem or inline attachements like inlining images?
--Jürgen Weber
, 30-Nov-2006
Allowing access to the file system would be a big security risk...
--JanneJalkanen, 30-Nov-2006
Adding the feature to code2html files in the filesystem is really a security risk, esepecially when u put a site on the internet. But inline attachements like inlining images is really a good idea, also i'm cosidering to add line number display switch in the next coming version.
--Jacky Liu, 01-Dec-2006
Of course, it would be a risk to give internet users access to the filesystem.
Still, it would be useful for intranets, e.g. you could access a subversion repository checked out to the filesystem.
So, to address the security concerns:
- filesystem access should be restricted to a given folder and its subfolders
- linking to the filesystem should be restricted to certain user groups
--Jürgen Weber, 01-Dec-2006
What is the full path to the class I need to enter in the jspwiki.properties file for the property called: jspwiki.plugin.searchPath
Currently I have it set to: jspwiki.plugin.searchPath = lu.intrasoft.jspwiki.plugin
Plugin insertion failed: Could not find plugin CodePluginPlugin insertion failed: Could not find plugin CodePlugin
-- Venki, 04-Dec-2006
Hi Venki, the file has no package, so sometimes might be a issue.
Try: 1) reload the web app;
2) recompile the file by move Code.java to beansoft.jspwiki.plugins.Code.java, then add to search path.
I've created a small patch fileCodePluginBinPatch.zip
of this issue, see UPD above. Please test it and send a feedback.
Next version i'll trying to move it to a new package so this issue might be fixed.
--Jacky Liu, 05-Dec-2006
Jacky, thanks very much for implementing the attachment feature, it works like a breeze. Wonder how I got by with plain text source code for so long.
8-) Jürgen
--Jürgen Weber
, 11-Dec-2006
Hi Jacky
I'm using jspwiki 2.4.87
It prints everything as preformatted text?
Looking at the page source it makes sense, i.e. I see this:
<pre><span class=reservedWord></span><br><span class=comment>/*</span><span class=comment>*</span><span class=comment> </span><span class=comment>A</span><span class=comment> </span><span class=comment>JavaScript</span><span class=comment> </span><span class=comment>function</span><span class=comment> </span><span class=comment>*/</span>
<span class=reservedWord>function</span> test() <span class=operator>{</span>
<span class=reservedWord>var</span> a <span class=operator>=</span> <span class=literal>"</span><span class=literal>abc</span><span class=literal>"</span><span class=operator>;</span>
<span class=operator>}</span>
</pre>
Why are there <pre></pre> tags surrounding it?
Can a patch be done, or could you tell me how to fix this
Thanks
--GregP 25th Jan 2007
Yes, it do use pre to keep the original code format, but the span with class name which will display different colors of code.
The output code is like this: <link rel='stylesheet' type='text/css' href='css/syntax.css'/> <pre><span class=reservedWord....>res</span> </pre>
Don't forget to check the css file, without it the code is just displayed as preformatted text.
It should be put at: $tomcat_home/webapps/JSPWiki/css/syntax.css then the app can use it.
Or enter http://localhost
:8080/JSPWiki/css/syntax.css to check the file whether could be accessble.
--Jacky Liu, 26-Jan-2007
--GregP, 16-Feb-2007
FYI, it seems that the Brushed Template, Typography functionality interferes with your plugin
Nice plugin by the way... very useful
Plugin doesn't like it when JSPWiki has spaces in its path. It uses "%20" instead of ' '. I've tracked that down to StringUtil.getRealFilePath and just inserted .replaceAll("%20", " ") after inputURL.getFile(), but there should be a better solution.
--ShadowIce, 01-Mar-2007
Hi,
on my wiki the plugin does not seem to work. i checked the reachability of the syntax.css and the code, but the result for:
[{Code lang=javascript
/** A JavaScript function */
function test() {
var a = "abc";
}
}]
is :
<span class="reservedWord"></span><br><span class="comment">/*</span><span class="comment">*</span><span class="comment"> </span><span class="comment">A</span><span class="comment"> </span><span class="comment">JavaScript</span><span class="comment"> </span><span class="comment">function</span><span class="comment"> </span><span class="comment">*/</span>
<span class="reservedWord">function</span> test() <span class="operator">{</span>
<span class="reservedWord">var</span> a <span class="operator">=</span> <span class="literal">"</span><span class="literal">abc</span><span class="literal">"</span><span class="operator">;</span>
<span class="operator">}</span>
any idea, what could be the problem?
--Lukas Weberruss, 23-Mar-2007
I was trying to solve issue that path have "%20" in the string, so I am thinking to add some code to ModeLoader , just like below :
public static void loadModeCatalog(String path, boolean resource)
{
path=path.replaceAll("%20"," ");
/*some orign code here */
will that help the issue ?
thanks a lot...
--TonyQ
, 10-Jun-2008
Add new attachment
List of attachments
| Kind | Attachment Name | Size | Version | Date Modified | Author | Change note |
|---|---|---|---|---|---|---|
java |
Code.java | 9.9 kB | 1 | 08-Dec-2006 09:18 | Jacky Liu | |
zip |
CodePluginBin.zip | 490.7 kB | 1 | 01-Nov-2006 13:52 | Jacky Liu | The plugin it self |
zip |
CodePluginBinPatch.zip | 8.6 kB | 2 | 08-Dec-2006 09:19 | Jacky Liu | |
zip |
CodePluginSrc.zip | 148.1 kB | 1 | 01-Nov-2006 13:55 | Jacky Liu | The source code |
txt |
readme.txt | 2.0 kB | 1 | 01-Nov-2006 13:56 | Jacky Liu | |
png |
syntaxscreenshoot.png | 1.3 kB | 1 | 01-Nov-2006 13:55 | Jacky Liu |