Codemirror: [markdown] underscores in URLs produce italicizing

Created on 14 Oct 2016  ·  5Comments  ·  Source: codemirror/CodeMirror

http://goo.com/_foo bar baz [foo](bar)

gets rendered with the _ starting an italicized section, whereas it should just be part of the URL, as rendered below:

http://goo.com/_foo bar baz foo

All 5 comments

The markdown mode doesn't highlight URLs, so I guess you're using the GFM mode. That is currently implemented as an overlay over the Markdown mode, which means it can't influence the tokenizing the Markdown mode produces. This is the cause of a bunch of problems, but it's not something that can be addressed without rewriting the whole GFM mode. Since this is contributed code, I don't really have any plans to do so myself on the short term.

I wasn't talking about any special highlighting of the URL.

We are currently using this config for markdown mode:

  {
    name: 'markdown',
    underscoresBreakWords: false,
    fencedCodeBlocks: true,
    strikethrough: true
  },

The problem, as described above, is that when you paste my example into https://codemirror.net/mode/markdown/ the _ starts an italicized section, which here is undesirable. The desired fix would be some adjustment of the tokenization etc. in the markdown mode so that underscores in contexts like this (e.g. preceded by / and maybe other characters) don't trigger the start of italicizing.

I see. But then is there any reason to expect this underscore not to start an emphasis span? The CommonMark spec suggests treating punctuation (/ in this case) the same as whitespace.

If the _ is within a URL, I'd think the engine should be smart enough to know we (as end-users) are not declaring an initialization for italics. This is also just visible in the editor, which apparently is being used by Gist for GitHub. However, when a Gist is saved, the italics are not rendered.

A _simple_ way might be to determine if the string starts with http(s):// and everything up to the white space is considered part of the URL.

Likely need more work to get right, but something _similar_ to this... 🤔 🤷‍♂️

screen shot 2019-01-08 at 09 43 43

I think autolinks would be the right thing to use here, and inside these _ shouldn't start an italic span.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Azmisov picture Azmisov  ·  4Comments

KnightYoshi picture KnightYoshi  ·  6Comments

blgm picture blgm  ·  4Comments

ellisonbg picture ellisonbg  ·  4Comments

hameddhib-dydu picture hameddhib-dydu  ·  5Comments