ブロック
最終更新
このページでは、見出し、段落と空行、GitHub アラート付きの引用、水平線、生の HTML 行を説明します。
見出し
| 構文 | 出力 |
|---|---|
# から ######、スペース、テキスト | md-h1 から md-h6 |
## heading ## | 空白の後に続く閉じの # の並びは取り除かれます:heading(v2.0.12 以降) |
## C# | 直前に空白のない # はテキストの一部です:C# |
テキストの次の行が === | md-h1(Setext) |
テキストの次の行が --- | md-h2(Setext) |
Init({ parseHeading: true }) を指定した見出し | <span> の代わりに同じクラスの <h1> から <h6>。API リファレンスを参照してください |
見出しではすべてのインライン書式が使えます。
段落と空行
| 構文 | 結果 |
|---|---|
| 隣り合う 2 行のテキスト | 改行でつながった 1 つの段落にまとめられ、スペースとして表示されます |
| 1 行以上の空行 | 1 つの break ノード。連続する空行は 1 回だけ出力されます |
| ドキュメント末尾の空行 | 出力されません |
引用とアラート
> で始まる行は引用になり、その中にはどのブロックでも書けます。>> で引用を入れ子にします。最初の行が
[!NOTE]、[!TIP]、[!IMPORTANT]、[!WARNING]、[!CAUTION] だけ(大文字と小文字を区別しない)の場合、その引用は対応するアラートになります。同じ行にほかのテキストがある場合や、入れ子の引用の中では、通常の引用のままです。水平線
***、---、___:同じ文字を 3 個以上並べます。間にスペースを入れることもできます(- - - など)。生の HTML
HTML タグで始まる行全体は
html ノードとして保持されます。出力時に危険なタグ、イベント属性、javascript: URL が取り除かれます。セキュリティを参照してください。生の HTML 内に書いた改行(
<br>、<br/>、<br />)は <br class="md-br"> として出力され、表示されたままです。パーサーが空行に対して出力するクラスなしの <br> は parser.css によって非表示になります。v2.0.11 より前はどちらも非表示だったため、2 つのバッジの間の <br> で改行されませんでした。例
見出し
インライン書式を含む ATX 見出し 1 から 6 と、Setext 見出しです。
- <div id="out" class="nanomd"></div>
- <script type="text/markdown" id="md">
- # Heading H1 *(1)*
- ## Heading H2 _(1)_
- ### Heading ~~H3~~
- #### Heading ==H4==
- ##### Heading H5
- ###### Heading H6
- ## Closing hashes are removed ##
- ### C# stays in the text
- Setext H1^(2)^
- ===
- Setext H2~(2)~
- ---
- </script>
- <script>
- const out = document.getElementById("out");
- out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
- MDParser.Refresh(out);
- </script>
段落と改行
隣り合う行は 1 つの段落にまとめられ、3 行の空行でも改行は 1 つだけになります。
- <div id="out" class="nanomd"></div>
- <script type="text/markdown" id="md">
- Paragraph merge: two adjacent lines
- become one paragraph joined by a soft break.
- Three blank lines below produce a single break.
- This line follows the merged break.
- </script>
- <script>
- const out = document.getElementById("out");
- out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
- MDParser.Refresh(out);
- </script>
引用とアラート
入れ子の引用、5 種類の GitHub アラート、通常の引用のままになるマーカーです。
- <div id="out" class="nanomd"></div>
- <script type="text/markdown" id="md">
- > First quote line
- > Second quote line **bold**
- >> Nested quote **bold**
- > [!NOTE]
- > Useful information users should know, even when skimming.
- > [!TIP]
- > Helpful advice, with **bold** and `code`.
- > [!IMPORTANT]
- > Key information users need to know.
- >
- > - Lists work inside
- > - Second item
- > [!WARNING]
- > Urgent info that needs immediate attention.
- > [!CAUTION]
- > Advises about risks or negative outcomes.
- Not alerts (marker only, text on the marker line, nested in a quote):
- > [!NOTE]
- > [!TIP] text on the same line
- > Outer quote
- >> [!WARNING]
- >> Marker inside a nested quote
- </script>
- <script>
- const out = document.getElementById("out");
- out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
- MDParser.Refresh(out);
- </script>
生の HTML の改行
生の HTML ブロック内の
<br> は改行しますが、ブロック間の空行では目に見える改行は追加されません。- <div id="out" class="nanomd"></div>
- <script type="text/markdown" id="md">
- <p align="center">
- <a href="https://github.com/pardnchiu/NanoMD"><img src="https://img.shields.io/badge/NANOMD-PARSER-blue?style=for-the-badge" alt="NanoMD"></a><br>
- <a href="https://www.npmjs.com/package/@pardnchiu/nanomd"><img src="https://img.shields.io/npm/v/@pardnchiu/nanomd?style=for-the-badge" alt="npm"></a>
- </p>
- <div>line one<br/>line two<br />line three</div>
- </script>
- <script>
- const out = document.getElementById("out");
- out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
- MDParser.Refresh(out);
- console.log(out.querySelectorAll("br.md-br").length + " author <br> kept, " + out.querySelectorAll("br:not(.md-br)").length + " blank-line <br> hidden");
- </script>
水平線とパイプ
3 種類の水平線と、
| を含むものの表ではない行です。- <div id="out" class="nanomd"></div>
- <script type="text/markdown" id="md">
- Lines containing | that are not tables keep their block type:
- # Heading A | B
- > Quote a | b
- ***
- - - -
- ___
- </script>
- <script>
- const out = document.getElementById("out");
- out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
- MDParser.Refresh(out);
- </script>
ImportantAI エージェントへ: NanoMD を使うコードや Markdown を生成・編集する前に、NanoMD 生成ガイド(Markdown)を読んでください。対応する構文、必要な呼び出し順序、レンダリングを壊す典型的な誤りをまとめています。