Javascript 使用ckeditor整理html

Javascript 使用ckeditor整理html,javascript,html,ckeditor,tidy,Javascript,Html,Ckeditor,Tidy,您好,我有一个小问题与ckeditor,基本上我需要使编辑器运行它的html清理命令。 有没有办法做到这一点。 目前,它似乎没有运行后,我键入一些东西到源代码,然后按保存我想它整理html像它在'正常'编辑器视图 有什么想法吗? 谢谢 理查德 下面是一些示例代码 <SCRIPT type=text/javascript src="http://www.johnpricephotography.co.uk/crawler.js"> /* Text and/or Image Crawle

您好,我有一个小问题与ckeditor,基本上我需要使编辑器运行它的html清理命令。 有没有办法做到这一点。 目前,它似乎没有运行后,我键入一些东西到源代码,然后按保存我想它整理html像它在'正常'编辑器视图 有什么想法吗? 谢谢 理查德

下面是一些示例代码

<SCRIPT type=text/javascript src="http://www.johnpricephotography.co.uk/crawler.js">
/* Text and/or Image Crawler Script v1.5 (c)2009-2011 John Davenport Scheuer
   as first seen in http://www.dynamicdrive.com/forums/
   username: jscheuer1 - This Notice Must Remain for Legal Use
   updated: 4/2011 for random order option, more (see below)
*/

</SCRIPT>
<div class="marquee" id="mycrawler2">
    <img alt="Derby wedding photographer - masa restaurant wedding" src="http://johnprice.foliopic.com/images/3539/homepage//226.jpg" style="width: 204px; height: 162px" /> <img alt="Shottle Hall Derby by Nottingham wedding photographer, shottle hall wedding" src="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/large/049_1314978790.jpg" style="width: 204px; height: 162px" /> <img alt="Shottle Hall wedding Derby wedding by Nottingham wedding photographer" src="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/large/13150063462954.jpg" style="width: 204px; height: 162px" /> <img alt="derby conference centre wedding by nottingham wedding photographer" src="http://johnprice.foliopic.com/images/3539/homepage//146_1.jpg" style="width: 250px; height: 162px" /> <img alt="professional wedding photographer john price" src="http://johnprice.foliopic.com/images/3539/homepage//31.jpg" style="width: 181px; height: 162px" /> <img alt="Leicestershire wedding photographer john price" src="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/normal/ian---jo--24-of-62-_1312848448.jpg" style="width: 223px; height: 162px" /> <img alt="Leicestershire wedding photographer john price" src="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/normal/ian---jo--47-of-62-_1312849131.jpg" style="width: 124px; height: 162px" /> <img alt="Derby river lights holiday inn wedding by derby wedding photographer john price" src="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/normal/112_1314726892.jpg" style="width: 164px; height: 162px" /> <img alt="alvaston park wedding from derby conference centre wedding" src="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/normal/163_1311890753.jpg" style="width: 220px; height: 162px" /> <img alt="London uk wedding photographer" src="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/normal/flashmo-800x450-30_1311894940.jpg" style="width: 215px; height: 162px" /> <img alt="London uk wedding photographer" src="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/normal/flashmo-800x450-04_1311894907.jpg" style="width: 212px; height: 162px" /></div>
<div class="marquee">
    &nbsp;</div>
<h1 align="center">
    <font face="Times New Roman, Times, serif" size="4"><b><font size="5">By Nottingham Wedding Photographer - John Price, </font></b></font><br />
    <span style="color: #a9a9a9"><font face="Times New Roman, Times, serif" size="4"><b><font size="5">&#39;Give me a wedding and I will give you memories&#39;</font></b></font></span></h1>
<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 800px">
    <tbody>
        <tr>
            <td>
                <p>
                    <br />
                    <span style="font-size: 14px"><font face="Times New Roman, Times, serif"><span style="color: #000000">Welcome to the&nbsp;website of Nottingham wedding photographer John Price. </span><span style="color: #000000">If you are browsing my website, the chances are that you already are or have recently become engaged. Congratulations. You are now both embarking on an exciting journey together and never before will you have so many choices to make, not least choosing a wedding photographer in nottingham or a wedding photographer in Derby or Leicester and beyond.&nbsp;</span></font></span></p>
            </td>
        </tr>
    </tbody>
</table>
<div>
    &nbsp;</div>
<SCRIPT type=text/javascript>
marqueeInit({
    uniqueid: 'mycrawler2',
    style: {
        'padding': '2px',
        'width': '840px',
        'height': '160px'
    },
    inc: 10, //speed - pixel increment for each iteration of this marquee's movement
    mouse: 'cursor driven', //mouseover behavior ('pause' 'cursor driven' or false)
    moveatleast: 1,
noAddedSpace: false,
    neutral: 106,
    savedirection: true,
    random: true

});
</SCRIPT><div>
    &nbsp;</div>
<p>
    <span style="font-size: 16px"><span style="font-family: arial, helvetica, sans-serif">&nbsp;</span></span></p>
<p>
    &nbsp;</p>
