Thuta Learning
HTML
BasicWeb Developmentအခြေခံ

Quotes & Code Text

HTMLသင်ခန်းစာ 1225 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Quote အရှည်အတွက် <blockquote> နဲ့ စာကြောင်းထဲက quote အတိုအတွက် <q> ကို ရွေးသုံးနိုင်ဖို့
  • Quote ရဲ့ မူရင်းကို blockquote ရဲ့ အပြင်ဘက်မှာ figcaption နဲ့ ဖော်ပြနိုင်ဖို့
  • Inline code ကို <code>၊ code block ကို <pre><code>၊ keyboard key ကို <kbd> နဲ့ ရေးနိုင်ဖို့
  • HTML code ကို page ပေါ်မှာ ပြချင်တဲ့အခါ < နဲ့ & ကို escape လုပ်နိုင်ဖို့

ရိုးရိုးလေး ရှင်းပြမယ်

ရိုးရိုးလေး ရှင်းရရင်

သတင်းစာ ဆောင်းပါးတစ်ပုဒ်မှာ တခြားသူ ပြောတဲ့ စကားကို quotation mark နဲ့ ပိတ်ပြီး ရေးပါတယ်၊ ရှည်ရင်တော့ သီးသန့် အပိုဒ်အဖြစ် အတွင်းကို ဝင်ပြီး ရေးပါတယ်။ HTML မှာ စာကြောင်းထဲက quote အတိုကို <q>၊ သီးသန့် အပိုဒ် quote ကို <blockquote> နဲ့ ရေးပါတယ်။

Programming tutorial တွေမှာ code ကိုလည်း သာမန်စာနဲ့ ခွဲပြရပါတယ်။ စာကြောင်းထဲက code စကားလုံးကို <code>၊ line အများကြီးပါတဲ့ code block ကို <pre> ထဲမှာ <code>၊ နှိပ်ရမယ့် keyboard key ကို <kbd> နဲ့ ရေးပါတယ်။

Problem → Why → Solution

ပြဿနာ: ပြချင်တဲ့ tag က တကယ့် tag ဖြစ်သွားတာ

HTML tutorial တစ်ခု ရေးနေတဲ့သူက "Use <h1> for the title" ဆိုတဲ့ စာကြောင်းကို paragraph ထဲမှာ ဒီအတိုင်း ရိုက်ထည့်လိုက်ပါတယ်။ ပြီးတော့ code example တစ်ခုကို indent တွေနဲ့ paragraph ထဲမှာ ကူးထည့်လိုက်ပါတယ်။ Browser မှာ ဖွင့်လိုက်တော့ "<h1>" ဆိုတဲ့ စာသား ပျောက်သွားပြီး "for the title" က ခေါင်းစဉ်ကြီး ဖြစ်သွားကာ code example ရဲ့ indent တွေ အကုန် ပျောက်သွားပါတယ်။

tutorial.html
<p>Use <h1> for the title of the page.</p>

<p>
  <ul>
    <li>Item</li>
  </ul>
</p>

ဘာကြောင့် ဒီလို ဖြစ်တာလဲ

Browser က < ကို မြင်တာနဲ့ tag အစလို့ ယူဆပါတယ်။ ဒါကြောင့် စာသားထဲက <h1> က heading element အစစ် ဖြစ်သွားပြီး ဒုတိယ paragraph ထဲက <ul> ကလည်း list အစစ် ဖြစ်သွားပါတယ်။ Indent တွေကတော့ whitespace ချုံ့တဲ့ စည်းမျဉ်းကြောင့် ပျောက်ပါတယ်။ Code ကို စာသားအဖြစ် ပြချင်ရင် < ကို character reference နဲ့ escape လုပ်ရပြီး spacing ကို ထိန်းဖို့ <pre> ကို သုံးရပါတယ်။

Core concept: ကိုးကားတာနဲ့ code ပြတာ

