<?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>25552</bug_id>
          
          <creation_ts>2014-05-05 16:22:13 +0000</creation_ts>
          <short_desc>Shouldn&apos;t &lt;figure&gt; also allow intermixed script-supporting elements (before/after the &lt;figcaption&gt;)?</short_desc>
          <delta_ts>2017-07-21 17:43:08 +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>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          <see_also>https://www.w3.org/Bugs/Public/show_bug.cgi?id=25555</see_also>
    
    <see_also>https://www.w3.org/Bugs/Public/show_bug.cgi?id=25549</see_also>
    
    <see_also>https://www.w3.org/Bugs/Public/show_bug.cgi?id=25553</see_also>
    
    <see_also>https://www.w3.org/Bugs/Public/show_bug.cgi?id=25547</see_also>
    
    <see_also>https://www.w3.org/Bugs/Public/show_bug.cgi?id=25550</see_also>
    
    <see_also>https://www.w3.org/Bugs/Public/show_bug.cgi?id=25551</see_also>
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#the-figure-element</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          <blocked>25547</blocked>
    
    <blocked>25550</blocked>
    
    <blocked>25551</blocked>
    
    <blocked>25553</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ian</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>105053</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2014-05-05 16:22:13 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/
Multipage: http://www.whatwg.org/C#the-figure-element
Complete: http://www.whatwg.org/c#the-figure-element
Referrer: 

Comment:
Shouldn&apos;t &lt;figure&gt; also allow intermixed script-supporting elements
(before/after the &lt;figcaption&gt;)?

Posted from: 2a00:801:e0:30:d9c4:c34f:b530:6023
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36 OPR/21.0.1432.48 (Edition Next)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105085</commentid>
    <comment_count>1</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-05-05 21:31:07 +0000</bug_when>
    <thetext>What&apos;s the value in doing this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105238</commentid>
    <comment_count>2</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-05-06 21:12:42 +0000</bug_when>
    <thetext>It&apos;s easy to understand that script/template is allowed anywhere (modulo HTML parser behavior). This is an unnecessary exception.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105331</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-05-07 18:36:07 +0000</bug_when>
    <thetext>But they&apos;re not allowed anywhere. There&apos;s lots of exceptions.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105403</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-05-08 07:50:56 +0000</bug_when>
    <thetext>Yeah, that&apos;s why I filed lots of bugs. :-P I don&apos;t see a technical reason for this exception to exist.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105463</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-05-08 17:54:03 +0000</bug_when>
    <thetext>The idea is that all the elements whose content model are essentially &quot;a fixed element, then a hole where you can fill whatever you want&quot; would only accept things like &lt;script&gt; and &lt;style&gt; in the hole, since that makes all the logic around the fixed element easier in tools that only have to deal with conforming content.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105711</commentid>
    <comment_count>6</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-05-12 12:01:25 +0000</bug_when>
    <thetext>I don&apos;t understand why &quot;a fixed element with a hole&quot; should be different from &quot;a fixed element without a hole&quot; (e.g. &lt;ol&gt;, &lt;dl&gt;, &lt;table&gt;). Doesn&apos;t the easier logic argument apply equally to those?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105735</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-05-12 17:54:20 +0000</bug_when>
    <thetext>Well if there&apos;s a hole, you can still do everything you need to, you just put the content in the hole.

If there&apos;s no hole, then it depends what you&apos;re trying to do. For example, in &lt;ol&gt; and &lt;dl&gt; you could easily imagine wanting a &lt;template&gt; that you stamp out, and putting it in the element seems like a logical place for it. In &lt;table&gt; we already have to allow crazy stuff for legacy reasons.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105931</commentid>
    <comment_count>8</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-05-13 23:25:14 +0000</bug_when>
    <thetext>Regardless of the decision here, the same decision will apply to the following cases also:

   &lt;details&gt;/&lt;summary&gt; (bug 25550)
   &lt;fieldset&gt;/&lt;legend&gt; (bug 25551)
   &lt;video&gt;/&lt;audio&gt;/&lt;source&gt;/&lt;track&gt; (bug 25547)
   &lt;object&gt;/&lt;param&gt; (bug 25553)

See also bug 25555 (ruby) and bug 25549 (datalist).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109534</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-07-29 23:53:38 +0000</bug_when>
    <thetext>IMHO the current state (now that bug 25549 and bug 25572 are fixed) is pretty internally consistent (modulo some weird constraints due to legacy, like not having &lt;script&gt; in &lt;colgroup&gt;). I don&apos;t see much value in changing the content models to allow script and template to be put before summary, legend, figcaption, source, track, param, and style (or after figcaption).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109836</commentid>
    <comment_count>10</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-08-04 14:42:55 +0000</bug_when>
    <thetext>OK. What do you think &lt;picture&gt;&apos;s content model should be?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109841</commentid>
    <comment_count>11</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-08-04 17:37:09 +0000</bug_when>
    <thetext>I don&apos;t think &lt;picture&gt; should exist.
