Turn a character vector into a vector of valid markdown Setext headings. These markdown leaf blocks can be rendered as the <h1> and <h2> tags only.

md_setext(x, level = 1, width = TRUE)

Arguments

x

A character vector of heading text.

level

An numeric vector of all either 1 or 2 to determine whether level 1 headings are created with = or level two with -. If less levels are provided than headings, level will be repeated via glue::glue().

width

logical or integer; if TRUE the width will be automatically determined by the width of the longest line in x. If an integer, the setext underline will be that wide.

Value

A glue vector of headings with length equal to x.

Details

A setext heading consists of one or more lines of text, each containing at least one non-whitespace character, with no more than 3 spaces indentation, followed by a setext heading underline. The lines of text must be such that, were they not followed by the setext heading underline, they would be interpreted as a paragraph: they cannot be interpretable as a code fence, ATX heading, block quote, thematic break, list item, or HTML block.

A setext heading underline is a sequence of = characters or a sequence of - characters, with no more than 3 spaces indentation and any number of trailing spaces. If a line containing a single - can be interpreted as an empty list items, it should be interpreted this way and not as a setext heading underline.

The heading is a level 1 heading if = characters are used in the setext heading underline, and a level 2 heading if - characters are used. The contents of the heading are the result of parsing the preceding lines of text as CommonMark inline content.

In general, a setext heading need not be preceded or followed by a blank line. However, it cannot interrupt a paragraph, so when a setext heading comes after a paragraph, a blank line is needed between them.

See also

Other leaf block functions: md_blank(), md_chunk(), md_fence(), md_heading(), md_indent(), md_label(), md_paragraph(), md_reference(), md_rule(), md_table()

Examples

md_setext("Overview")
#> Overview
#> ========
md_setext("This is a setext\nheading", level = 2)
#> This is a setext
#> heading
#> ----------------
md_setext(c("one", "two", "three", "four"), level = c(1, 2))
#> one
#> ===
#> two
#> ---
#> three
#> =====
#> four
#> ----
md_setext("Installation", level = 2, width = 55)
#> Installation
#> -------------------------------------------------------