【发布时间】:2020-04-17 15:29:44
【问题描述】:
我正在尝试通过r-markdown 制作revealjs 幻灯片。另外,我想使用lua 过滤器以简单的表示法(即类似降价的表示法)为一些文本着色,如建议的那样
R Markdown 食谱的Using a Pandoc Lua filter。
但是,生成的幻灯片没有上色。在下面的幻灯片中,单词 red 应该是 red 而 blue 应该是 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"}.
【问题讨论】:
标签: html lua r-markdown reveal.js