<blockquote> က တခြား source ကနေ ကိုးကားထားတဲ့ block quote ပါ။ ထဲမှာ <p> တွေ ထည့်ရေးလို့ ရပြီး browser က ဘယ်ညာ နှစ်ဖက်လုံးမှာ margin ပေးလို့ အတွင်းကို ဝင်နေတာ မြင်ရပါတယ်။ cite attribute မှာ source ရဲ့ URL ကို ထည့်လို့ ရပေမယ့် browser က page ပေါ်မှာ မပြပါဘူး။ ဒါကြောင့် စာဖတ်သူ မြင်ရမယ့် ကိုးကားချက် (ဘယ်သူ ပြောတာလဲ၊ ဘယ်စာအုပ်ကလဲ) ကို spec ညွှန်ကြားတဲ့အတိုင်း blockquote ရဲ့ အပြင်ဘက်မှာ ရေးပါ — အများအားဖြင့် <figure> ထဲမှာ blockquote နဲ့ <figcaption> ကို တွဲထားပါတယ်။

<q> က စာကြောင်းထဲမှာ ပါတဲ့ quote အတိုပါ။ Browser က quotation mark တွေကို CSS နဲ့ အလိုအလျောက် ထည့်ပေးလို့ ကိုယ်တိုင် " မရိုက်ရပါဘူး၊ ရိုက်ရင် နှစ်ထပ် ဖြစ်ပါတယ်။ <cite> element ကတော့ စာအုပ်၊ ရုပ်ရှင်၊ ဆောင်းပါး လို လက်ရာတစ်ခုရဲ့ ခေါင်းစဉ်အတွက်ပါ၊ default မှာ italic ပေါ်ပါတယ်။

<code> က computer code အပိုင်းအစ ဖြစ်ကြောင်း ပြပြီး monospace font နဲ့ ပေါ်ပါတယ်၊ ဒါပေမယ့် whitespace တွေကိုတော့ ပုံမှန်အတိုင်း ချုံ့ပါတယ်။ <pre> (preformatted) က space နဲ့ line break အားလုံးကို source ထဲကအတိုင်း ထိန်းထားပါတယ်။ Code block ရဲ့ standard ပုံစံက <pre><code>...</code></pre> ပါ — <pre> က spacing ကို ထိန်းပြီး <code> က "ဒါ code ပါ" လို့ အဓိပ္ပာယ် ပေးပါတယ်။ <kbd> က user ရိုက်ထည့်ရမယ့် input (Ctrl, Enter လို key တွေ) အတွက်ပါ။ <pre> ထဲက line ရှည်တွေက default မှာ line မခွဲလို့ CSS က wrap လုပ်ခွင့် မပေးရင် code အကျယ်ကြီးတွေက ဘေးတိုက် scroll ဆွဲရပါတယ်။

<code> နဲ့ <pre> ထဲမှာတောင် browser က tag တွေကို parse လုပ်ပါသေးတယ်။ ဒါကြောင့် HTML code ကို စာသားအဖြစ် ပြချင်ရင် < ကို ampersand, lt, semicolon ဆိုတဲ့ character reference နဲ့ ရေးရပြီး & ကိုလည်း ampersand, amp, semicolon နဲ့ ရေးရပါတယ်။ > ကို escape လုပ်ဖို့ အမြဲ မလိုပေမယ့် ampersand, gt, semicolon နဲ့ ရေးထားရင် ဖတ်ရတာ တစ်ပုံစံတည်း ဖြစ်ပါတယ်။ Example ထဲမှာ အတိအကျ ရေးပုံကို ကြည့်ပါ။

မှတ်ထားရမယ့် ပုံစံ: ဘယ်သူ့ စကားလဲ၊ ဘယ်လို စာသားလဲ
  1. တခြားသူ့ စကား အရှည် → <blockquote>
  2. စာကြောင်းထဲက quote → <q>
  3. Code စကားလုံး → <code>၊ block → pre+code
  4. Code ထဲက < နဲ့ & ကို escape

