Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Browser and UI #2 HTML/ARIA

ken7253
April 28, 2025

Browser and UI #2 HTML/ARIA

[Browser and UI #2 HTML/ARIA](https://browser-and-ui.connpass.com/event/343524/)にて発表したスライドです

勉強会の趣旨説明とオープニングトークとしてHTMLパーサーの仕様についてのクイズをおこないました。

ken7253

April 28, 2025
Tweet

More Decks by ken7253

Other Decks in Programming

Transcript

  1. HTML Parser Quiz!! 手元で試してみたい人はコンソールで DOMParser を使うと簡単に試せるかも。 https://developer.mozilla.org/ja/docs/Web/API/DOMParser const p =

    new DOMParser(); const dom = p.parseFromString(` <!DOCTYPE html> <html> <head></head> <body><h1 id="foo">Hello HTML!</h1></body> </html> `, 'text/html'); console.log(dom.getElementById("foo")); // => <h1 id="foo">Hello HTML!</h1>
  2. point <html> / <head> / <body> などを書いていない Q1: Skip Element

    <!DOCTYPE html> <meta charset="utf-8"> <div>Hello World.</div>
  3. <html> / <head> / <body> が挿入される 特定の要素については書かれていなくても補完される ※ <div> の後に

    <title> などを入れた場合は <body> 内部に入る A1: Skip Element <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <div>Hello World.</div> </body> </html>
  4. head内部の処理 doctype が終了( before html 状態)のときに html 以外の開始タグが出現 <html> をDOMに挿入する

    before head に移行する before head の状態で head 以外のタグが出現した head をDOMに挿入する in head に移行する meta[charset="UTF-8"] を挿入する A1: Skip Element
  5. point <!-- console.log("html comment"); はどのように解釈されるか --> はどのように解釈されるか Q2: HTML Comment

    with inline script 1 <!doctype html> 2 <html lang="ja"> 3 <head> 4 <script> 5 <!-- console.log("html comment"); 6 console.log("Hello, world!"); 7 </script> 8 --> 9 </head> 10 <body></body> 11 </html>
  6. <a> を開いたが先に <b> の閉じタグが来ている <b> の閉じタグの後に <a> が閉じられている 閉じタグの順番がぐちゃぐちゃ HTML

    LSにも乗っている有名(?)な問題 Q3: Formatting Elements <!-- // --> <body> <p>foo<b>bar<a href="#top">buzz</b>qux</a>foobar</p> </body> <!-- // -->
  7. qux の部分に <a> の開始タグが挿入される これはFormatting Elements特有の挙動 A3: Formatting Elements 7

    <a href="#top">qux</a> 1 <!-- // --> 2 <body> 3 <p>foo 4 <b>bar 5 <a href="#top">buzz</a> 6 </b> 8 foobar 9 </p> 10 </body> 11 <!-- // -->
  8. HTML LSに定義されている下記の要素 a / b / big / code /

    em / font / i / nobr / s / small / strike / strong / tt / u これらの要素が出現している間は自動閉じタグ挿入の仕組みが特別なものにな る。 自動的に閉じタグが挿入されるが、本来の閉じタグがある場所まではフォーマ ットを維持するために開始タグを挿入したりする。 Formatting Elements The following HTML elements are those that end up in the list of active formatting elements: a, b, big, code, em, font, i, nobr, s, small, strike, strong, tt, and u.
  9. Step <!-- // --> <body> <p>foo <b>bar <a href="#top"> buzz

    </a> </b><a href="#top">qux </a><!-- [] -->foobar </p> </body> <!-- // -->
  10. END