Skip to contents

Converts a markdown string to a paragraph object compatible with flextable. This allows using markdown syntax to format text in flextable cells.

Usage

as_paragraph_md(x, font_family_mono = "mono")

Arguments

x

A character string containing markdown.

font_family_mono

Font family to use for inline code. Defaults to "mono".

Value

A paragraph object (class "paragraph") 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)

  • ![alt](path) (images)

  • Line breaks with \n\n (paragraph) or two spaces + \n (hard break)

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