10

When editing a question on History of Science and Mathematics, I observed that a link which was not rendered in the post was hyperlinked in the edit preview (see pictures below). I tried reproducing it in the Sandbox to see if this also happens when the post is posted for the first time and observed the same.

It seems to be a bug after the shift to CommonMark, leading to the different rendering of links on client and server-side. A link following a special character (without any space) is not hyperlinked in the post but is hyperlinked in the preview. A link separated from the special character with a white space appears to have no such problem. (see pictures below and my Sandbox post).

Link not hyperlinked in post

Link not hyperlinked in post

Same link hyperlinked in preview

Link hyperlinked in preview

4

Thanks for highlighting this.

We're using different renderers for the preview and for rendering Markdown content server-side and both use their own, built-in mechanism to detect links. Ideally, both would behave exactly the same. Unfortunately they don't quite match perfectly all the time.

I've got a bugfix about to go out that's trying to make both renderers behave more alike. We won't attempt to make both behave exactly equivalent and there will always be edge cases where the preview is showing something slightly different from the server-side rendered post. I know this can be annoying at times. However, the effort it'd take to get this perfect outweighs the benefit in my view, especially given that the workaround is simple: Add a space after interpunction characters (as you should do for proper interpunction anyway, in my humble opinion) or use proper Markdown link syntax to denote your hyperlinks. On top of that, I want to avoid introducing bugs where something gets incorrectly auto-linked.

With the bugfix in place, a URL appearing right after a colon :, a semicolon ;, a hash # without any space will be rendered as a hyperlink in the preview and on the server.

| improve this answer | |
  • 1
    Thanks for the update Ham. I wonder why it would be hard to have the same renderer on two places. Isn't it simply copy paste? – Luuklag Jul 23 at 10:45
  • 1
    @Luuklag unfortunately it isn't. In the preview, we're using linkify-it which comes bundled with markdown-it. It's all written in JavaScript and based on regular expressions. On the server, we're using markdig's AutoLink extension. This one's using a quite different approach altogether. Auto-detecting links is more complicated than it seems on the surface, that's why I'd prefer to leave link detection to those libraries as much as we can. – Ham Vocke Jul 23 at 11:06
  • 1
    Why don't you use Node to run the same Javascript code on the server and client? – Ian Ringrose Jul 23 at 12:12
  • The issue now seems to be with dot(.). See this post for example. – Kulfy Aug 1 at 15:32
  • Note I reported also <s>links</s> are autocompleted on preview but not rendered when posted. It was marked as dupe of this, while this answer is not solving that case because the exception has been made for colon, semicolon and hash. – fedorqui 'SO stop harming' Aug 5 at 11:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .