Search code examples
htmlnewlineline-breaks

how to view line break in page source


If I view page source of below html page:

This is first line text
This is second line text

I can see:

<div><font color="black">This is first line text<br>
This is second line text<br></font>

But if the above lines are in <pre></pre> tag, the page source is like something below:

This is first line text
This is second line text

i.e, I can't see any html tags like <\n> or <nl2br> here. Is there any browser plugin or php code so that I can view from page source, whether the new line/ line break within <pre></pre> tag is either <\n> or <nl2br> here?


Solution

  • I think you can use js(jQuery) to do this, please check this link, a small example, hope it helps =D

    $("pre").each(function(index) {
      let pre_text = JSON.stringify($(this).text())
      alert(pre_text);
    });
    

    https://jsfiddle.net/dalinhuang/hhsaukec/4/

    then you can save those raw data into a hidden tag? or do whatever you want.