@@ -16,37 +16,37 @@ knitr::opts_chunk$set(echo = TRUE)
1616extract_remote_markdown <- function(url, header_pattern) {
1717 lines <- try(readLines(url, warn = FALSE), silent = TRUE)
1818 tmp <- tempfile(fileext = ".md")
19-
19+
2020 if (inherits(lines, "try-error")) {
2121 writeLines("_Documentation temporarily unreachable._", tmp)
2222 return(tmp)
2323 }
24-
24+
2525 # Find the starting line (e.g., the line containing "## WSL2")
2626 start_idx <- grep(header_pattern, lines, ignore.case = TRUE)
27-
27+
2828 if (length(start_idx) > 0) {
2929 # Determine the level of the header found (count the # symbols)
3030 header_line <- lines[start_idx]
3131 header_level <- nchar(gsub("(^#+).*", "\\1", header_line))
32-
32+
3333 # Find headers that are at the SAME level or HIGHER (fewer or equal #)
3434 # We want to ignore ### if we are looking for a ## section
3535 stop_pattern <- paste0("^#{1,", header_level, "} ")
3636 all_potential_stops <- grep(stop_pattern, lines)
37-
37+
3838 # The end index is the next header that isn't the current one
3939 end_idx <- all_potential_stops[all_potential_stops > start_idx][1]
40-
40+
4141 if (is.na(end_idx)) end_idx <- length(lines) else end_idx <- end_idx - 1
42-
42+
4343 # Extract and add blank lines for proper RMarkdown list rendering
44- content <- c("", lines[(start_idx + 1):end_idx], "")
44+ content <- c("", lines[(start_idx + 1):end_idx], "")
4545 writeLines(content, tmp)
4646 } else {
4747 writeLines("_Section not found in remote documentation._", tmp)
4848 }
49-
49+
5050 return(tmp)
5151}
5252```
0 commit comments