Code2Html 插件
这个插件使用 jEdit(jedit.org) 的语法引擎来翻译并转换源代码为 HTML 格式的输出, 支持像 jEdit 那么多的 130 多种语法. 请阅读 Code2Html/readme.txt
来获得完整的说明.
安装: 解压缩 Code2Html/CodePluginBin.zip
到你的 jspwiki web 应用安装目录, 然后重启 web 应用的服务器或者重新载入应用.
要安装最新版本, 请同时解压缩Code2Html/CodePluginBinPatch.zip
到你的 jspwiki web 应用安装目录, 不要忘了修改文件 WEB-INF/code2html.properties, 这样才能启用读取服务器本机文件的功能.
更新:
2006-12-08 Code2Html Plugin 1.1 版本
发布新版本的 Code2Html 插件, 感谢 Jürgen Weber 和 Venk 热情测试并且给与我一些很棒的想法.
这个版本支持读取附件(像内置的 Image 插件一样)和本地文件系统(当然, 这是个安全隐患, 不过我用一个配置文件来让管理员决定是否允许插件来访问本地的文件系统).
源代码是:Code2Html/Code.java
2006-12-05
Code2Html/CodePluginBinPatch.zip
是一个包含了完整包名的类文件的版本. 我已经编译了这个版本, 解压缩这个补丁文件到 wiki 根目录. 完整的类名是 beansoft.jspwiki.plugins.Code.
修改文件 jspwiki.properties, 从下面的行开始:
jspwiki.plugin.searchPath = beansoft.jspwiki.plugins,...other packages
或者使用完整的类名:
[{beansoft.jspwiki.plugins.Code ...
}]
怎么更改输出的代码的颜色和格式? 修改 CSS 文件 css/syntax.css 就可以了.
用法:
[{Code lang='语言类型' src='附件文件地址' version='附件文件版本'
file = '本机文件路径(服务器端的)' encoding='UTF-8,等等' showsrc='true/false'
<回车或者换行, 放一个空行>
--- 源码正文, 可以包含多行的代码. ---
}]
参数:
- lang(可选):语言类型, 默认值是 java, 可用的值为:
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
- 源代码 (可选), 放在插件标签的正文中(所有的 JSPWiki 插件支持一个特殊的参数, 名字叫 '_body'), 第一行必须是空行.
- src(可选):wiki 上的附件的地址, 可以包含, 也可以不包含完整的页面路径. 例如: Code2Html/Code.java 或者 Code.java
- version(可选):只有当使用 src 参数的时候这个参数才有用, 这个指定附件文件的版本, 默认是最新值, 例如: 0,1
- file(可选):想要读取的本地文件系统的文件路径, 例如: c:
\My.java 或者 c:/My.java, 默认情况下这个功能是禁用的
- encoding(可选):附件或者文件内容的编码, 默认和服务器的文件系统编码一致
- showsrc(可选):是否显示附件/文件的源路径, 默认打开, 值为"true"
插件安装下列的顺序(优先级)加载源代码内容: _body > src > file
- 安全问题:
allowReadLocalFile = false 为 allowReadLocalFile = true
用法示例:
[{Code lang=javascript
/** A JavaScript function */
function test() {
var a = "abc";
}
}]
输出的结果为:
更多例子: 读取同一页面的附件: [{Code src='Code.java'}] 读取本地文件系统(服务器端): [{Code file='E:\\OpenSource\\JSPWikiPlugins\\src\\Test.java' showsrc=false}]
联系我(MSN): 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 fileCode2Html/CodePluginBinPatch.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
When it is used in Windows, the follow code get something wrong,
studio.beansoft.syntax.ModeLoader.loadModeCatalog(StringUtil
.getRealFilePath("/modes/catalog"), false);
I think it should be modified like this when in Windows
studio.beansoft.syntax.ModeLoader.loadModeCatalog(StringUtil
.getRealFilePath("\\modes\\catalog"), false);
--AnonymousCoward, 26-Dec-2006
Well, when your tomcat install using the default settings using tye exe setup file on Windows, there will be space chars in your tomcat directory path, such as
Disk Letter:/program files/Apache/Tomcat 5.5
thus I get the file's real path by using getResource(), then convert the URL to a file, finnlay it's got:
c:/program%20files/Apache/Tomcat%205.5
So we can't find the file anymore...I'll fix this bug a little latter. But so far u can only install your tomcat to a path like this:
Disk Letter:/Apache/Tomcat5.5
Remove all spaces in the path, this is also suggested by many Java IDEs such as IDEA/JBuilder, they all said better not install a path with special chars.
--Jacky Liu, 28-Dec-2006
Add new attachment
List of attachments
| Kind | Attachment Name | Size | Version | Date Modified | Author | Change note |
|---|---|---|---|---|---|---|
jar |
jeditsyntax_fix_catalog_space.... | 124.7 kB | 1 | 10-Jun-2008 21:49 | 220.134.27.68 | fix space %20 for modified ModeLoader...(i hope that will be not any offense) |