# MarkdownリンクはURL内の括弧を正しく解釈しません

**URL:** https://meta.discourse.org/t/markdown-links-do-not-interpret-parenthesis-in-urls-correctly/364844
**Category:** Feature
**Tags:** markdown
**Created:** [2025 年 5 月 5 日午後 2:34 UTC](https://meta.discourse.org/t/markdown-links-do-not-interpret-parenthesis-in-urls-correctly/364844 "2025-05-05T14:34:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [2025 年 5 月 5 日午後 2:34 UTC](https://meta.discourse.org/t/markdown-links-do-not-interpret-parenthesis-in-urls-correctly/364844/1 "2025-05-05T14:34:36Z")

</div>

[URLs in parenthesis do not turn into links](https://meta.discourse.org/t/urls-in-parenthesis-do-not-turn-into-links/30479) での議論の続きです。

[RFC2396 のセクション 2.3](https://www.rfc-editor.org/rfc/rfc2396#section-2.3) には次のように記載されています。

> 未予約文字は、意味を変えずにエスケープできますが、エスケープされていない文字を許可しないコンテキストで URI が使用されない限り、これを行うべきではありません。

括弧はこのような文字です。Discourse に貼り付けられると、これらの文字を使用する URL（たとえば、特定のコンテキストでの高度な検索のクエリ文字列など）は、Markdown URL 構文の一部として誤解され、使用できなくなります。

たとえば、次の URL は、私の協会が発行した合法的に保管された書籍のリストを取得します。

[https://www.depotlegal.be/Depot/form.aspx?SC=KBRVITRINE1#/Search/(query:(AdvancedQuery:(queryGroups:!((queryClauses:!((index:KBR264b\_idx,logical:0,operator:0,otherValue:!n,value:‘petites%20singularités’))](https://www.depotlegal.be/Depot/form.aspx?SC=KBRVITRINE1#/Search/(query:(AdvancedQuery:(queryGroups:!((queryClauses:!((index:KBR264b_idx,logical:0,operator:0,otherValue:!n,value:'petites%20singularit%C3%A9s')))

上記のように貼り付けた場合は機能しますが、 **Markdown リンクとして使用すると** 、機能しなくなります。

`[アンカー](URL)` → [アンカー]([https://www.depotlegal.be/Depot/form.aspx?SC=KBRVITRINE1#/Search/(query:(AdvancedQuery:(queryGroups:!((queryClauses:!((index:KBR264b\_idx,logical:0,operator:0,otherValue:!n,value:‘petites%20singularités’)](https://www.depotlegal.be/Depot/form.aspx?SC=KBRVITRINE1#/Search/(query:(AdvancedQuery:(queryGroups:!((queryClauses:!((index:KBR264b_idx,logical:0,operator:0,otherValue:!n,value:'petites%20singularit%C3%A9s')))

さらに、 **このような URL が電子メールで受信されると** 、結果は次のようになります。

`Recherche avancée - Depot)))),ForceSearch:!t,Grid:!n,Page:0,PageRange:3,QueryString:!n,ResultSize:-1,ScenarioCode:KBRVITRINE1,SearchContext:1))`

ここで、「Recherche avancée - Depot」は正しく解釈されたリンクタイトル（クリック可能）であり、残りはゴミであり、クリック可能なリンクからは欠落しています。(電子メールは HTML で受信するように設定されています) HTML を再構築してもリンクは修正されません。

---

<div class="post-metadata">

### Author: ![Alteras](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alteras/32/179824_2.png) [@Alteras](https://meta.discourse.org/u/Alteras)
#### Post date: [2025 年 5 月 5 日午後 3:23 UTC](https://meta.discourse.org/t/markdown-links-do-not-interpret-parenthesis-in-urls-correctly/364844/2 "2025-05-05T15:23:30Z")

</div>

これはURLとCommonMarkの問題のようですね。末尾に`))))))`を追加して開き括弧と閉じ括弧のバランスを取ると、Markdownリンクが正しく解析されます。

[link](https://www.depotlegal.be/Depot/form.aspx?SC=KBRVITRINE1#/Search/(query:(AdvancedQuery:(queryGroups:!((queryClauses:!((index:KBR264b_idx,logical:0,operator:0,otherValue:!n,value:'petites%20singularit%C3%A9s'))))))))

```plaintext
[link](https://www.depotlegal.be/Depot/form.aspx?SC=KBRVITRINE1#/Search/(query:(AdvancedQuery:(queryGroups:!((queryClauses:!((index:KBR264b_idx,logical:0,operator:0,otherValue:!n,value:'petites%20singularit%C3%A9s'))))))))

```

これは、Markdown-itエンジン（Discourseで使用されている）が従う[CommonMark Spec](https://spec.commonmark.org/0.31.2/#links)の動作と一致します。

> `<`で始まらず、[ASCII制御文字](https://spec.commonmark.org/0.31.2/#ascii-control-character)または[スペース](https://spec.commonmark.org/0.31.2/#space)文字を含まず、バックスラッシュでエスケープされているか、(a)バックスラッシュでエスケープされているか、(b)エスケープされていない括弧のバランスの取れたペアの一部である場合にのみ括弧を含む、空でない一連の文字。（実装ではパフォーマンスの問題を回避するために括弧のネストに制限を設ける場合がありますが、少なくとも3レベルのネストはサポートする必要があります。）

これは[markdown-itデモ](https://markdown-it.github.io/)でもテストできます。

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [2025 年 5 月 5 日午後 3:52 UTC](https://meta.discourse.org/t/markdown-links-do-not-interpret-parenthesis-in-urls-correctly/364844/3 "2025-05-05T15:52:18Z")

</div>

仕様はかなり明確に思えます。ユーザーはアンバランスな括弧もエスケープできます。

`[link](https://www.depotlegal.be/Depot/form.aspx?SC=KBRVITRINE1#/Search/\(query:\(AdvancedQuery:\(queryGroups:!\(\(queryClauses:!\(\(index:KBR264b_idx,logical:0,operator:0,otherValue:!n,value:'petites%20singularit%C3%A9s'\))`

これは

[link](https://www.depotlegal.be/Depot/form.aspx?SC=KBRVITRINE1#/Search/(query:(AdvancedQuery:(queryGroups:!((queryClauses:!((index:KBR264b_idx,logical:0,operator:0,otherValue:!n,value:'petites%20singularit%C3%A9s'))

となります。

これは仕様に記載されている通りに動作しているため、#contribute:featureのディスカッションに移動します。

---

<div class="post-metadata">

### Author: ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)
#### Post date: [2025 年 5 月 9 日午後 12:24 UTC](https://meta.discourse.org/t/markdown-links-do-not-interpret-parenthesis-in-urls-correctly/364844/4 "2025-05-09T12:24:47Z")

</div>

残念ながら、括弧のバランスを取ったり、エスケープしたりすることは、ほとんどの場合行われません 🙂

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [2025 年 5 月 9 日午後 12:32 UTC](https://meta.discourse.org/t/markdown-links-do-not-interpret-parenthesis-in-urls-correctly/364844/5 "2025-05-09T12:32:02Z")

</div>

この件については、別の #Contribute > Bug のトピックがあります。[Ensure that links containing )) still render and work correctly](https://meta.discourse.org/t/ensure-that-links-containing-still-render-and-work-correctly/335205)
