简体   繁体   English

如何将样式应用于GitBook中的代码块?

[英]How do you apply a style to code blocks in GitBook?

I want to change the appearance of the code sections generated using ``` and ` markdown. 我想改变使用```和`markdown生成的代码段的外观。

My book.json is 我的book.json是

{
    "styles": {
        "website": "styles/website.css"
    }
}

and my styles/website.css says about the simplest thing I could come up with to test: 和我的styles / website.css谈到我可以提出的最简单的测试方法:

/* CSS for website */

code {
  background-color: red;
}

But my GitBook code blocks don't have a red background: https://lokathor.gitbooks.io/haskell-stuff/content/general/using_st.html 但我的GitBook代码块没有红色背景: https ://lokathor.gitbooks.io/haskell-stuff/content/general/using_st.html

When I open the page and look in chrome's dev console, there are code tags and so on, such as <code>runST :: (forall s. ST sa) -&gt; a</code> 当我打开页面并查看chrome的开发控制台时,会有代码标签等,例如<code>runST :: (forall s. ST sa) -&gt; a</code> <code>runST :: (forall s. ST sa) -&gt; a</code> , so I'm not clear on what's wrong. <code>runST :: (forall s. ST sa) -&gt; a</code> ,所以我不清楚什么是错的。 I don't really know CSS and I don't really know much GitBook, so it seems like I could be doing just about anything wrong. 我真的不知道CSS,我真的不太了解GitBook,所以看起来我可能做的任何错误。

Try this in your CSS file: 在CSS文件中试试这个:

.book .book-body .page-wrapper .page-inner section.normal code {
  background-color: red;
}

The html generated by gitbook uses other elements, which contain the code, p, div, etc. elements, so you have to "navigate" down to these. 由gitbook生成的html使用其他元素,其中包含代码,p,div等元素,因此您必须“导航”到这些元素。

Here's what worked for me for targeting the <p> and <h1> tags: 以下是针对<p><h1>标记的工作原理:

.normal .markdown-section p
{
  //style
}

I couldn't do some things to the website's CSS, because of whatever template they have in place (I suspect), but I was able to do text-transform that way. 我不能对网站的CSS做一些事情,因为他们有任何模板(我怀疑),但我能够以这种方式进行文本转换。 I'm hoping to be able to alter the pdf stylesheet. 我希望能够改变pdf样式表。

It turns out that using the PDF options in book.json is much more effective. 事实证明,使用book.json的PDF选项更有效。
See this link which details various configurations options for your book, including PDF page size, font size, and margins. 请参阅此链接 ,其中详细介绍了图书的各种配置选项,包括PDF页面大小,字体大小和边距。

{
"pdf": {
    "fontSize": 17,
    "margin": {
      "left": 80,
      "right": 80,
      "bottom": 60
    }
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM