0

I've been trying to figure this out by observing various README files on public repositories.

If seen stuff like encapsulating a function with ```cs on top and ``` on bottom.

Then in some places I've seen bash or diff instead of cs.

But I haven't been able to apply any of these options in my own README file and get them to produce the same colors.

Does it possibly have anything to do with the .gitattributes file?

halfer
  • 19,824
  • 17
  • 99
  • 186
goodvibration
  • 5,980
  • 4
  • 28
  • 61
  • Can you link to an example? – Jonathan Hall Jul 11 '19 at 12:47
  • [.gitattributes](https://git-scm.com/docs/gitattributes) is obviously unrelated. – Jonathan Hall Jul 11 '19 at 12:47
  • @Flimzy: Sure - https://github.com/github/linguist#application-usage (that's where I also looked for a clue, though according to your second comment, it clearly has nothing to do with my issue). – goodvibration Jul 11 '19 at 12:47
  • That's just syntax highlighting for a codeblock. Look at [the source](https://raw.githubusercontent.com/github/linguist/master/README.md) to see how it's done. – Jonathan Hall Jul 11 '19 at 12:49
  • Possible duplicate of [How to add color to Github's README.md file](https://stackoverflow.com/questions/11509830/how-to-add-color-to-githubs-readme-md-file) – Jonathan Hall Jul 11 '19 at 12:50
  • @Flimzy: Yes, that's exactly what I did (where'd you think I got the `bash` from?). But how on earth does GitHub know how to apply colors here? – goodvibration Jul 11 '19 at 12:50
  • Are you asking how syntax highlighting works, or how GitHub converts markdown to HTML? – Jonathan Hall Jul 11 '19 at 12:51
  • @Flimzy: No, I'm just asking what to do in my README file so that GitHub will color function and variable names in a nice manner. – goodvibration Jul 11 '19 at 12:51
  • You just indicated you already know the answer to that. – Jonathan Hall Jul 11 '19 at 12:52
  • @Flimzy: I don't. I said it didn't work for me. And the answer you've linked - that's where I got the `diff` from - that also didn't work. – goodvibration Jul 11 '19 at 12:52
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example. – Jonathan Hall Jul 11 '19 at 12:53

1 Answers1

2

When you have a JavaScript snippet you can highlight the content via:

```javascript
content
```

(Read more here: https://help.github.com/en/articles/creating-and-highlighting-code-blocks)


The .gitattributes file is not needed for the README.md. It is needed when GitHub (Linguist) highlights a whole file in a wrong syntax


Last but not least, syntax highlighting in GitHub is made possible by the GitHub project linguist.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
MarvinJWendt
  • 2,357
  • 1
  • 10
  • 36
  • "GitHub project linguist" - is that the same one I just looked at (provided as an example in response to one of the comments to my question)? – goodvibration Jul 11 '19 at 12:54
  • Yes it is, GitHub linguist is the algorithm working behind syntax highlighting on GitHub. And Yes you post a programming language behind the three `. A list of all possible languages is here: https://github.com/github/linguist/blob/master/lib/linguist/languages.yml – MarvinJWendt Jul 11 '19 at 12:58
  • Oh and btw `bash` is for console commands (Linux) and `diff` is for GitHub diffs (which is also kinda an own language) – MarvinJWendt Jul 11 '19 at 13:02
  • Is there a way to use this per word (or some part of the line)? Or is it applicable only an entire line (or block of lines)? – goodvibration Jul 11 '19 at 13:18
  • AFAIK this is only possible in code blocks. A little sneaky trick tho is, that you can make a screenshot of your desired look and embed that screenshot as a little image in your `README`. But you should only do this if it's really necessary. – MarvinJWendt Jul 11 '19 at 14:12