在 Scribble 中更改字体颜色(html 后端)

Change font color in Scribble (html backend)

有什么方法可以使用 HTML 后端更改 scribble 中的字体颜色?

(更具体地说,我想在图书馆的手册中放置一个大的红色警告标签。)

正如 Alexis 提到的,您可以将 class 与级联样式 Sheet (CSS) 配对使用,如下所示:

<head>
   <link rel="stylesheet" type="text/css" href="mystyle.css">
   <!-- that's to link our styles to the webpage. -->
</head>
<body>
   <!-- some time later... -->
   <p class = "example">test</p> 
   <!-- the rest of the website -->

mystyle.css中:

.example{ /* select all tags with the "example" class */
     color: #FF0000; /* change font color using hex value */
     background-color: #552222; /* change background color using hex value */
}

现在,如果我们能够使用多个文件,那就太好了。但是,如果您想将所有内容都放在一个文件中,我们可以在 <style> 标签中发送相同的信息:

<head>
   <!-- no need to link our styles, since they're embedded in the webpage. -->
</head>
<body>
   <style>
     .example{ /* select all tags with the "example" class */
        color: #FF0000; /* change font color using hex value */
        background-color: #552222; /* change background color using hex value */
     }
   </style>
   <!-- some time later... -->
   <p class = "example">test</p> 
   <!-- the rest of the website -->

还有另一种嵌入方法,但您不应该使用它。曾经。这始终是正确的方法。

如果您需要 CSS 方面的更多信息,请参阅 http://www.w3schools.com/css/css_examples.asp

手动创建 style struct containing an attributes 属性 似乎可行:

#lang scribble/base

@(require scribble/core
          scribble/html-properties)

@para[#:style (style #f `(,(attributes '([style . "color:blue;"]))))]{blue text}

事实证明,您可以直接在 scribble 中执行此操作,而无需使用依赖于后端的解决方案。诀窍是使用 styles that have color-property.

使用 elem to set the style, ,您可以创建一个 colorize 函数来设置文本的颜色。

(define (colorize #:color c . content)
  (elem #:style (style #f (list (color-property c)))
        content))

然后你可以这样使用它:

@colorize[#:color "red"]{WARNING}

还有background-color-property可以告设置文字背景