te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - line break and paragraph has doubled itself every time I save the document ckeditor adding extra spaces paragraph a
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - line break and paragraph has doubled itself every time I save the document ckeditor adding extra spaces paragraph a

programmeradmin3浏览0评论

Hi I have implemented the ckeditor in my asp and vb web application. After a lot of struggle its working fine.

But its adding a lots of line breaks and paragraphs (specially copying and pasting from word file ) after every save. The editor is placing extra <br/> in side the html after submission of the page.

If there is one line break its adding 4 line breaks. if I submit

xxx<br>yyy 

after submission it is being

xxx<br/><br/><br/><br/<br/><br/>yyy

To clarify when copying and pasting for the first time we do NOT see this behaviour, the problem is only seen on subsequent edits/saves.

Please advice me how i can handle that. So that it does not adds extra line breaks and paragraph after saving the form.

Here are the steps which I have followed to implement ckeditor.

1. Downloaded the ckeditor from the link . I am using the full package

2. Copied the whole folder under project folder.

3. In the master page added the following lines to add reference of ckeditor

   <script src="/ckeditor/ckeditor.js" type="text/javascript"></script>
   <script src="/ckeditor/adapters/jquery.js" type="text/javascript"></script>
   <script src="/ckeditor/ckeditor_custom.js" type="text/javascript"></script>

4. Changed the class for the specific textarea

<textarea runat="server" id="txtDescription" name="txtDescription" class="ckeditor" style="width: 98%; height: 250px;"></textarea>

5. Added following javascript function at the bottom of the content page

$('#' + '<%= btnSave.ClientID%>').mousedown(function () {
    for (var i in CKEDITOR.instances) {
        CKEDITOR.instances[i].updateElement();
    }
});

Thats it. nothing has changed in the code file

here the btn.save is the button which submits the data

To describe the problem clearly I am providing the case situation below.

Suppose I want to copy padte the follwing text from a word file.

Working Log • 1st Week : Introduction o Discovered the location of the website o Started familiarise with the websites and portal.

After pasting it into ck editor the html source of this is like following

<p><strong>Working Log</strong></p>
<ol style="list-style-type:lower-roman">
   <li>1<sup>st</sup> Week : Introduction
    <ul style="list-style-type:circle">
        <li>Discovered the location of the website</li>
        <li>Started familiarise with the websites and portal.</li>
    </ul>
   </li>
</ol>

But when I save the form and open it again the source code bees like this

        <p><strong>Working Log</strong></p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <ol style="list-style-type:lower-roman"><br />
        <li>1<sup>st</sup> Week : Introduction<br />
          &nbsp;
        <ul style="list-style-type:circle"><br />
            <li>Discovered the location of the website</li>
            <br />
            <li>Started familiarise with the websites and portal.</li>
           <br />
           <br />
           &nbsp;
        </ul>
        </li>
           <br />
         <br />
        &nbsp;
         </ol>
        <p>&nbsp;</p>
        <p>&nbsp;</p>

And the line break and paragraphs doubles and triples after each submission of the form.

Driving me mad. Please help how can i handle the situation.

----------------- Why My problem is different from the question asked in this link Removing unwanted newline characters when adding <p> in CKEditor -----------------

The question asked in that link does not explain all the detail. in my question i have explained clearly when I can see this problem. the person asked the question in the above mentioned link if he has copied and text from a word document or has he used html tags to format the text in the editor. I have mentioned every detail so that it bees easy for the people who will answer the question.

The problems was also different. The problem in the mentioned link was only concerned with the <p> replaced by indent. Whereas in my case every line break <br> and paragraph <p> has doubled itself every time I save the document . I was copying text from word document and mentioned it in my question. I did not find any detail in the question in above mentioned link.

Situations are different for different coder. the person asked that question did not explain what is his coding environment. I have implemented CKEditor in Vb.Net and ASP based web app and I mentioned that in my question. I also mentioned every steps how I have installed the editor in the app. But the person who asked the question in the link did not included any details. Also trying the solution given in his question did not solve my problem. So I included all the details in my question. And my solution is also different.

