Skip to contents

Parses text in Markdown format and returns fpar and as_paragraph command strings to be used with officer

Usage

md_to_officer(
  str,
  default_format = list(color = "black", font.size = 12, bold = FALSE, italic = FALSE,
    underlined = FALSE, font.family = "Cambria (Body)", vertical.align = "baseline",
    shading.color = "transparent")
)

Arguments

str

string containing Markdown can contain the following elements:

  • paragraph: two or more new lines creates a paragraph

  • bold: can be either "**text in bold**" or "__text in bold__"

  • italics: can be either "*text in italics*" or "_text in italics_"

  • subscript: "Normal~subscript~"

  • superscript: "Normal^superscript^"

  • color: "<color:red>red text</color>"

  • shade: "<shade:#33ff33>shading</shade>"

  • font family: "<ff:symbol>symbol</ff>"

  • reference: "<ref:key>" Where "key" is the value assigned when adding a table or figure

default_format

list containing the default format for elements not defined with markdown default values.


   default_format = list(
      color          = "black",
      font.size      = 12,
      bold           = FALSE,
      italic         = FALSE,
      underlined     = FALSE,
      font.family    = "Cambria (Body)",
      vertical.align = "baseline",
      shading.color  = "transparent")

Value

list with parsed paragraph elements with the content added to the body, each paragraph can be found in a numbered list element (e.g. pgraph_1, pgraph_2, etc) each with the following elements:

  • locs: Dataframe showing the locations of markdown elements in the current paragraph

  • pele: These are the individual parsed paragraph elements

  • ftext_cmd: String containing the ftext commands.

  • fpar_cmd: String containing the fpar commands that can be run using eval to return the output of fpar. For example:

    
      myfpar = eval(parse(text=pgparse$pgraph_1$fpar_cmd))
     
  • as_paragraph_cmd: String containing the as_paragraph_cmd that can be run using

    
      myas_para = eval(parse(text=pgparse$pgraph_1$as_paragraph_cmd))
     

Examples

res              = md_to_officer("Be **bold**!")
fpar_obj         = eval(parse(text=res$pgraph_1$fpar_cmd))
as_paragraph_obj = eval(parse(text=res$pgraph_1$as_paragraph_cmd))