0

our web application shares code. To share the proper code we have used htmlEncode and htmlDecode as follow so that all the htmlTags are handled properly when they pass via http protocol as follows

     htmlEncode = function (value) {
     if (value) {
         return $('<div />').text(value).html();
     }
     else {
         return '';
     }
 },
htmlDecode = function (value) {
    if (value) {
        return $('<div />').html(value).text();
    }
    else {
        return '';
    }
},

Now if user gave more spaces within the code, it gets coverted to single space (which ofcourse is not a big issue).

But the issue with this kind of implementation is if user has clicked EnterKey twice or thrice within the code sharing section, then its not taken as it is but the output is in a single line as follows:

UserInput: enter image description here

Actual Output enter image description here

Expected Output enter image description here

Any solution?

ismail baig
  • 861
  • 2
  • 11
  • 39
  • Is this output in a textbox/textarea? I think [this question](http://stackoverflow.com/questions/3381331/jquery-convert-br-and-br-and-p-and-such-to-new-line) will help you. – George Feb 27 '13 at 10:16
  • Check out http://stackoverflow.com/questions/8482991/textarea-value-not-showing-any-new-lines-breaks?rq=1 - it might help with the specific problem of line breaks/new lines. – Raad Feb 27 '13 at 10:18
  • @F4R-20: User input is in a textarea,but the output is in a div – ismail baig Feb 27 '13 at 10:18

1 Answers1

0

This is to be expected as this is exactly the effect peforming .text() on your value should have. I think you shouldn't use .text in this case

Surya
  • 129
  • 1
  • 3
  • 12