<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>28467</bug_id>
          
          <creation_ts>2015-04-12 06:42:54 +0000</creation_ts>
          <short_desc>How character data is get serialized when appended as innerHTML to  &lt;pre&gt; element.</short_desc>
          <delta_ts>2016-03-26 17:34:03 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          
          <bug_file_loc>https://html.spec.whatwg.org/#serialising-html-fragments</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>annevk</cc>
    
    <cc>ian</cc>
    
    <cc>kandalkar.abhijeet58</cc>
    
    <cc>mike</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>119440</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2015-04-12 06:42:54 +0000</bug_when>
    <thetext>Specification: https://html.spec.whatwg.org/
Multipage: https://html.spec.whatwg.org/multipage/#serialising-html-fragments
Complete: https://html.spec.whatwg.org/#serialising-html-fragments
Referrer: https://www.google.co.in/

Comment:
How character data is get serialized when appended as innerHTML to  &lt;pre&gt;
element. ?  HTML : &lt;div&gt;&lt;pre id=&quot;test3&quot;&gt;&lt;/pre&gt;&lt;/div&gt;  JS : 
document.getElementById(&quot;test3&quot;).innerHTML = &quot;\n\n\nfoo&quot;; str =
document.getElementById(&quot;test3&quot;).innerHTML;  As per spec, If current node is a
pre element, and the first child node of the element, if any, is a Text node
whose character data has as its first character a U+000A LINE FEED (LF)
character, then append a U+000A LINE FEED (LF) character.  I was expecting,
str = &quot;\n\nfoo&quot; but FF/chrome is returning it as str=&quot;\n\n\nfoo&quot;

Posted from: 106.51.129.57
User agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119441</commentid>
    <comment_count>1</comment_count>
    <who name="Abhijeet Kandalkar">kandalkar.abhijeet58</who>
    <bug_when>2015-04-12 06:52:59 +0000</bug_when>
    <thetext>Please refer JSfiddle demonstrating scenario ,

http://jsfiddle.net/abhijeetk/j91n2vLd/1/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119582</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2015-04-16 22:05:54 +0000</bug_when>
    <thetext>I don&apos;t understand the bug here. Are you saying the browsers and the spec match?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119635</commentid>
    <comment_count>3</comment_count>
    <who name="Abhijeet Kandalkar">kandalkar.abhijeet58</who>
    <bug_when>2015-04-17 13:44:50 +0000</bug_when>
    <thetext>Currently, blink/Gecko/Webkit all doesn&apos;t support proper serialization of HTML markup inside &lt;pre&gt; tag.

1.
During parsing, In the HTML syntax, a leading newline character immediately following the pre element start tag is stripped. Refer https://html.spec.whatwg.org/#the-pre-element

2.
Creating HTML fragment for innerHTML function call should behave in reverse way as that of parsing.
As per spec, https://html.spec.whatwg.org/#serialising-html-fragments
&quot;If current node is a pre, textarea, or listing element, and the first child node of the element, if any, is a Text node whose character data has as its first character a U+000A LINE FEED (LF) character, then append a U+000A LINE FEED (LF) character.&quot;

Consider jsfiddle in previous comment:

&lt;pre id=&quot;test1&quot;&gt;


foo&lt;/pre&gt;

str = document.getElementById(&quot;test1&quot;).innerHTML;
val1 = (str.match(/\n/g) || []).length;

During parsing, html markup inside &lt;pre&gt; is &quot;\n\n\nfoo&quot; (three newlines)
but when you as for innerHTML it is returning &quot;\n\nfoo&quot; (two newline)

That is for each rountrip we are ignoring &apos;1&apos; newline.

Refer chrome issue : https://code.google.com/p/chromium/issues/detail?id=174829

Currently browsers are not behaving properly for &lt;pre&gt; serialization. I have identified three use cases as mentioned in http://jsfiddle.net/abhijeetk/j91n2vLd/1/. Could you please let me know proper behavior in each of this case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119678</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2015-04-20 11:19:58 +0000</bug_when>
    <thetext>The proper behavior per spec is to serialize an extra LF when the first child is Text and starts with LF.

Test: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3504</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119734</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2015-04-21 21:18:49 +0000</bug_when>
    <thetext>As far as I can tell this is a bug with the browsers, not with the spec. If that is the case, then the bug should be filed in the relevant bug trackers of the browser vendors.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125629</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-03-25 13:08:52 +0000</bug_when>
    <thetext>I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1259723 against Gecko.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125635</commentid>
    <comment_count>7</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-03-26 17:34:03 +0000</bug_when>
    <thetext>https://github.com/whatwg/html/issues/944</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>