If it exists, I don&apos;t think it should reuse &lt;source&gt;.

But more generally, for elements that take specific children, like &lt;select&gt;, &lt;optgroup&gt;, &lt;dl&gt;, and company (i.e. elements that don&apos;t take arbitrary flow or phrasing children), I think the design thinking should be:

 1. Figure out what elements are going to be required at all times in the element. 
    (Generally, it&apos;s bad design if something is required at all times, since you
    should just use the parent element instead.)

 2. Figure out what elements are going to be zero-or-more or one-or-more children.
    If it&apos;s zero-or-more, then allow them to be replaced by template or script (i.e.
    &quot;script-supporting elements). If it&apos;s one-or-more, only allow them to be
    replaced by &quot;template&quot;. Allowing zero-or-more is strongly encouraged.

 3. Figure out if the required elements, if any, are to be placed in any particular 
    location, or if it doesn&apos;t matter.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>111223</commentid>
    <comment_count>12</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-09-08 23:57:04 +0000</bug_when>
    <thetext>zcorpan, I&apos;m reassigning this to you per comment 10 and comment 11; please feel free to reassign this to me if you think there&apos;s more for me to do (e.g. if you disagree with comment 9). Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>111261</commentid>
    <comment_count>13</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-09-09 13:04:42 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #5)
&gt; The idea is that all the elements whose content model are essentially &quot;a
&gt; fixed element, then a hole where you can fill whatever you want&quot; would only
&gt; accept things like &lt;script&gt; and &lt;style&gt; in the hole, since that makes all
&gt; the logic around the fixed element easier in tools that only have to deal
&gt; with conforming content.

I don&apos;t see why it&apos;s easier in tools to only support conforming content. Let&apos;s take &lt;video&gt; for example, and the tool wants the &lt;source&gt; elements. In both cases you need to check if the given element is a &lt;source&gt; element.

