在四开中定义新标注

bos*_*hek 6 css quarto

在四开本中定义新标注的最佳调用方式是什么?我可以像这样修改默认标注:

---
format: 
  html: 
    theme:
      - custom.scss
---


::: {.callout-tip appearance="minimal"}
Some wild callout
:::
Run Code Online (Sandbox Code Playgroud)

然后是一个.scss像这样的文件:

/*-- scss:defaults --*/
$callout-background: #ff5bbb;

/*-- scss:rules --*/

.callout {
    background-color:$callout-background;
 }
Run Code Online (Sandbox Code Playgroud)

但适用于所有后续标注。定义新的最好方法是什么?

sha*_*fee 16

创建新标注块的一种选择是使用callout所需规则重新定义 CSS 类。

这里我定义了一个新的标注块,callout-tweet重新定义了callout. 但这个重新定义的标注块不包含标注图标,即使使用callout-appearance: default. 因此,为了获得图标,我添加了另一个类.icon

因此,callout-icon: false或者true在yaml中,不会影响这个新定义的callout-block( callout-tweet)。默认情况下,它会在没有图标的情况下呈现,要获取图标,您需要使用.icon它。

---
title: "New Callout Block"
format: 
  html: 
    theme: callout_tweet.scss
---

::: {.callout-tweet}
Tweet from the callout tweet
:::

::: {.callout-tweet .icon}
Tweet from the callout tweet with icon
:::

::: {.callout-tip}
Some wild callout
:::

::: {.callout-warning}
Some wild callout
:::
Run Code Online (Sandbox Code Playgroud)

callout_tweet.scss

/*-- scss:defaults --*/
$border-color-left: #0dcaf0 !default;
$icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-twitter" viewBox="0 0 16 16">  <path d="M5.026 15c6.038 0 9.341-5.003 9.341-9.334 0-.14 0-.282-.006-.422A6.685 6.685 0 0 0 16 3.542a6.658 6.658 0 0 1-1.889.518 3.301 3.301 0 0 0 1.447-1.817 6.533 6.533 0 0 1-2.087.793A3.286 3.286 0 0 0 7.875 6.03a9.325 9.325 0 0 1-6.767-3.429 3.289 3.289 0 0 0 1.018 4.382A3.323 3.323 0 0 1 .64 6.575v.045a3.288 3.288 0 0 0 2.632 3.218 3.203 3.203 0 0 1-.865.115 3.23 3.23 0 0 1-.614-.057 3.283 3.283 0 0 0 3.067 2.277A6.588 6.588 0 0 1 .78 13.58a6.32 6.32 0 0 1-.78-.045A9.344 9.344 0 0 0 5.026 15z"/></svg>') !default;

$background-color: #bfe4eb !default;


/*-- scss:rules --*/

div.callout-tweet.callout {
  border-left-color: $border-color-left;
}

div.callout-tweet.callout-style-default>.callout-header {
  background-color: $background-color;
}

.callout-tweet.icon .callout-icon {
  display: unset !important;
}

div.callout-tweet.icon.callout-captioned .callout-icon::before {
  background-image: $icon;
}

.callout-tweet.icon.callout-style-default div.callout-icon-container {
  padding-top: 0.1em;
  padding-right: 0.35em;
}
Run Code Online (Sandbox Code Playgroud)

标注推文


现在,新定义的标注块仍然存在一个问题,即如果您使用collapse=true它,它会变得可折叠,但不会显示可折叠图标。要解决此问题,无需再大惊小怪,只需在 in div 标头后添加已定义的标注类型即可.callout-tweet

---
title: "New Callout Block with collapse sign"
format: 
  html: 
    theme: callout_tweet.scss
---

::: {.callout-tweet collapse=true}
Tweet from the callout tweet with icon
:::

::: {.callout-tweet .callout-warning collapse=true}
Tweet from the callout tweet
:::

::: {.callout-tweet .icon .callout-note collapse=true}
Tweet from the callout tweet with icon
:::
Run Code Online (Sandbox Code Playgroud)

折叠标注推文


  • 目前无法创建新的标注(但可以预见)。我最终在我的四开扩展 https://github.com/ginolhac/unilur 中为我破解了最少使用的标注(`callout-caution`)。css是由lua过滤器注入的。此处渲染的文件:https://ginolhac.github.io/unilur/example.html (2认同)