atom / language-gfm

GitHub Flavored Markdown in Atom
MIT License
101 stars 107 forks source link

Better support for info strings in fenced code blocks containing more than just the language #199

Open fasiha opened 7 years ago

fasiha commented 7 years ago

Prerequisites

Better support for info strings in fenced code blocks containing more than just the language

If I start a fenced code block, and add an info string like py, the fenced code block will be highlighted as Python. So far so good. But if I make it py base.py, e.g., Atom stops formatting the code block as Python because language-gfm parses the entire info string, including trailing characters, as the language name (a guess).

Consider interpreting the info string’s text only up to the the first whitespace/punctuation as the language specifier?

Steps to Reproduce

  1. Create a fenced code block with ticks.
  2. Add a language specification to after the opening triplet and confirm that the code is highlighted as that language
  3. Add a space and some more text.

Expected behavior: The code block retains the syntax highlighting

Actual behavior: The code block is shown as a plain codeblock as if it lacked an info string

Reproduces how often: 100%

Versions

Atom:

Atom    : 1.16.0
Electron: 1.3.13
Chrome  : 52.0.2743.82
Node    : 6.5.0

apm:

apm  1.16.1
npm  3.10.5
node 6.9.5 x64
python 2.7.13
git 2.9.2

macOS Sierra.

kachkaev commented 6 years ago

Same here in Atom 1.26.0 on macOS, even in Safe Mode. screen shot 2018-04-19 at 16 42 57

source
Example code listing

````markdown
# fenced code block without arguments
```js
const x = 42; // highlighting works
```

# fenced code block with arguments
```js {something=something}
const x = 42; // no highlighting here
```
````

Looks like the same code is used to highlight stuff on Github. Check out these examples:

```js
const x = 42;
↓
```js
const x = 42;

ok


```js {something=something}
const x = 42;
↓
```js {something=something}
const x = 42;

ok


````markdown
# fenced code block without arguments
```js
const x = 42;

fenced code block with arguments

const x = 42;

# fenced code block without arguments
```js
const x = 42;

fenced code block with arguments

const x = 42;

_highlighting inside ` ```js {something=something}` does not happen_

If I manage to fix this, would the change propagate to GitHub.com? I'd like to get online highlighting working [in this README](https://github.com/gicentre/litvis/blob/2ba014df51700010cc52f5626f85ac78842cfc7f/documents/README.md).