- 浏览: 2585955 次
- 性别:
- 来自: 小胖儿的大城
最新评论
-
ni4wangba0:
ni4wangba0 写道亲测,算法有问题。对不起,其实是我自 ...
谈谈"求线段交点"的几种算法(js实现,完整版) -
ni4wangba0:
亲测,算法有问题。
谈谈"求线段交点"的几种算法(js实现,完整版) -
kers007:
苹果不让Webapp 在appstore 里发布,我不知道对 ...
苹果真的要在 AppStore 里封杀 WebApp 吗? -
striveandlive:
fins = js大牛
[原创]GT-Template, 一个超轻量级的js模板工具. -
AlwaysYang:
基础扎实的才能行走天下。
关于body的"大小"在ie和ff下的一些基础知识
\n');
}
该函数实现的功能比较简单 效果也不是很好.
我做了一个增强的版本, (见后 )
效果也不是很完美 主要是解决了 多层嵌套引用的问题,
代码写的不是很好 而且没有解决换行弄丢的bug.(现在quote_comment 也有该问题)
唉 郁闷啊. 这个很难解决, 除非对字符串进行复杂的查找替换等工作.
(但是肯定解决, 毕竟这个引用功能无论多复杂 都没有语法着色来得复杂).
最好的方法我觉得需要从两方面下手 :
1是js方面写的再强大些
2是后台到前台输出的html代码结构再重新规划一下.
不过这本身就不是什么重要功能 无所谓了.
======================================
我写的这个代码并不好 还有很大优化和完善的余地 大家一起来吧
就当做个游戏.
其实 要想完美实现这个js端的引用 还是蛮难的哦 有挑战
==============================
代码很长 但是其中一些是公共的功能函数, 可以提取出去的.
该函数实现的功能比较简单 效果也不是很好.
我做了一个增强的版本, (见后 )
效果也不是很完美 主要是解决了 多层嵌套引用的问题,
代码写的不是很好 而且没有解决换行弄丢的bug.(现在quote_comment 也有该问题)
唉 郁闷啊. 这个很难解决, 除非对字符串进行复杂的查找替换等工作.
(但是肯定解决, 毕竟这个引用功能无论多复杂 都没有语法着色来得复杂).
最好的方法我觉得需要从两方面下手 :
1是js方面写的再强大些
2是后台到前台输出的html代码结构再重新规划一下.
不过这本身就不是什么重要功能 无所谓了.
======================================
我写的这个代码并不好 还有很大优化和完善的余地 大家一起来吧
就当做个游戏.
其实 要想完美实现这个js端的引用 还是蛮难的哦 有挑战
==============================
代码很长 但是其中一些是公共的功能函数, 可以提取出去的.
function quote_comment(link) { var BR='\r\n'; var maxDepth=20,depth=0; function removeNode(el){ if (!el) { return; } var orphanDiv= $('_orphan_div'); if (!orphanDiv) { orphanDiv=document.createElement('div'); orphanDiv.id='_orphan_div'; orphanDiv.style.display='none'; } orphanDiv.appendChild(el); orphanDiv.innerHTML = ''; } function getText(el) { return el.innerHTML.stripTags(); //return el.textContent || el.innerText; } function createQuote(quoteBody){ var children=quoteBody.childElements(); for (var i=0,child;child=children[i];i++) { if (child.className=='quote_title') { var title=getText(child).strip(); if (!title||title=="引用") { child.innerHTML= BR +'引用'; }else{ title= title.endsWith("写道")?title.substring(0,title.length-2):title; child.innerHTML= BR +''+ title.strip() +' 写道'; } }else if (child.className=='quote_div') { var subQuoteBody = child.select('[class="quote_div"]'); var quoteBodyText=null; if (subQuoteBody && subQuoteBody.length>0 && depth++<maxDepth ) { quoteBodyText = createQuote(child); }else{ quoteBodyText= getText(child); } child.innerHTML=quoteBodyText+''+BR; }else{ // do nothing } } return getText(quoteBody); } var quoteUser = getText( $(link).previous(0) ); var commentBody = $(link).up().next().cloneNode(true); var quote=[ ''+quoteUser+' 写道', createQuote(commentBody), ''+BR ] var editorArea=editor.bbcode_editor.textarea; editorArea.insertAfterSelection(quote.join(BR)); removeNode(commentBody); }评论
3 楼 QuakeWang 2009-01-12汗,通过回帖发现一个bbcode到html转换的bug,被code包含起来的bbcode也被转换了,赶紧去修改2 楼 fins 2009-01-12代码贴到这里来就乱了
这个要是想用JS做个完美的确实不简单啊
而且 我觉得"完美"应该做不到
bbcode-->html的时候 有些东西会丢失 , 或者是多个不同的东西转换成了一种html
有时候是不可逆的吧
除非在 bbcode-->html 时 就像语法着色时一样, 用很多的DIV SPAN(配合class)对很多东西都做出标记1 楼 QuakeWang 2009-01-12这个功能是为了提供一个简单的引用回复,要用js完美解决相当于实现一个HTML到BBCode完全转换,我们后台的ruby代码实现过一次(用正则表达式的),移植到js倒是很简单。
在贴上我的实现之前,先贴单元测试的代码,你可以试试看用js来通过所有的单元测试:require 'test/unit' require 'bbcodeize_helper' class DeBbcodeizerTest < Test::Unit::TestCase include BBCodeizeHelper def test_bold assert_equal( "I am [b]really[/b] happy!", debbcodeize("I am <strong>really</strong> happy!")) end def test_italic assert_equal( "Have you read [i]Catcher in the Rye[/i]?", debbcodeize("Have you read <em>Catcher in the Rye</em>?")) end def test_underline assert_equal( "[u]Please note[/u]:", debbcodeize("<u>Please note</u>:")) end def test_email assert_equal( "You can also [email=jd@example.com]contact me by e-mail[/email].", debbcodeize("You can also <a href=\"mailto:jd@example.com\">contact me by e-mail</a>.")) end def test_url assert_equal( "Check out [url=http://www.rubyonrails.com]Ruby on Rails[/url]!", debbcodeize("Check out <a href=\"http://www.rubyonrails.com\">Ruby on Rails</a>!")) assert_equal( "Check out [url=http://www.rubyonrails.com]Ruby on Rails[/url]!", debbcodeize("Check out <a href=\"http://www.rubyonrails.com\" target=\"_blank\">Ruby on Rails</a>!")) end def test_image assert_equal( "[img]http://example.com/example.gif[/img]", debbcodeize("<img src=\"http://example.com/example.gif\" />")) end def test_align assert_equal("[align=center]test[/align]", debbcodeize("<div align=\"center\">test</div>")) end def test_align assert_equal("[align=center]test[/align]", debbcodeize("<div style=\"align: center\">test</div>")) end def test_flash assert_equal("[flash=100,50]a.swf[/flash]",debbcodeize('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100" height="50"><param name="movie" value="a.swf" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="" /><embed src="a.swf" wmode="" quality="high" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="100" height="50"></embed></object>')) assert_equal("[flash=100,50]a.swf[/flash]",debbcodeize("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"100\" height=\"50\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\">\n<param name=\"src\" value=\"a.swf\" /><embed type=\"application/x-shockwave-flash\" width=\"100\" height=\"50\" src=\"a.swf\"></embed>\n</object>")) end def test_size assert_equal( "[size=32]Big Text[/size]", debbcodeize("<span style=\"font-size: 32\">Big Text</span>")) end def test_color assert_equal( "[color=red]Red Text[/color]", debbcodeize("<span style=\"color: red\">Red Text</span>")) end def test_dequote assert_equal( "[quote=\"name\"]test\nquote", debbcodeize("<div class=\"quote_title\">name 写道</div><div class=\"quote_div\">test\nquote</div>") ) assert_equal( "[quote=\"name\"]test\nquote", debbcodeize("<div class=\"quote_title\">name 写道</div>\n<div class=\"quote_div\">test\nquote</div>") ) assert_equal( "[quote=\"name\"]test\nquotetest\n", debbcodeize("<div class=\"quote_title\">name 写道</div><div class=\"quote_div\">test\nquote</div><p>test</p>") ) assert_equal( "引用test\nquote", debbcodeize("<div class=\"quote_title\">引用</div><div class=\"quote_div\">test\nquote</div>") ) assert_equal( "引用test\nquote", debbcodeize("<div class=\"quote_title\">引用</div>\n<div class=\"quote_div\">test\nquote</div>") ) assert_equal( "引用test\nquotetest引用test\nquote", debbcodeize("<div class=\"quote_title\">引用</div><div class=\"quote_div\">test\nquote</div>test<div class=\"quote_title\">引用</div><div class=\"quote_div\">test\nquote</div>") ) end def test_nested_quote assert_equal( '1 写道', debbcodeize(bbcodeize('1 写道a1 写道')) ) end end1 写道a发表评论
相关推荐
JE695R3HC2L_LD-S18Y15A_20210617_202110266789.pdf
三菱伺服放大器编码手册,应用于mr-je伺服编程使用
Java开发图文混排的编辑器
MR-JE-B技术资料集manual_2015210173530294.pdf
AMD_WISTRON_JE40-SB_宏基4560G(A70) AMD_WISTRON_JE40-SB_宏基4560G(A70)
资源分类:Python库 所属语言:Python 资源全名:je_auto_control-0.0.76-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:je_api_testka_dev-0.0.21-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
可用于UnityVR开发,3D游戏开发,高清天空盒子Skybox素材,游戏环境背景素材,无水印。 让你身临其境的天空盒子,各类题材丰富,都是辛苦搜罗所得的高清exr格式,可以直接用于Unity开发,特别是VR游戏的开发。...
中英文分词工具,可以扩展词典,使用比较方便
GL_JE_BATCHES GL_ARCHIVE_BATCHES GL_JE_HEADERS GL_JE_LINES
JE中文分词压缩包,应用于网络搜索中的中文分词过程中
MR-JE-A伺服定位模式篇MR-JE-_A伺服放大器技术资料集(定位模式篇)
jemalloc库是用来替代系统自带的malloc和...extern "C" __declspec(dllimport) void* je_malloc(size_t size); extern "C" __declspec(dllimport) void je_free(void *ptr); #pragma comment (lib, "jemalloc.lib")
MR-JE-_C 技术资料集
在java环境下开发的分词源代码,本代码可以通过lucene,nutch调用,实现对中文的分词
著名的嵌入式内存数据库Berkeley DB je3.3版,轻量级,快捷好用。
墨菲线算法Matlab 函数murphy_line_draw.m实现墨菲的线算法 [1] 来绘制任意粗细的线。 它是 Bresenham 线算法的修改版本 [2]。 更多信息可以在上。 此实现适用于笛卡尔坐标系的所有八分圆。演示Matlab 脚本demo.m...
包含翻译后的API文档:je-5.0.73-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:com.sleepycat:je:5.0.73; 标签:sleepycat、je、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用...