Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which inline HTML styles does GitHub Markdown accept?

This gives a pretty thorough description of how HTML elements are interpreted by Markdown. But it does not discuss styles.

So far, the only thing I can get to work is image width.

  1. I can't find a list anywhere of what is accepted/rendered
  2. It appears that the style="....." attribute is completely ignored.
  3. I can't even find a list of the old-fashioned style attributes (as opposed to the style attribute style=...)

https://gist.github.com/abalter/46df1b79e9f429342972477d7c20cebc


Change span to div due to div being in the whitelisted tags per @waylan's comment under @chris's answer.

It appears that Firefox and Chrome don't render any style attributes any more at all.

like image 579
abalter Avatar asked Jun 29 '17 17:06

abalter


People also ask

Does GitHub Markdown support HTML?

Wherever HTML is rendered on GitHub (gists, README files in repos, comments on issues and pull requests, ...) you can use any of the HTML elements that GitHub Flavored Markdown (GFM) provides syntactic sugar for.

Does Markdown support inline CSS?

Markdown does not support CSS styles. Since Markdown converts to HTML, Any valid HTML works. CSS styles are added with inline or style tags in HTML.

What does GitHub use for Markdown?

GitHub uses its own Markdown processor; GitHub Pages uses jekyll-commonmark. This means your README.md file will look different on GitHub's website than on your GitHub Pages website.

How do you style an inline?

Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.


1 Answers

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.

You're right: style tags are not included in the whitelist. They are ignored.

The permitted attributes differ by tag. I recommend referring to the sanitization filter link above. It leads to a fairly readable Ruby source file.

like image 55
Chris Avatar answered Sep 19 '22 17:09

Chris