Quote tag တွေက "ဘယ်သူ့ စကားလဲ" ကို ပြပြီး code tag တွေက "ဘယ်လို စာသားလဲ" ကို ပြပါတယ်။

အထွေထွေ ပုံစံ

html
<figure>
  <blockquote cite="source-url"><p>Long quotation</p></blockquote>
  <figcaption>Author, <cite>Title of the work</cite></figcaption>
</figure>
<p>Sentence with <q>a short quote</q> and <code>codeWord</code>.</p>
<p>Press <kbd>Key</kbd> to continue.</p>
<pre><code>escaped code, spacing kept</code></pre>

figure က quote နဲ့ သူ့ မူရင်းကို တွဲထားပြီး figcaption က blockquote ရဲ့ အပြင်မှာ ရှိပါတယ်။ <q>, <code>, <kbd> က inline ဖြစ်လို့ စာကြောင်းထဲမှာ ရေးပြီး <pre><code> က သီးသန့် block ပါ။

Example: quote, inline code, key နဲ့ code block

ဒီ page မှာ figcaption ကိုးကားချက်ပါတဲ့ blockquote, <q>, inline code, <kbd> နဲ့ code block တို့ အကုန် ပါပါတယ်။ Code ထဲက < တွေကို character reference နဲ့ ရေးထားတာကို သတိထားကြည့်ပါ။ ပြီးရင် page ကို ဖွင့်ပြီး နှိုင်းယှဉ်ကြည့်ပါ — browser က reference တစ်ခုစီကို မြင်ရတဲ့ < character အဖြစ် ပြန်ပြောင်းပေးပါတယ်။

quotes-and-code.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Quotes and code</title>
</head>
<body>
  <figure>
    <blockquote>
      <p>Learning HTML is the first step to building the web.</p>
    </blockquote>
    <figcaption>From the course introduction</figcaption>
  </figure>
  <p>My teacher always said <q>close every tag you open</q>.</p>
  <p>Use <code>&lt;h1&gt;</code> for the main heading.</p>
  <p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save your file.</p>
  <pre><code>&lt;ul&gt;
  &lt;li&gt;Code block example&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</body>
</html>

Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်

  1. Lines 8-13<figure> <blockquote> <p>Learning HTML is the first step to building the web.</p> </blockquote> <figcaption>From the course introduction</figcaption> </figure>

    Quote ကို paragraph အဖြစ် blockquote ထဲမှာ ထည့်ပြီး မူရင်းကို blockquote ရဲ့ အပြင်က figcaption မှာ ရေးပါတယ်။ figure က နှစ်ခုကို အုပ်စုတစ်ခုအဖြစ် ချိတ်ပေးပါတယ်။

  2. Line 14<q>close every tag you open</q>

    Quotation mark တွေကို ကိုယ်တိုင် မရိုက်ထားပါဘူး၊ browser က document ရဲ့ lang အလိုက် ထည့်ပေးပါတယ်။

  3. Line 15<code>&lt;h1&gt;</code>

    Character reference တွေကြောင့် browser က ဒါကို tag အဖြစ် မဟုတ်ဘဲ <h1> ဆိုတဲ့ စာသားအဖြစ် ပြပါတယ်။ ဒီလို မ escape ရင် heading element အစစ် ဖြစ်သွားပါမယ်။

  4. Line 16<kbd>Ctrl</kbd> + <kbd>S</kbd>

    Key တစ်ခုစီကို <kbd> ကိုယ်စီ ပေးထားလို့ CSS နဲ့ keycap ပုံစံ ပေးချင်ရင် key တစ်ခုချင်းစီ ခွဲပြီး style လုပ်လို့ ရပါတယ်။

  5. Lines 17-19<pre><code>&lt;ul&gt; &lt;li&gt;Code block example&lt;/li&gt; &lt;/ul&gt;</code></pre>

    <pre> က line break နဲ့ ဒုတိယ line ရဲ့ space နှစ်ခုကို ထိန်းထားပါတယ်။ <pre> ထဲက content က source ထဲမှာ left margin ကနေ စရပါမယ်၊ မဟုတ်ရင် file ရဲ့ indent တွေက output ထဲ ပါသွားပါမယ်။

