parse_md_to_df_str: Parse Markdown Content to a Structured DataFrame

View source: R/md_to_df_str.R

parse_md_to_df_strR Documentation

Parse Markdown Content to a Structured DataFrame

Description

This function parses a vector of Markdown content into a structured DataFrame. Each line of Markdown is analyzed for heading levels, and content under headings is aggregated if specified. This allows for a tabular representation of hierarchical document structures, useful for content analysis and manipulation.

Usage

parse_md_to_df_str(chr, summarize = TRUE, collapse = ", ")

Arguments

chr

A character vector containing Markdown content, typically obtained from readLines().

summarize

Logical, if TRUE, the content under each heading is summarized into a single cell per heading level; if FALSE, each line retains its own row in the output DataFrame.

collapse

The string to use when collapsing multiple lines of content under each heading when summarize = TRUE.

Value

A data.frame where each row corresponds to a heading or content line. If summarize is TRUE, each heading level is summarized into single entries per heading level. The DataFrame columns represent the hierarchical levels (headings) and the content under these headings.

Examples

markdown_text <- c("# Heading 1", "Content under heading 1", "## Subheading 1.1",
"Content under subheading 1.1", "# Heading 2", "Content under heading 2")
md_df <- parse_md_to_df_str(markdown_text)
print(md_df)


Lightbridge-KS/lbdoc documentation built on May 16, 2024, 3:03 p.m.