Mix Github markdown language with CSS

拈花ヽ惹草 提交于 2019-12-31 05:42:09

问题


How can I add CSS to github's markdown language?

I've been able to do so by using the style property inside html tags, like:

<p style="text-align: center;">This is some random text</p>

But if I move the css to the beginning, like:

<style>
  p {
    text-align: center;
  }
</style>

<p>This is some random text</p>

Github doesn't recognize it, and just writes to the screen the css code.

I'm using Atom, and the package Markdown Preview actually recognizes this correctly, even though on the remote repository it shows wrong. And so does the Google Chrome extension Markdown Preview Plus.

Is there a way to do this? Writing css within html tags just feels plain wrong.


回答1:


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.



来源:https://stackoverflow.com/questions/40261461/mix-github-markdown-language-with-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!