You should see
Quote စာကြောင်းက ဘယ်ညာ အတွင်းဝင်ပြီး အောက်မှာ "From the course introduction" ပေါ်ပါတယ်။ ဆရာ့စကားကို browser က ထည့်ပေးတဲ့ “ ” quotation mark နဲ့ မြင်ရပြီး <h1>, Ctrl, S က monospace font နဲ့ ပေါ်ပါတယ်။ နောက်ဆုံးမှာ <ul>, <li>Code block example</li>, </ul> ဆိုတဲ့ line သုံးကြောင်းကို ဒုတိယ line indent အတိုင်း monospace နဲ့ မြင်ရပါမယ်။

Escape လုပ်ရမယ့် character တွေနဲ့ ဘယ်ဟာ ဘယ်တော့ သုံးလဲ

အောက်က code segment က character တစ်ခုစီကို HTML source ထဲမှာ ဘယ်လို ရေးရလဲ ပြထားပါတယ်။ ဘယ်ဘက်က ရေးရမယ့် ပုံစံ၊ comment ထဲမှာ page ပေါ်မှာ မြင်ရမယ့် character ပါ။

escaping.html
<p><code>&lt;</code></p>   <!-- shows <  (always escape inside code) -->
<p><code>&amp;</code></p>  <!-- shows &  (escape when shown as text) -->
<p><code>&gt;</code></p>   <!-- shows >  (optional, but consistent) -->
<p><code>&quot;</code></p> <!-- shows "  (inside a double-quoted attribute) -->
Elementဘာအတွက်လဲDefault ပုံစံ
<blockquote>Source တစ်ခုက quote အရှည်ဘယ်ညာ indent
<q>စာကြောင်းထဲက quote အတိုQuotation mark အလိုအလျောက်
<cite>စာအုပ်၊ ရုပ်ရှင် စတဲ့ လက်ရာ ခေါင်းစဉ်Italic
<code>Code အပိုင်းအစMonospace
<pre>Spacing ထိန်းရမယ့် စာသားMonospace, whitespace ထိန်း
<kbd>User ရိုက်ရမယ့် key/inputMonospace

လက်တွေ့ project တွေမှာ

Real project တွေမှာ ဘယ်လို သုံးလဲ

Documentation site တွေ၊ blog တွေ အားလုံးမှာ code block တွေကို <pre><code> နဲ့ ထုတ်ပါတယ်။ Syntax highlighting library တွေက <code> ထဲက စာသားကို ဖတ်ပြီး keyword တစ်ခုစီကို အရောင်ပါတဲ့ <span> တွေနဲ့ ပတ်ပေးပါတယ်၊ class="language-html" လို class ကို ကြည့်ပြီး ဘာ language လဲ ဆုံးဖြတ်ကြပါတယ်။ Markdown မှာ backtick သုံးခုနဲ့ ရေးတဲ့ code block ကလည်း နောက်ကွယ်မှာ <pre><code> ဖြစ်လာပြီး < တွေကို အလိုအလျောက် escape လုပ်ပေးပါတယ်။

