as_qmd() creates a chunk for inline Quarto markdown
content (text-level) that fits within a table
cell paragraph. This enables cross-references
(@fig-xxx, @tbl-xxx), links, bold/italic, math,
inline code, shortcodes and other inline Quarto markdown
features inside flextable cells.
It is not designed for block-level elements such as headings, bullet lists or fenced code blocks.
The chunk is used with compose(), append_chunks()
or prepend_chunks(). It requires the flextable-qmd Lua
filter extension (see use_flextable_qmd()) and works with
HTML, PDF and Word (docx) Quarto output formats.
Setup
Install the extension once per project:
flextable::use_flextable_qmd()Add the filter to your Quarto document YAML. For HTML and PDF, a single line is enough:
For Word (docx), an additional post-render filter removes the wrapper table that Quarto adds around labelled flextables:
Supported markdown
Cross-references:
@fig-xxx,@tbl-xxxBold / italic:
**bold**,*italic*Inline code:
`code`Links:
[text](url)(internal and external)Math:
$\\alpha + \\beta$Shortcodes and other Quarto markdown constructs
Limitations
Each table cell in a flextable contains a single paragraph
built from inline chunks (see as_paragraph()). There is no
mechanism to insert block-level structures (multiple
paragraphs, lists, headings, fenced code blocks, callouts,
etc.) inside a cell. Because as_qmd() produces one of
these inline chunks, only inline markdown is supported.
See also
use_flextable_qmd() to install the Lua filter extension,
knit_print.flextable() for rendering options in knitr documents.
Other chunk elements for paragraph:
as_b(),
as_bracket(),
as_chunk(),
as_equation(),
as_highlight(),
as_i(),
as_image(),
as_strike(),
as_sub(),
as_sup(),
as_word_field(),
colorize(),
gg_chunk(),
grid_chunk(),
hyperlink_text(),
linerange(),
minibar(),
plot_chunk()
Examples
library(flextable)
dat <- data.frame(
label = c("Bold", "Link", "Code"),
content = c(
"This is **bold** text",
"Visit [Quarto](https://quarto.org)",
"Use `print()` here"
)
)
ft <- flextable(dat)
ft <- mk_par(ft, j = "content",
value = as_paragraph(as_qmd(content)))
ft
label
content
Bold
This is **bold** text
Link
Visit [Quarto](https://quarto.org)
Code
Use `print()` here