// any content
function getSources(video) {
  return [].filter.call(video.children, function(child) {
    return child instanceof HTMLSourceElement;
  };
}

// only conforming content
function getSources(video) {
  var children = video.children;
  var rv = [];
  for (var i = 0; i &lt; children.length; ++i) {
    if (!(children[i] instanceof HTMLSourceElement)) {
      return rv;
    }
    rv.push(children[i]);
  }
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>111262</commentid>
    <comment_count>14</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-09-09 13:16:33 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #7)
&gt; Well if there&apos;s a hole, you can still do everything you need to, you just
&gt; put the content in the hole.

Not really for &lt;figure&gt;.

If I want to use &lt;script&gt; at the end of a &lt;figure&gt; to paint on the &lt;canvas&gt; and fill something in in the &lt;figcaption&gt;, I think that should be allowed regardless of if the &lt;figcapion&gt; is before or after the &lt;canvas&gt;. The current rule basically means I have to put the script after the &lt;/figure&gt; which is just wasting the author&apos;s time.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>111263</commentid>
    <comment_count>15</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-09-09 13:25:54 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #11)
&gt; But more generally, for elements that take specific children, like &lt;select&gt;,
&gt; &lt;optgroup&gt;, &lt;dl&gt;, and company (i.e. elements that don&apos;t take arbitrary flow
&gt; or phrasing children), I think the design thinking should be:
&gt; 
&gt;  1. Figure out what elements are going to be required at all times in the
&gt; element. 
&gt;     (Generally, it&apos;s bad design if something is required at all times, since
&gt; you
&gt;     should just use the parent element instead.)
&gt; 
&gt;  2. Figure out what elements are going to be zero-or-more or one-or-more
&gt; children.
&gt;     If it&apos;s zero-or-more, then allow them to be replaced by template or
&gt; script (i.e.
&gt;     &quot;script-supporting elements). If it&apos;s one-or-more, only allow them to be
&gt;     replaced by &quot;template&quot;. Allowing zero-or-more is strongly encouraged.
&gt; 
&gt;  3. Figure out if the required elements, if any, are to be placed in any
&gt; particular 
&gt;     location, or if it doesn&apos;t matter.

So &lt;picture&gt; has zero-or-more &lt;source&gt;s followed by one required &lt;img&gt;.

If I understand correctly, this would mean that &lt;picture&gt;&apos;s &lt;source&gt;s can be replaced by script/template, but not intermixed, and no script/template after the img.

Valid:

&lt;picture&gt;&lt;script&gt;&lt;/script&gt;&lt;img&gt;&lt;/picture&gt;
&lt;picture&gt;&lt;source&gt;&lt;img&gt;&lt;/picture&gt;

Invalid:

&lt;picture&gt;&lt;script&gt;&lt;/script&gt;&lt;source&gt;&lt;img&gt;&lt;/picture&gt;
&lt;picture&gt;&lt;source&gt;&lt;script&gt;&lt;/script&gt;&lt;img&gt;&lt;/picture&gt;
&lt;picture&gt;&lt;img&gt;&lt;script&gt;&lt;/script&gt;&lt;/picture&gt;

Is that right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>111264</commentid>
    <comment_count>16</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-09-09 13:28:21 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #9)
&gt; I don&apos;t see much value in changing
&gt; the content models to allow script and template to be put before summary,
&gt; legend, figcaption, source, track, param, and style (or after figcaption).

I disagree. I think disallowing them is waste of author time when the validator complains at them for using a &lt;script&gt; somewhere that does exactly what they wanted.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>111458</commentid>
    <comment_count>17</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-09-12 18:43:44 +0000</bug_when>
    <thetext>(In reply to Simon Pieters from comment #13)
&gt; 
&gt; I don&apos;t see why it&apos;s easier in tools to only support conforming content.

Because you start at the top of the element, and stop when you reach something that&apos;s not a source.

  function handleVideo(video) {
    var source = video.firstElementChild;
    // first handle the video&apos;s sources
    while (source &amp;&amp; source instanceof HTMLSourceElement) {
      // do whatever...
      source = source.nextElementSibling;
    }
    // then handle the video&apos;s tracks
    while (source &amp;&amp; source instanceof HTMLTrackElement) {
      // do whatever...
      source = source.nextElementSibling;
    }
  }

It gets much more messy if you have a content model that allows mixing stuff around, interleaving scripts, or whatever.

(In reply to Simon Pieters from comment #14)
&gt; 
&gt; If I want to use &lt;script&gt; at the end of a &lt;figure&gt; to paint on the &lt;canvas&gt;
&gt; and fill something in in the &lt;figcaption&gt;, I think that should be allowed
&gt; regardless of if the &lt;figcapion&gt; is before or after the &lt;canvas&gt;. The
&gt; current rule basically means I have to put the script after the &lt;/figure&gt;
&gt; which is just wasting the author&apos;s time.

The script here is not part of the transparent part of the figure, the &quot;figure per se&quot;, for lack of a better term. In the case of figcaption being at the start, it looks like you can do it, because then the script is &quot;reaching out&quot; of the figure to affect the caption. But really it&apos;s not supposed to be in the figure at all, since it&apos;s affecting the figcaption.

I suppose we could allow &lt;script&gt; to be interleaved into &lt;figure&gt;, &lt;hgroup&gt;, and so on, not as a replacement but just because scripts can go more or less anywhere. But this makes the connection between &lt;script&gt; and &lt;template&gt; much more tenuous, makes the content models much more complicated, and generally makes things less consistent and coherent, IMHO. And I still think it&apos;d be bad in the &lt;video&gt; case, for the reason given above.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>111671</commentid>
    <comment_count>18</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2014-09-17 08:00:20 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #17)
&gt; Because you start at the top of the element, and stop when you reach
&gt; something that&apos;s not a source.

I see. I&apos;m not convinced it&apos;s much more messy to support any order, though.

  function handleVideo(video) {
    var source = video.firstElementChild;
    while (source) {
      // handle the video&apos;s sources
      if (source instanceof HTMLSourceElement) {
        // do whatever...
      }
      // handle the video&apos;s tracks
      if (source instanceof HTMLTrackElement) {
        // do whatever...
      }
      source = source.nextElementSibling;
    }
  }

Also, if the tool is supposed to work with arbitrary Web content, it can&apos;t assume that it is valid anyway. If the tool only works with content that is known to have a particular structure, it doesn&apos;t need the spec requiring that particular structure. So I think it&apos;s not a convincing argument.

&gt; The script here is not part of the transparent part of the figure, the
&gt; &quot;figure per se&quot;, for lack of a better term. In the case of figcaption being
&gt; at the start, it looks like you can do it, because then the script is
&gt; &quot;reaching out&quot; of the figure to affect the caption. But really it&apos;s not
&gt; supposed to be in the figure at all, since it&apos;s affecting the figcaption.

That&apos;s... really obscure. I really don&apos;t think authors are going to think in those terms. They will just put their scripts where they please and have it do whatever they need to do.
 
&gt; I suppose we could allow &lt;script&gt; to be interleaved into &lt;figure&gt;, &lt;hgroup&gt;,
&gt; and so on, not as a replacement but just because scripts can go more or less
&gt; anywhere.

Yes.

&gt; But this makes the connection between &lt;script&gt; and &lt;template&gt; much
&gt; more tenuous, makes the content models much more complicated, and generally
&gt; makes things less consistent and coherent, IMHO.

So allow &lt;template&gt; where &lt;script&gt; is allowed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128769</commentid>
    <comment_count>19</comment_count>
    <who name="Michael[tm] Smith">mike</who>
    <bug_when>2017-07-21 17:43:08 +0000</bug_when>
    <thetext>Let’s re-raise this in the GitHub issue tracker if necessary.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>