The answer given in the mentioned link did not solve my problem. i had to set every rules as false to get rid of the problem. Whereas in the answer of the above mentioned link two of the rules were set as True. Also the function CKEDITOR.editorConfig = function (config) { was not mentioned in the answer to the question mentioned in the link. Hence the question given on that link was not helpful for me.

Hi I have implemented the ckeditor in my asp and vb web application. After a lot of struggle its working fine.

But its adding a lots of line breaks and paragraphs (specially copying and pasting from word file ) after every save. The editor is placing extra <br/> in side the html after submission of the page.

If there is one line break its adding 4 line breaks. if I submit

xxx<br>yyy 

after submission it is being

xxx<br/><br/><br/><br/<br/><br/>yyy

To clarify when copying and pasting for the first time we do NOT see this behaviour, the problem is only seen on subsequent edits/saves.

Please advice me how i can handle that. So that it does not adds extra line breaks and paragraph after saving the form.

Here are the steps which I have followed to implement ckeditor.

1. Downloaded the ckeditor from the link http://ckeditor./download. I am using the full package

2. Copied the whole folder under project folder.

3. In the master page added the following lines to add reference of ckeditor

   <script src="/ckeditor/ckeditor.js" type="text/javascript"></script>
   <script src="/ckeditor/adapters/jquery.js" type="text/javascript"></script>
   <script src="/ckeditor/ckeditor_custom.js" type="text/javascript"></script>

4. Changed the class for the specific textarea

<textarea runat="server" id="txtDescription" name="txtDescription" class="ckeditor" style="width: 98%; height: 250px;"></textarea>

5. Added following javascript function at the bottom of the content page

$('#' + '<%= btnSave.ClientID%>').mousedown(function () {
    for (var i in CKEDITOR.instances) {
        CKEDITOR.instances[i].updateElement();
    }
});

Thats it. nothing has changed in the code file

here the btn.save is the button which submits the data

To describe the problem clearly I am providing the case situation below.

Suppose I want to copy padte the follwing text from a word file.

Working Log • 1st Week : Introduction o Discovered the location of the website o Started familiarise with the websites and portal.

After pasting it into ck editor the html source of this is like following

<p><strong>Working Log</strong></p>
<ol style="list-style-type:lower-roman">
   <li>1<sup>st</sup> Week : Introduction
    <ul style="list-style-type:circle">
        <li>Discovered the location of the website</li>
        <li>Started familiarise with the websites and portal.</li>
    </ul>
   </li>
</ol>

But when I save the form and open it again the source code bees like this

        <p><strong>Working Log</strong></p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <ol style="list-style-type:lower-roman"><br />
        <li>1<sup>st</sup> Week : Introduction<br />
          &nbsp;
        <ul style="list-style-type:circle"><br />
            <li>Discovered the location of the website</li>
            <br />
            <li>Started familiarise with the websites and portal.</li>
           <br />
           <br />
           &nbsp;
        </ul>
        </li>
           <br />
         <br />
        &nbsp;
         </ol>
        <p>&nbsp;</p>
        <p>&nbsp;</p>

And the line break and paragraphs doubles and triples after each submission of the form.

Driving me mad. Please help how can i handle the situation.

----------------- Why My problem is different from the question asked in this link Removing unwanted newline characters when adding <p> in CKEditor -----------------

The question asked in that link does not explain all the detail. in my question i have explained clearly when I can see this problem. the person asked the question in the above mentioned link if he has copied and text from a word document or has he used html tags to format the text in the editor. I have mentioned every detail so that it bees easy for the people who will answer the question.

The problems was also different. The problem in the mentioned link was only concerned with the <p> replaced by indent. Whereas in my case every line break <br> and paragraph <p> has doubled itself every time I save the document . I was copying text from word document and mentioned it in my question. I did not find any detail in the question in above mentioned link.

Situations are different for different coder. the person asked that question did not explain what is his coding environment. I have implemented CKEditor in Vb.Net and ASP based web app and I mentioned that in my question. I also mentioned every steps how I have installed the editor in the app. But the person who asked the question in the link did not included any details. Also trying the solution given in his question did not solve my problem. So I included all the details in my question. And my solution is also different.

The answer given in the mentioned link did not solve my problem. i had to set every rules as false to get rid of the problem. Whereas in the answer of the above mentioned link two of the rules were set as True. Also the function CKEDITOR.editorConfig = function (config) { was not mentioned in the answer to the question mentioned in the link. Hence the question given on that link was not helpful for me.

Share Improve this question edited May 23, 2017 at 11:46 CommunityBot 11 silver badge asked Jun 18, 2014 at 10:45 BashabiBashabi 7062 gold badges14 silver badges44 bronze badges 3
  • please share the source that is being produced after you paste xxx<br/>yyy – Sid M Commented Jun 18, 2014 at 10:51
  • I have updated the problem and added the source code in there. Please have a look and help me – Bashabi Commented Jun 18, 2014 at 11:47
  • possible duplicate of Removing unwanted newline characters when adding <p> in CKEditor – dove Commented May 13, 2015 at 11:07
Add a ment  | 

3 Answers 3

Reset to default 7

I have solved the problem by adding the following lines of code in the config.js file.

CKEDITOR.editorConfig = function (config) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
CKEDITOR.on('instanceReady', function (ev) {
    var writer = ev.editor.dataProcessor.writer;
    // The character sequence to use for every indentation step.
    writer.indentationChars = '  ';

    var dtd = CKEDITOR.dtd;
    // Elements taken as an example are: block-level elements (div or p), list items (li, dd), and table elements (td, tbody).
    for (var e in CKEDITOR.tools.extend({}, dtd.$block, dtd.$listItem, dtd.$tableContent)) {
        ev.editor.dataProcessor.writer.setRules(e, {
            // Indicates that an element creates indentation on line breaks that it contains.
            indent: false,
            // Inserts a line break before a tag.
            breakBeforeOpen: false,
            // Inserts a line break after a tag.
            breakAfterOpen: false,
            // Inserts a line break before the closing tag.
            breakBeforeClose: false,
            // Inserts a line break after the closing tag.
            breakAfterClose: false
        });
    }

    for (var e in CKEDITOR.tools.extend({}, dtd.$list, dtd.$listItem, dtd.$tableContent)) {
        ev.editor.dataProcessor.writer.setRules(e, {
            indent: true,
        });
    }



});
}

if anyone facing the same problem like me just copy the above code and paste it in the config.js file in the ckeditor folder.

Thank you mo for your answers. You have been very helpful

you can avoid that by:

config.autoParagraph = false;

or

config.enterMode = CKEDITOR.ENTER_BR;

or

CKEDITOR.on('txtDescription', function (ev) {
        ev.editor.dataProcessor.writer.setRules('br',
         {
             indent: false,
             breakBeforeOpen: false,
             breakAfterOpen: false,
             breakBeforeClose: false,
             breakAfterClose: false
         });
    });

config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_BR;

and for more information see Output Formatting in CKEditor

Your problem isn't CKEditor or its configuration.

Instead you should look at your server code and remove the calls to nl2br

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论