Search code examples
javascripthtmlnode.jsmongodbckeditor

CKEditor adding indents between <p> tags from source HTML


So, nodejs project, express, mongodb, there is one function, that generate some HTML code for saving it in DB, here is it

botcfg.body =
    '<h3>Trade amount settings</h3>'
    + '<p># Coin position: <strong>' + req.body.coin_pos + '</strong></p>'
    + '<p># Trade amount: <strong>' + req.body.ta + '</strong></p>'
    + '<p># Template: <strong>' + req.body.template + '</strong></p>'
    + '<p># Fee: <strong>' + req.body.fee + '</strong></p>'
    + '<br>'
    + '<h3>Mad hatter mode</h3>'
    + '<p># Min Price Change To Buy: <strong>' + mh_min_pr_c2b + '</strong></p>'
    + '<br>'
    + '<h3>Safety settings</h3>'
    + '<p># Min Price Change To Buy: <strong>' + req.body.ss_min_pr_c2b + '</strong></p>'
    + '<p># Min Price Change To Sell: <strong>' + req.body.ss_min_pr_c2s + '</strong></p>'
    + '<p># Stop Loss (%): <strong>' + req.body.stoploss + '</strong></p>'
    + '<br>'

In Jade view I get it with

h4 Config
            div.botconf-text.no-p-margin!= botcfg.body

(without tags, as HTML) How i see after saving from node

After that, if I want to edit this body i use CKEditor 4

script.
    CKEDITOR.replace('botcfg-body-edit', {
        toolbar: 'Full',
        height: '600px'
    })

And, when i do nothing and simply save text i recieve the text with indents between P tags... After ckeditor saving

I try to add below configs in different ways (autoParagraph single, fillEmptyBlocks single, they together etc), but nothing helps

config.autoParagraph = false;
config.fillEmptyBlocks = false;
config.enterMode = CKEDITOR.ENTER_BR;
config.forceEnterMode = true;

The style of P of this text is

.botconf-text {
    white-space: pre-wrap;
    color: #99ff99;
    border-left: 2px dotted #ABABAB;
    padding: 8px;
    margin-left: 8px;
}

.no-p-margin p {
    margin: 0 0 2px;
}

try to add specially no-p-margin tag for p childrens in div but not... Don't understand what setting this padding.


Solution

  • My fault... for storing data I use MongoDB, when i inserting data in it it saving as it is (with \r\n) so when i calling != botcfg.body in jade template I recieve text how it's stored, I add regex when parsing parameter botcfg.body = req.body.body.replace(/(\r\n|\n|\r)/gm,""); and everything goes OK. May be that can help someone else. CKEditor configs not needed.