{"action":"created","issue":{"url":"https://api.github.com/repos/tpope/vim-markdown/issues/60","labels_url":"https://api.github.com/repos/tpope/vim-markdown/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/tpope/vim-markdown/issues/60/comments","events_url":"https://api.github.com/repos/tpope/vim-markdown/issues/60/events","html_url":"https://github.com/tpope/vim-markdown/issues/60","id":26812957,"number":60,"title":"Inappropriate Italic","user":{"login":"zeis","id":1945427,"avatar_url":"https://avatars.githubusercontent.com/u/1945427?v=3","gravatar_id":"","url":"https://api.github.com/users/zeis","html_url":"https://github.com/zeis","followers_url":"https://api.github.com/users/zeis/followers","following_url":"https://api.github.com/users/zeis/following{/other_user}","gists_url":"https://api.github.com/users/zeis/gists{/gist_id}","starred_url":"https://api.github.com/users/zeis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zeis/subscriptions","organizations_url":"https://api.github.com/users/zeis/orgs","repos_url":"https://api.github.com/users/zeis/repos","events_url":"https://api.github.com/users/zeis/events{/privacy}","received_events_url":"https://api.github.com/users/zeis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2014-02-03T15:53:56Z","updated_at":"2016-01-30T18:40:38Z","closed_at":null,"body":"First of all thanks for this awesome vim script.\r\n\r\nI'm using the GitHub version. I noticed a little problem with italic text after a single underscore or asterisk.\r\n\r\nThis work as expected:\r\n`foo_bar`\r\n\r\nThis doesn't, and \"bar\" is italicized:\r\n`foo_<any non-alphanumeric character>bar`\r\n\r\nThis is particularly annoying with LaTex formulas :\r\n`$ x_{3} $`\r\n\r\nOne last thing, it would be nice to have no highlighting at all for single underscores: `foo_bar`, most of the times the missing underscore is not an error. Also, using plugins such as vim-surround it is impossible that you forget the closing underscore when you want it.   \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/tpope/vim-markdown/issues/comments/177269192","html_url":"https://github.com/tpope/vim-markdown/issues/60#issuecomment-177269192","issue_url":"https://api.github.com/repos/tpope/vim-markdown/issues/60","id":177269192,"user":{"login":"lifepillar","id":1193314,"avatar_url":"https://avatars.githubusercontent.com/u/1193314?v=3","gravatar_id":"","url":"https://api.github.com/users/lifepillar","html_url":"https://github.com/lifepillar","followers_url":"https://api.github.com/users/lifepillar/followers","following_url":"https://api.github.com/users/lifepillar/following{/other_user}","gists_url":"https://api.github.com/users/lifepillar/gists{/gist_id}","starred_url":"https://api.github.com/users/lifepillar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lifepillar/subscriptions","organizations_url":"https://api.github.com/users/lifepillar/orgs","repos_url":"https://api.github.com/users/lifepillar/repos","events_url":"https://api.github.com/users/lifepillar/events{/privacy}","received_events_url":"https://api.github.com/users/lifepillar/received_events","type":"User","site_admin":false},"created_at":"2016-01-30T18:40:38Z","updated_at":"2016-01-30T18:40:38Z","body":"I have taken a look at how, ehm, Atom does it. It turns out that it seems to follow a simple rule: an underscore starts italics only if it is followed by non-whitespace and if it is at the start of the line or it is preceded by a non-alphanumeric character different from `{` or `}` (braces are excluded because they are used in math formulas). Similarly, an underscore ends italics only if it is preceded by non-whitespace and it is followed by a space or eol.\r\n\r\nThat means that strings like `a_a_a` are *not* italicized at all. But, considering that italicizing inside a word is a relatively infrequent use case, it seems to me an acceptable compromise between simplicity and accuracy. Also, note that things like `$[x]_1$` may be rewritten as `${[x]}_1$`, so it should be possible to write math formulas without triggering italics in most cases.\r\n\r\nSo, my proposal to solve the issue is to use the following syntax rules:\r\n\r\n```\r\nexe 'syn region markdownItalic matchgroup=markdownItalicDelimiter         start=\"\\(^\\|[^0-9A-Za-z_{}]\\)\\@<=\\*\\S\\@=\" end=\"\\S\\@<=\\*\\(\\s\\|$\\)\\@=\" keepend contains=markdownLineStart' . s:concealends\r\nexe 'syn region markdownItalic matchgroup=markdownItalicDelimiter         start=\"\\(^\\|[^0-9A-Za-z_{}]\\)\\@<=_\\S\\@=\" end=\"\\S\\@<=_\\(\\s\\|$\\)\\@=\" keepend contains=markdownLineStart' . s:concealends\r\nexe 'syn region markdownBold matchgroup=markdownBoldDelimiter             start=\"\\(^\\|[^0-9A-Za-z_{}]\\)\\@<=\\*\\*\\S\\@=\" end=\"\\S\\@<=\\*\\*\\(\\s\\|$\\)\\@=\" keepend contains=markdownLineStart,markdownItalic' . s:concealends\r\nexe 'syn region markdownBold matchgroup=markdownBoldDelimiter             start=\"\\(^\\|[^0-9A-Za-z_{}]\\)\\@<=__\\S\\@=\" end=\"\\S\\@<=__\\(\\s\\|$\\)\\@=\" keepend contains=markdownLineStart,markdownItalic' . s:concealends\r\nexe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start=\"\\(^\\|[^0-9A-Za-z_{}]\\)\\@<=\\*\\*\\*\\S\\@=\" end=\"\\S\\@<=\\*\\*\\*\\(\\s\\|$\\)\\@=\" keepend contains=markdownLineStart' . s:concealends\r\nexe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start=\"\\(^\\|[^0-9A-Za-z_{}]\\)\\@<=___\\S\\@=\" end=\"\\S\\@<=___\\(\\s\\|$\\)\\@=\" keepend contains=markdownLineStart' . s:concealends\r\n```\r\n\r\nPlease experiment with them. I may open a pull request if necessary. An explanation of the first rule follows (the others being analogous):\r\n\r\n- `\\(^\\|[^0-9A-Za-z_{}]\\)\\@<=\\*\\S\\@=` matches an asterisk (`\\*`) immediately preceded (`\\@<=`) by either the beginning of the line (`^`) or by any character different from a digit, a letter, an underscore, or a brace (`[^0-9A-Za-z_{}]`); the asterisk must be followed by a non-whitespace character (`\\S`), which is not included as part of the match (`\\@=`).\r\n\r\n- `\\S\\@<=\\*\\(\\s\\|$\\)\\@=` matches an asterisk (`\\*`) immediately preceded (`\\@<=`) by a non-whitespace character (`\\S`) and followed by either a white space (`\\s`) or by the end of the line (`$`), which are not part of the match (`\\@=`)."}}