# 带下划线的链接被连字符包围时渲染不正确

**URL:** https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913
**Category:** Bug
**Created:** [2018年九月24日 07:52 UTC](https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913 "2018-09-24T07:52:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mcwumbly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcwumbly/32/103861_2.png) [@mcwumbly](https://meta.discourse.org/u/mcwumbly)
#### Post date: [2018年九月24日 07:52 UTC](https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913/1 "2018-09-24T07:52:13Z")

</div>

I’m not sure if this is a commonmark issue, a markdown-it issue, or a Discourse issue, but when sharing the link in [this post](https://meta.discourse.org/t/how-not-to-structure-your-database-backed-web-applications/97912), I noticed this edge case with the automatic link detection where the sequence `-_foo_-` breaks it.

This was the original link:

```plaintext
https://blog.acolyer.org/2018/06/28/how-_not_-to-structure-your-database-backed-web-applications-a-study-of-performance-bugs-in-the-wild/

```

Here’s a simplified example:

```plaintext
https://example.org/foo-_bar_-baz

```

And rendered:

[https://example.org/foo-\_bar\_-baz](https://example.org/foo-_bar_-baz)

(And as an image for good measure):

![link-detection-issue-edge-case](https://global.discourse-cdn.com/meta/original/3X/6/d/6d96acc9c13345b491ac847cfb5c083fe582bc41.png)

* * *

As a workaround, to make a link like this go to the right destination, you can always just use a _real_ markdown link like so:

```plaintext
[foo _bar_ baz](https://example.org/foo-_bar_-baz)

```

[foo _bar_ baz](https://example.org/foo-_bar_-baz)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2018年九月24日 15:05 UTC](https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913/2 "2018-09-24T15:05:53Z")

</div>

This was already opened in the context of a Twitter user with similar character patterns in username, rendering linking to that twitter profile very difficult.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2018年九月24日 15:09 UTC](https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913/3 "2018-09-24T15:09:06Z")

</div>

Known issue with commonmark, we can continue discussion here:

> [@Links broken with (at least) two underscores in URL](https://meta.discourse.org/t/twitter-links-broken-with-at-least-two-underscores-in-username/72976/7):
>
> That’s a known issue: It’s possible to fix, but not easy. Workaround available. Correct solution is to make linkifier part of tokenizer process. That’s expensive (for example, email lookahead check for every character). Tradeoff is to listen : then do look behind for http(s), and lookahead for the rest. That’s not universal, but will cover all real cases: http/https links will be parsed with other tokens, with higher priority than emphasis everything else will be detected via text scan & r…
