v2.0.16

リンクとメディア

最終更新


このページでは、インラインリンク、参照リンク、相対リンク、裸の URL と自動リンク、画像のサイズ指定、動画、YouTube や Vimeo の埋め込みを説明します。

リンク


構文説明
[text](https://example.com)インラインリンク。新しいタブで開きます
[text](https://example.com "title")タイトルはダブルクォートでもシングルクォートでも書けます
[![alt](badge.svg)](https://example.com), [![alt](badge.svg)][ref], [`code` and $x$](https://example.com)リンクテキストには、インラインでも参照でも、画像(サイズ指定付き)、インラインコード、インライン数式を含められます
[text](./a.md), [text](../b.md), [text](/c), [text](#anchor)相対パスとアンカー
[mail](mailto:a@example.com), [call](tel:+886912345678)mailto: と tel: のリンクは target="_blank" なしで同じページで開きます。参照定義でも使えます
https://example.com裸の URL はリンクになります。末尾の句読点はテキストに残ります
<https://example.com>自動リンク。山括弧は構文の一部で、描画されません(v2.0.12 以降)
[text][ref] と [ref]: https://example.com "title"参照リンク。ref は大文字と小文字を区別せず、定義行は出力されません

その他のスキーム(javascript: や ftp: など)の URL はリンクにならず、プレーンテキストのまま残ります。スキームは小文字である必要があり(MAILTO: はテキストのまま)、裸の mailto: アドレスはリンクになりません。

画像と動画


構文出力
![alt](a.png "title")<img class="md-img">
![a](a.png)(300x200)幅 300px、高さ 200px
![a](a.png)(50%x)幅のみ。% 付きの数値はパーセンテージです
![a](a.png)(x120)高さのみ
![a](a.png)(120)幅と高さが同じ
![a](a.mp4), ![a](a.mov)<video controls>。サイズ指定も同じように使えます

埋め込みプレーヤー


リンク先が YouTube(youtube.com/watch?v=、youtu.be/、/embed/)または Vimeo の場合、リンクの後に埋め込みプレーヤーが続きます。

例


リンク


インラインリンク、裸の URL、自動リンク、URL を囲む装飾、相対パス、タイトルです。
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. Links: [NanoMD](https://nanomd.pardn.io), bare URL https://github.com/pardnchiu/NanoMD.
  4. Autolinks: <https://nanomd.pardn.io>, <https://github.com/pardnchiu/NanoMD>
  5. Styles around bare URLs: **https://nanomd.pardn.io**, ~~https://github.com~~, *https://nanomd.pardn.io*, _https://github.com_
  6. Relative: [same dir](./other.md), [parent](../README.md), [root](/docs/a.md), [anchor](#md-fn-1), [javascript: rejected](javascript:alert(1))
  7. Same page: [mail](mailto:dev@pardn.io), [call](tel:+886912345678), bare mailto:dev@pardn.io
  8. Titles: [NanoMD](https://nanomd.pardn.io "NanoMD docs"), [GitHub](https://github.com/pardnchiu/NanoMD 'single-quoted title')
  9. </script>
  10. <script>
  11. const out = document.getElementById("out");
  12. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  13. MDParser.Refresh(out);
  14. </script>
ライブプレビュー · @pardnchiu/nanomd@2.0.16

リンク付き画像


リンクテキスト内の画像はバッジのようにクリックできる画像になります。リンクテキスト内のインラインコードと数式も描画されます。
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. Badge: [![Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
  4. Image with text: [dog ![dog](/static/image/dog-7128749_640.jpg)(x40) photo](https://nanomd.pardn.io)
  5. Code and math: [`Parse()`](https://nanomd.pardn.io/parser-api), [formula $E=mc^2$](https://nanomd.pardn.io/syntax-inline)
  6. </script>
  7. <script>
  8. MDParser.Init({ enable: { latex: true } }).then(() => {
  9. const out = document.getElementById("out");
  10. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  11. MDParser.Refresh(out);
  12. console.log(out.querySelectorAll("a > img").length, "linked images");
  13. });
  14. </script>
ライブプレビュー · @pardnchiu/nanomd@2.0.16

参照リンク


大文字と小文字を区別しないラベル、タイトル、相対リンク先、参照を囲む装飾、未定義のラベルです。
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. References: [NanoMD][nanomd], [different case][NANOMD], [with title][gh], [relative][rel], **[bold around][nanomd]**, [undefined][missing]
  4. [nanomd]: https://nanomd.pardn.io
  5. [gh]: https://github.com/pardnchiu/NanoMD "GitHub source"
  6. [rel]: ./other.md
  7. </script>
  8. <script>
  9. const out = document.getElementById("out");
  10. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  11. MDParser.Refresh(out);
  12. </script>
ライブプレビュー · @pardnchiu/nanomd@2.0.16

画像と動画


タイトル、両方のサイズ、幅のみ、高さのみ、正方形を指定する単一の値、動画です。
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. Image: ![dog](/static/image/dog-7128749_640.jpg "dog")
  4. Size: ![flamingo](/static/image/flamingo-9190160_640.jpg)(300x200)
  5. Width only: ![hippopotamus](/static/image/hippopotamus-9147023_640.jpg)(50%x)
  6. Height only: ![stilt](/static/image/stilt-8593487_640.jpg)(x120)
  7. Square: ![corn](/static/image/corn-9135131_640.jpg)(120) one value sets both
  8. Video: ![video](/static/image/233867_tiny.mp4 "video title")(320x)
  9. </script>
  10. <script>
  11. const out = document.getElementById("out");
  12. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  13. MDParser.Refresh(out);
  14. </script>
ライブプレビュー · @pardnchiu/nanomd@2.0.16

YouTube と Vimeo


YouTube や Vimeo へのリンクと裸の URL には埋め込みプレーヤーが付きます。
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. YouTube: [Me at the zoo](https://www.youtube.com/watch?v=jNQXAC9IVRw)
  4. YouTube bare URL: https://youtu.be/jNQXAC9IVRw
  5. Vimeo: [The New Vimeo Player](https://vimeo.com/76979871)
  6. </script>
  7. <script>
  8. const out = document.getElementById("out");
  9. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  10. MDParser.Refresh(out);
  11. </script>
ライブプレビュー · @pardnchiu/nanomd@2.0.16



ImportantAI エージェントへ: NanoMD を使うコードや Markdown を生成・編集する前に、NanoMD 生成ガイド(Markdown)を読んでください。対応する構文、必要な呼び出し順序、レンダリングを壊す典型的な誤りをまとめています。