Rmarkdown 中的文本着色失败:color-text.lua 在 RevealJS 中不起作用

Colorizing text in Rmarkdown fails: color-text.lua doesn't work in RevealJS

我正在尝试通过 r-markdown 制作 revealjs 幻灯片。此外,我想使用 lua 中建议的过滤器使用简单的符号(即类似 markdown 的符号)为一些文本着色 Using a Pandoc Lua filter R Markdown 食谱

但是,生成的幻灯片没有着色。在下面的幻灯片中,单词 red 应该是红色,blue 应该是蓝色,但实际上不是。

此外,简单的符号 [blue]{color="blue"} 意外地转换为 <span color="blue">blue</span>,而不是理想的 HTML 代码 <span style="color: blue;">blue</span>

有人能告诉我我错过了什么吗...?

---
title: "title"
output: 
  bookdown::html_document2:
    base_format: "function(..., number_sections) revealjs::revealjs_presentation(...)"
    theme: moon
    pandoc_args: 
      - "--lua-filter=color-text.lua"
    transition: default
    background_transition: zoom
    center: true
    incremental: true
    number_sections: true
    toc: true
    toc_depth: 3
    fig_caption: TRUE
    #dev: cairo_pdf
    self_contained: false
    reveal_plugins: ["zoom", "notes", "menu"] #"search"
    reveal_options:
      slideNumber: true
      previewLinks: true
      margin: 0.1
      menu:
        numbers: true
always_allow_html: yes
link-citations: yes
---

## First

we define a Lua filter and write it to
the file `color-text.lua`.

```{cat, engine.opts = list(file = "color-text.lua")}
Span = function(span)
  color = span.attributes['color']
  -- if no color attribute, return unchange
  if color == nil then return span end

  -- tranform to <span style="color: red;"></span>
  if FORMAT:match 'html' then
    -- remove color attributes
    span.attributes['color'] = nil
    -- use style attribute instead
    span.attributes['style'] = 'color: ' .. color .. ';'
    -- return full span element
    return span
  elseif FORMAT:match 'latex' then
    -- remove color attributes
    span.attributes['color'] = nil
    -- encapsulate in latex code
    table.insert(
      span.content, 1,
      pandoc.RawInline('latex', '\textcolor{'..color..'}{')
    )
    table.insert(
      span.content,
      pandoc.RawInline('latex', '}')
    )
    -- returns only span content
    return span.content
  else
    -- for other format return unchanged
    return span
  end
end
```

Now we can test the filter with some text in brackets with
the `color` attribute, e.g.,

> Roses are [red and **bold**]{color="red"} and
> violets are [blue]{color="blue"}.

是的,我可以,你也可以:你的问题已经有了答案。 你是

trying to make revealjs

因此,当您 运行 您的代码时,您的 lua 过滤器不会产生任何有趣的东西,只是在倒数第二行执行 return span 而不是所需的更改。

因此,一个简单的更改就是您的解决方法。
替换:
if FORMAT:match 'html' then

if FORMAT:match 'html' or FORMAT:match 'revealjs' then
这样做,lua 过滤器完成了它的工作,我得到了所需的输出,格式正确。