Converts markdown strings to a paragraph object compatible with flextable. This allows using markdown syntax to format text in flextable cells.
As flextable::as_paragraph(), it is vectorised: each element of x
gives the paragraph of a row, so that a column of markdown can be used
with flextable::mk_par() (value = as_paragraph_md(col)).
Value
A paragraph object (class "paragraph"), with one paragraph per
element of x, that can be used with flextable::mk_par() or
flextable::as_flextable().
Details
Supported markdown syntax:
**bold**or__bold__*italic*or_italic_`code`(monospace)~~strikethrough~~[link](url)(underlined and colored)(images, with a height of twice the font size, as inmd_grob(); an image that can not be read is dropped with a warning)Line breaks with
\n\n(paragraph) or two spaces +\n(hard break)^superscript^and~subscript~, as in Pandoc (no space inside, unless escaped:^a\ b^)Equations
$...$and$$...$$(LaTeX), as in Pandoc;\$is a dollar. They are written as equations of 'flextable' (flextable::as_equation()), which needs the package 'equatags'.
Examples
library(flextable)
ft <- flextable(head(iris, 3))
ft <- mk_par(
ft,
j = 1,
part = "body",
value = as_paragraph_md("**Column1** has *values*")
)
ft
Sepal.Length
Sepal.Width
Petal.Length
Petal.Width
Species
Column1 has values
3.5
1.4
0.2
setosa
Column1 has values
3.0
1.4
0.2
setosa
Column1 has values
3.2
1.3
0.2
setosa
# With inline code
ft <- mk_par(
ft,
j = 2,
part = "body",
value = as_paragraph_md("Use `Sepal.Width` column")
)
ft
Sepal.Length
Sepal.Width
Petal.Length
Petal.Width
Species
Column1 has values
Use Sepal.Width column
1.4
0.2
setosa
Column1 has values
Use Sepal.Width column
1.4
0.2
setosa
Column1 has values
Use Sepal.Width column
1.3
0.2
setosa
