首页 > 其他 > 详细

xheditor+prettify实现代码高亮

时间:2014-02-09 15:31:53      阅读:347      评论:0      收藏:0      [点我收藏+]

网上的教程很多,主要遗漏了三点。

1、导入ubb.min.js   <script type="text/javascript" src="js/ubb.min.js"></script>

2、在textarea中,不要写class="xheditor"了,如果写了的话,就不会出现自己添加的新按钮。

3、pageInit()函数要这样写:


<script type="text/javascript">  
$(pageInit);
function pageInit()
{
	var plugins={
		Code:{c:‘btnCode‘,t:‘插入代码‘,h:1,e:function(){
			var _this=this;
			var htmlCode=‘<div><select id="xheCodeType"><option value="html">HTML/XML</option><option value="js">Javascript</option><option value="css">CSS</option><option value="php">PHP</option><option value="java">Java</option><option value="py">Python</option><option value="pl">Perl</option><option value="rb">Ruby</option><option value="cs">C#</option><option value="c">C++/C</option><option value="vb">VB/ASP</option><option value="">其它</option></select></div><div><textarea id="xheCodeValue" wrap="soft" spellcheck="false" style="width:300px;height:100px;" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>‘;			var jCode=$(htmlCode),jType=$(‘#xheCodeType‘,jCode),jValue=$(‘#xheCodeValue‘,jCode),jSave=$(‘#xheSave‘,jCode);
			jSave.click(function(){
				_this.loadBookmark();
				_this.pasteText(‘[code=‘+jType.val()+‘]\r\n‘+‘<pre class="prettyprint lang-‘+jType.val()+‘">‘+jValue.val()+‘</pre>‘+‘\r\n[/code]‘);
				_this.hidePanel();
				return false;	
			});
			_this.saveBookmark();
			_this.showDialog(jCode);
		}}			
	};
	$(‘#newContent‘).xheditor({plugins:plugins,tools:‘full‘,showBlocktag:false,forcePtag:false,beforeSetSource:ubb2html,beforeGetSource:html2ubb,shortcuts:{‘ctrl+enter‘:submitForm}});
	$(‘#replyContent‘).xheditor({plugins:plugins,tools:‘full‘,showBlocktag:false,forcePtag:false,beforeSetSource:ubb2html,beforeGetSource:html2ubb,shortcuts:{‘ctrl+enter‘:submitForm}});
}
function submitForm(){$(‘#solution‘).submit();}

</script> 


这样就可以了。

xheditor+prettify实现代码高亮

原文:http://blog.csdn.net/exceptional_derek/article/details/18979535

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!