<table border="0" cellpadding="1" cellspacing="1" style="width: 800px">
    <tbody>
        <tr>
            <td>
                <p>
                    <strong><span style="font-size: 18px"><span style="font-family: arial, helvetica, sans-serif"><strong><span style="font-size: 18px"><span style="font-family: arial, helvetica, sans-serif">Nottingham wedding photographer - John Price<br />
                    Receives wedding photographer recommedation by Insight Magazine. </span></span></strong></span></span></strong></p>
                <p style="text-align: center">
                    <strong><span style="font-size: 18px"><span style="font-family: arial, helvetica, sans-serif">&nbsp;</span></span></strong></p>
                <p>
                    <strong><span style="font-size: 18px"><span style="font-family: arial, helvetica, sans-serif"><span style="font-size: 12px"><span style="font-family: arial, helvetica, sans-serif">October 2011 edition of the Insight Magazine features a full page recommended article on the wedding photography services that I provide. </span></span></span></span></strong></p>
                <p>
                    &nbsp;</p>
                <p>
                    <span style="font-size: 12px"><span style="font-family: arial, helvetica, sans-serif">This is also a privilege for the beautiful bride and grooms which also feature in this article. The photos was all taken from real weddings that I photographed during 2011</span></span></p>
                <p>
                    &nbsp;</p>
                <p>
                    <span style="font-size: 12px"><span style="font-family: arial, helvetica, sans-serif">A big thank you to the couples featured.</span></span></p>
                <p>
                    <span style="font-size: 12px"><span style="font-family: arial, helvetica, sans-serif">Wayne&nbsp;&amp; Katey was married at the Derby Riverlights Holiday Inn, </span></span></p>
                <p>
                    <span style="font-size: 12px"><span style="font-family: arial, helvetica, sans-serif">Ian &amp; Jo were had an amazing wedding at&nbsp;Shottle Hall, Derby..&nbsp; </span></span></p>
                <p>
                    <span style="font-size: 12px"><span style="font-family: arial, helvetica, sans-serif">James &amp; Kerry-Ann was married at the Derby Conference Centre.</span></span></p>
                <p>
                    &nbsp;</p>
                <p>
                    &nbsp;</p>
                <p>
                    <span style="font-size: 12px"><span style="font-family: arial, helvetica, sans-serif">You can view a pdf copy of this interview <a href="http://www.johnpricephotography.co.uk/Nottingham Wedding Photographer.pdf"><strong><span style="color: #0000ff"><span style="font-size: 14px">Here</span></span></strong></a>.or see an image <strong><a href="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/large/1317302692.jpg"><span style="color: #0000ff"><span style="font-size: 14px">Here</span></span></a></strong></span></span></p>
            </td>
            <td style="text-align: center">
                <img alt="Nottingham Wedding Photographer Recommended By Insight Magazine" src="http://www.nottinghamweddingphotography.co.uk/images/sites/3539/gallery/normal/1317297874.png" style="width: 264px; height: 187px" /></td>
        </tr>
    </tbody>
</table>
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
<p style="text-align: center">
    &nbsp;</p>
<p>
    <span style="font-size: 12px"><span style="font-family: arial, helvetica, sans-serif">Wedding photographer in Nottingham, Wedding photographer in Derby, Wedding photographer in leicester.</span></span></p>
<p>
    <font face="Times New Roman, Times, serif"><font color="#666666"><font color="#666666">John Price is a Nottingham NG based wedding photographer who enjoys capturing that special moment that you know you can look back on time and time again. As a Nottingham wedding photographer, I make no distinction between a Church or Civil Ceremony, Registry Office or Civil Partnerships. Every wedding commands the very best.<span style="display: none">&nbsp;</span></font></font></font></p>
<p>
    <font face="Times New Roman, Times, serif"><font color="#666666">Nottingham Wedding Photography, Nottingham Boudoir Photography, Nottingham Portrait Photography, Nottingham Trash The Dress Photography Covering not just Nottingham, Mansfield, Derby, Leicester, Lincolnshire, Peterborough but the whole of the UK</font></font>&nbsp;<span style="display: none">&nbsp;<span style="display: none">&nbsp;</span></span></p>
<p>
    &nbsp;</p>
<p>
    &nbsp;&nbsp;</p>
<p>
    <a href="http://www.nottinghamweddingphotography.co.uk/article/shottle-hall-wedding-photos-of-ian---jo-1963">Shottle Hall Wedding Photos by Derby Wedding Phototographer John Price&nbsp;Photography at shottle hall&nbsp;&nbsp; </a></p>
<p>
    <a href="http://www.nottinghamweddingphotography.co.uk/article/the-wedding-of-james---lisa-at-rufford-abbey-country-park-2144">Rufford Abbey Wedding Photos by Nottingham Wedding Phototographer Nottingham Rufford Abbey Country Park.</a></p>
<p>
    <a href="http://www.nottinghamweddingphotography.co.uk/article/masa-restaurant-wedding--the-old-chapel--mark---anna-1915">Masa Restaurant Wedding photos Derby wedding photography at Massa Restaurant.</a></p>
<p>
    <a href="http://www.nottinghamweddingphotography.co.uk/article/the-derby-conference-centre-wedding---james---kerry-ann-1911">The Derby Conference Centre Wedding photos by Derby wedding photographer John Price Photography</a></p>