News site တွေနဲ့ review site တွေက customer ရဲ့ စကား၊ ခေါင်းဆောင်တွေရဲ့ မိန့်ခွန်းကို figure ထဲက blockquote နဲ့ figcaption ကိုးကားချက်နဲ့ ပြလေ့ ရှိပြီး landing page တွေရဲ့ testimonial card တွေကလည်း ဒီ structure ကို သုံးပါတယ်။ Software help page တွေမှာတော့ keyboard shortcut တွေကို <kbd> နဲ့ ရေးပြီး CSS နဲ့ ခလုတ်ပုံစံ ပေးကြပါတယ်။ User ရေးထားတဲ့ comment ကို page ပေါ် ပြတဲ့ server code တိုင်းကလည်း < နဲ့ & ကို escape လုပ်ပေးရပါတယ် — မလုပ်ရင် comment ထဲက <script> tag က တကယ် run သွားနိုင်ပြီး cross-site scripting (XSS) ပြဿနာ ဖြစ်ပါတယ်။

အမှားများ

အဖြစ်များတဲ့ အမှားတွေ

1. Code ထဲက < ကို escape မလုပ်တာ

<code><p></code> လို ရေးရင် browser က paragraph element အစစ် တစ်ခု ဖန်တီးပြီး စာသား <p> က ပျောက်သွားပါတယ်။ < ကို အမြဲ character reference နဲ့ ရေးပါ။

2. <q> ထဲမှာ quotation mark ကိုယ်တိုင် ထည့်တာ

<q>"Hello"</q> လို ရေးရင် browser ထည့်တဲ့ mark နဲ့ ပေါင်းပြီး mark နှစ်ထပ် ပေါ်ပါတယ်။ Mark တွေကို browser ကို ထည့်ခိုင်းပါ။

3. Indent ပေးချင်လို့ <blockquote> သုံးတာ

Quote မဟုတ်တဲ့ စာသားကို အတွင်းဝင်အောင် blockquote ထဲ ထည့်ရင် screen reader က quote အဖြစ် ဖတ်နိုင်ပါတယ်။ Indent ကို CSS margin-left ဒါမှမဟုတ် padding နဲ့ ပေးပါ။

4. Author နာမည်ကို blockquote ထဲမှာ ထည့်တာ

Blockquote ထဲမှာ ပါတာ အားလုံးက ကိုးကားထားတဲ့ စကားလို့ အဓိပ္ပာယ် ရပါတယ်၊ author နာမည်က ပြောခဲ့တဲ့ စကား မဟုတ်ပါဘူး။ figure နဲ့ figcaption ကို သုံးပြီး အပြင်ဘက်မှာ ထားပါ။

Best Practices

အကောင်းဆုံး အလေ့အကျင့်များ

  • Code block တိုင်းမှာ <code> ပေါ်က class="language-html" လို language class ထည့်ထားပါ၊ highlighting tool တွေနဲ့ ချိတ်ရ လွယ်ပါတယ်။
  • ကိုးကားတဲ့ စကားကို မူရင်းအတိုင်း တိတိကျကျ ကူးပြီး ဘယ်သူ ပြောတာလဲ ဆိုတာကို မြင်သာတဲ့ figcaption နဲ့ ဖော်ပြပါ။
  • Code ကို လက်နဲ့ escape လုပ်ရတာ များလာရင် Markdown ဒါမှမဟုတ် template engine ကို သုံးပြီး အလိုအလျောက် escape လုပ်ခိုင်းပါ။
  • <pre> ထဲက code ကို ကိုယ့်ဘာသာ copy ကူးပြီး editor ထဲမှာ run ကြည့်ပါ၊ escape အမှားတွေ ချက်ချင်း တွေ့ပါမယ်။

Mini challenge

Mini challenge: tip page တစ်ခု

HTML tip တစ်ခုအကြောင်း page လေးတစ်ခု ရေးပါ။ မူရင်းပါတဲ့ quote တစ်ခု၊ စာကြောင်းထဲက quote အတို၊ keyboard shortcut၊ inline code နဲ့ escape လုပ်ထားတဲ့ HTML code block တစ်ခု ပါရပါမယ်။

  • figure ထဲမှာ blockquote နဲ့ figcaption (cite ပါ)
  • စာကြောင်းထဲမှာ <q> တစ်ခု (quotation mark ကိုယ်တိုင် မရိုက်ရ)
  • <kbd> နဲ့ shortcut တစ်ခု၊ <code> နဲ့ tag နာမည်တစ်ခု
  • Indent ပါတဲ့ HTML line သုံးကြောင်းကို <pre><code> ထဲမှာ escape လုပ်ပြီး
