Which Inline HTML Styles Does Github Markdown Accept

Github markdown - cannot change any style by inline-css and class

This is not possible due to security concerns.

In fact, it is not related to Markdown, but rather GitHub's post-processing of all user provided markup, as documented in github/markup. The conversion of Markdown to HTML happens in step 1, which leaves your tags and attributes intact. However, of note is step 2:


  1. The HTML is sanitized, aggressively removing things that could harm you and your kin—such as script tags, inline-styles, and class
    or id attributes.

A previous version of that document linked to the code for the HTML sanitizer they were using at the time. Whether they are still using that sanitizer or a different one is currently unknown. However, a review of the code for that sanitizer makes it clear that they are striping out all user defined styles. If they have updated to a new sanitizer, it is likely that it has been made more strict.

In conclusion, it is clear that GitHub does not allow any user-defined styles to be used on their site.

Do style tags work in Markdown?

Just tested it myself.

<style>
#foo {color: red}
</style>

<p id="foo">foo</p>

<p style="color: blue">bar</p>

The above rendered to:

#foo {color: red}
<p>foo</p>

<p>bar</p>

GitHub strips style tags and attributes preventing you from changing the style on their pages. This is probably for security reasons. If you could inject css into GitHub pages, you could easily launch a phishing attack.

Mix Github markdown language with CSS

After GitHub converts Markdown to HTML,

The HTML is sanitized, aggressively removing things that could harm you and your kin—such as script tags, inline-styles, and class or id attributes. See the sanitization filter for the full whitelist.

style tags are not included in GitHub's whitelist, so they are removed. I'm actually surprised that inline style attributes work; they don't seem to be included in the whitelist, either, and are explicitly mentioned in the previous paragraph.

In any case, GitHub does not permit arbitrary HTML to be included in Markdown.

Custom css file for readme.md in a Github repo

GitHub does not allow for CSS to affect README.md files through CSS for security reasons (as if you could inject CSS into a ReadMe, you could easily launch a phishing attack). This includes both stylesheets referenced through <link rel> and inline styles used with <style>.

The readmes are in markdown syntax, so some styling can be done, such as adding colours through placeholder images, just like here on StackOverflow. For example, you can add red squares #f03c15 with the following:

- ![#f03c15](https://placehold.it/15/f03c15/000000?text=+) `#f03c15`

You can also make use of things like diff, json, html, js and css to affect text colouring.

Inline code syntax highlighting in GitHub markdown?

GitHub comments, wikis, README.md etc. use GFM, essentially CommonMark with some extensions. There it's not possible. (Follow the link to see whether anything has changed, but don't hold your breath because nothing has in the last decade.)

However, GitHub Pages uses Jekyll and by extension kramdown where you can use:

`x = 4`{:.ruby}

P.S. If you happen to use pandoc, the syntax is:

`x = 4`{.ruby}


Related Topics



Leave a reply



Submit