<p>
    <a href="http://www.nottinghamweddingphotography.co.uk/article/the-wedding-of-craig---sarah-at-the-nottingham-council-house-1906">Nottingham Council House Wedding Photos Photographer</a></p>
<p>
    <a href="http://www.nottinghamweddingphotography.co.uk/page/nottingham-boudoir-photographer-1949">Nottingham Boudoir, Derby Boudoir, Leicester Boudoir Photographer</a></p>

/*文本和/或图像爬虫脚本v1.5(c)2009-2011 John Davenport Scheuer
正如第一次看到的那样http://www.dynamicdrive.com/forums/
用户名:jscheuer1-此通知必须保留以供合法使用
更新日期:2011年4月,随机订单选项,更多(见下文)
*/
诺丁汉婚礼摄影师约翰·普莱斯,
'给我一个婚礼,我会给你回忆';
欢迎访问诺丁汉婚礼摄影师约翰·普莱斯的网站。如果你正在浏览我的网站,很可能你已经或者最近已经订婚了。祝贺你们现在都在一起踏上一段激动人心的旅程,你们以前从未有过如此多的选择,尤其是在诺丁汉选择婚礼摄影师,在德比或莱斯特选择婚礼摄影师

马奎因特({ 唯一标识:“mycrawler2”, 风格:{ “padding”:“2px”, “宽度”:“840px”, “高度”:“160px” }, inc:10,//速度-此字幕移动每次迭代的像素增量 鼠标:'光标驱动',//鼠标悬停行为('暂停''光标驱动'或false) 至少:1,, noAddedSpace:false, 中立:106, 方向:对, 随机:对 });

诺丁汉婚礼摄影师约翰·普莱斯 获得《洞察》杂志推荐的婚礼摄影师

2011年10月版的《洞察》杂志刊登了一篇关于我提供的婚礼摄影服务的整版推荐文章

这也是美丽的新娘和新郎的特权,这也是本文的特色。这些照片都是我在2011年拍摄的真实婚礼的照片

非常感谢这对夫妇

韦恩律师事务所;凯蒂在德比河光假日酒店结婚

伊恩,;Jo在德比郡的Shottle Hall举行了一场精彩的婚礼

詹姆士;克里·安在德比会议中心结婚

您可以查看此访谈的pdf副本。或者查看图像

诺丁汉的婚礼摄影师,德比的婚礼摄影师,莱斯特的婚礼摄影师

约翰·普莱斯(John Price)是诺丁汉州(Nottingham NG)的一位婚礼摄影师,他喜欢捕捉那个你们知道可以一次又一次回顾的特殊时刻。作为一名诺丁汉婚礼摄影师,我不区分教堂或民间仪式、登记处或民间伙伴关系。每一场婚礼都是最好的

诺丁汉婚礼摄影、诺丁汉闺房摄影、诺丁汉肖像摄影、诺丁汉垃圾服饰摄影不仅涵盖诺丁汉、曼斯菲尔德、德比、莱斯特、林肯郡、彼得伯勒,还涵盖整个英国

这是如何工作的,但我想做的是修复html,如果有问题。 基本上,这个html被保存到一个隐藏的元素中,然后当用户单击save时,所有内容都被整理出来。 老实说,现在考虑一下,这可能不是处理这个问题的最佳方式,但目前只是试图解决这个问题。
Richard

请在保存之前尝试执行以下操作(仅用于使用本机数据处理器处理数据):

当然,如果你经常这样做的话,它的性能会受到影响

更新: 对不起,我有点误导了你,但是在你提到“{cke_protected}”之后,我记得了。因此,dataProcessor的“toHtml”方法做了以下工作:修复损坏的html并将受保护的元素(脚本、flash)包装到特殊的代码结构中,以禁止通过wysiwyg模式进行编辑,但当相同的html应在源代码模式下显示时,编辑器使用“toDataFormat”数据处理器删除所有与ckeditor相关的代码构造的方法。因此,请参阅上面我的更新

更新2:
新的解决方案适用于的3.6.2和3.5.3版本。

我认为您只需要在保存之前切换到“普通”编辑器视图。是的,我知道,但我们谈论的是用户,您无法控制所有用户。如果你还有其他想法,那就太好了。谢谢你的帮助。你是使用工具栏上的“保存”按钮还是自己的?我想在保存之前模拟点击“源代码”按钮…我使用自定义按钮,我会考虑模拟点击源代码,看看我是否可以做到这一点-谢谢,我还有一个想法,就是将代码复制到临时显示none div和一些浏览器中(IE7,别担心,我也讨厌它)
    var yourEditor = CKEDITOR.instances.yourEditor;
    // retrieve current data from editor and process it with its dataprocessor
    var formattedDataForWysiWyg = yourEditor.dataProcessor.toHtml(yourEditor.getData());
    // "decode" content processed by ckeditor
    var sourceData = yourEditor.dataProcessor.toDataFormat(formattedDataForWysiWyg);
    // set formatted data back
    yourEditor.setData(sourceData);