tip.html
<!-- Place inside the <body> of a full page -->
<h1>Tip: always add alt text</h1>

<!-- TODO: figure > blockquote (a paragraph) + figcaption with a <cite> title -->

<!-- TODO: a sentence containing a short <q> quote -->

<!-- TODO: a sentence with a <kbd> shortcut and a tag name in <code> -->

<!-- TODO: a <pre><code> block with three lines of escaped HTML -->

ရလဒ်: Quote က indent ဝင်ပြီး အောက်မှာ italic စာအုပ်နာမည်ပါတဲ့ ကိုးကားချက်၊ browser ထည့်တဲ့ quotation mark ပါတဲ့ quote အတို၊ monospace key နဲ့ code စကားလုံး၊ နောက်ဆုံးမှာ tag တွေကို စာသားအဖြစ် မြင်ရတဲ့ indent ပါတဲ့ code block တစ်ခု ပေါ်ပါမယ်။

အရိပ်အမြွက် ကြည့်ရန်

Code block ကို အရင် သာမန် HTML အတိုင်း ရေးပြီးမှ < တိုင်းကို character reference နဲ့ အစားထိုးပါ။ <pre> ထဲက ပထမ line ကို <pre><code> နဲ့ line တစ်ကြောင်းတည်းမှာ စရေးပါ။

အဖြေ ကြည့်ရန်
tip.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Tip: always add alt text</title>
</head>
<body>
  <h1>Tip: always add alt text</h1>
  <figure>
    <blockquote>
      <p>An image without alt text is a locked door for screen reader users.</p>
    </blockquote>
    <figcaption>Workshop notes, <cite>Accessible Web Basics</cite></figcaption>
  </figure>
  <p>Our reviewer's rule is simple: <q>no alt, no merge</q>.</p>
  <p>Add the <code>alt</code> attribute, then press <kbd>Ctrl</kbd> + <kbd>S</kbd>.</p>
  <pre><code>&lt;figure&gt;
  &lt;img src="cat.jpg" alt="A cat asleep on a laptop"&gt;
&lt;/figure&gt;</code></pre>
</body>
</html>

Quick Quiz 1 / 3

Tutorial ထဲမှာ <p>Use the <strong> tag here.</p> လို့ escape မလုပ်ဘဲ ရေးလိုက်ရင် browser မှာ ဘာမြင်ရမလဲ။

Quick Quiz 2 / 3

စာကြောင်းတစ်ကြောင်းထဲမှာ တခြားသူ ပြောခဲ့တဲ့ စကားတိုလေးကို ကိုးကားချင်ပါတယ်။ ဘယ်ဟာ သုံးရမလဲ။

Quick Quiz 3 / 3

Indent အပါအဝင် line ငါးကြောင်းရှိတဲ့ code example ကို page ပေါ်မှာ အတိအကျ ပြချင်ပါတယ်။ ဘယ် markup က မှန်လဲ။

မှတ်ထားရမယ့် အချက်များ

  • Quote အရှည်က <blockquote>၊ စာကြောင်းထဲက quote အတိုက <q> ပါ။
  • ကိုးကားချက်ကို blockquote ရဲ့ အပြင်မှာ figure နဲ့ figcaption သုံးပြီး ရေးပါ။
  • Inline code က <code>၊ code block က <pre><code>၊ keyboard key က <kbd> ပါ။
  • Page ပေါ်မှာ HTML ကို စာသားအဖြစ် ပြရင် < နဲ့ & ကို character reference နဲ့ escape လုပ်ပါ။

HTML Living Standard — Sections and Semantics — WHATWG

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Quotes & Code Text | Thuta Learning