Не удается раскрасить текст в Rmarkdown: color-text. lua не работает в RevealJS - PullRequest
0 голосов
/ 17 апреля 2020

Я пытаюсь сделать revealjs слайды через r-markdown. Кроме того, я хотел бы раскрасить некоторые тексты с помощью простой нотации (например, нотации, подобной уценке), используя фильтр lua, как предложено в Используя фильтр Pando c Lua из R Markdown Кулинарная книга .

Однако полученные слайды не окрашены. На следующем слайде слово красный должно быть красным, а синий должно быть синим, но на самом деле это не так.

enter image description here

Кроме того, простая запись [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"}.
...