diff --git a/NEWS.md b/NEWS.md index 17e9cdf..3e2dfa3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ * `proj_outline()` and `dir_outline()` now excludes example files -* `file_outline()` better support for TODO in md files +* `file_outline()` better support for todo in md files * `file_outline()` should recognize and transform markdown links automatically with new `markup_href()` It is no longer needed to use `{.href}` in your outline headings to show a link. diff --git a/R/outline.R b/R/outline.R index ecc59db..235ebe3 100644 --- a/R/outline.R +++ b/R/outline.R @@ -445,7 +445,7 @@ display_outline_element <- function(.data) { is_tab_or_plot_title ~ stringr::str_extract(outline_el, "title = [\"']([^\"]{5,})[\"']", group = 1), is_chunk_cap_next & !is_chunk_cap ~ stringr::str_remove_all(outline_el, "\\s?\\#\\|\\s+"), is_chunk_cap ~ stringr::str_remove_all(stringr::str_extract(outline_el, "(cap|title)\\:\\s*(.+)", group = 2), "\"|'"), - is_cross_ref ~ stringr::str_remove_all(outline_el, "^(i.stat\\:\\:)?.cdocs_lin.s\\(|[\"']\\)$"), + is_cross_ref ~ stringr::str_remove_all(outline_el, "^(i.stat\\:\\:)?.cdocs_lin.s\\(|[\"']\\)$|\""), is_doc_title ~ stringr::str_remove_all(outline_el, "subtitle\\:\\s?|title\\:\\s?|\"|\\#\\|\\s?"), is_section_title & !is_md ~ stringr::str_remove(outline_el, "^\\s{0,4}\\#+\\s+|^\\#'\\s\\#+\\s+"), # Keep inline markup is_section_title & is_md ~ stringr::str_remove_all(outline_el, "^\\#+\\s+|\\{.+\\}"), # strip cross-refs. @@ -534,7 +534,9 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) { .data$is_saved_doc <- is_saved_doc .data <- dplyr::mutate( .data, - condition_to_truncate = !is.na(outline_el) & !has_title_el & is_todo_fixme & is_saved_doc & !has_inline_markup, + condition_to_truncate = !is.na(outline_el) & !has_title_el & (is_todo_fixme) & is_saved_doc & !has_inline_markup, + condition_to_truncate2 = !is.na(outline_el) & !has_title_el & !is_todo_fixme & (is_second_level_heading_or_more | is_subtitle) & is_saved_doc & !has_inline_markup, + ) # r-lib/cli#627, add a dot before and at the end (Only in RStudio before 2023.12) .data$outline_el2 <- NA_character_ @@ -544,12 +546,19 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) { # Not showing up are the longer items. # truncating to make sure the hyperlink shows up. .data$outline_el2[cn] <- paste0( - as.character(trim_outline(.data$outline_el[cn], width)), + as.character(trim_outline(.data$outline_el[cn], width - 8L)), "- {.run [Done{cli::symbol$tick}?](reuseme::complete_todo(", # Removed ending dot. (possibly will fail with older versions) .data$line_id[cn], ", '", .data$file[cn], "', '", stringr::str_sub(stringr::str_replace_all(.data$content[cn], "'|\\{|\\}|\\)|\\(|\\[\\]|\\+", "."), start = -15L), "'))}", .data$rs_version[cn] ) + # truncate other elements + cn2 <- .data$condition_to_truncate2 + .data$outline_el2[cn2] <- paste0( + as.character(trim_outline(.data$outline_el[cn2], width - 1L)), + # Removed ending dot. (possibly will fail with older versions) + .data$rs_version[cn2] + ) .data <- dplyr::mutate( .data, outline_el2 = ifelse( @@ -606,7 +615,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) { } trim_outline <- function(x, width) { # problematic in case_when - cli::ansi_strtrim(x, width = width - 8L) + cli::ansi_strtrim(x, width = width) } # Remove duplicated entries from outline # for example, snapshots will have priority and will not return both the snapshot and the original test diff --git a/README.md b/README.md index dca0eed..2d2d61d 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ bench::mark( #> # A tibble: 1 × 6 #> expression min median `itr/sec` mem_alloc `gc/sec` #> -#> 1 outline <- proj_outline() 623ms 623ms 1.61 18MB 3.21 +#> 1 outline <- proj_outline() 434ms 453ms 2.21 19MB 4.42 ```
@@ -306,7 +306,7 @@ outline #> `i` A code section #> #> ── `tests/testthat/_ref/my-analysis.R` Analyse my streets -#> `i` Read my streets data +#> `i` Read my streets () data #> `i` data wrangling #> `i` Write my streets #> `i` TODO Create a new version- `Done✔?` @@ -331,7 +331,7 @@ outline #> ── `tests/testthat/_snaps/outline-criteria.md` #> `i` No outline criteria are untested #> -#> ── `tests/testthat/_snaps/outline.md` +#> ── `tests/testthat/_snaps/outline.md` 🕒 #> `i` alpha and work_only arguments work #> `i` pattern works as expected #> @@ -409,7 +409,6 @@ outline #> `i` TODO outlineroxygen comments processing should be left to `roxygen2::parse_file()`- `Done✔?` #> `i` TODO outlineshow key like `pak::pkg_deps_tree()` does.- `Done✔?` #> `i` TODO outlineroxygen function title- `Done✔?` -#> `i` TODO outlinetruncate other things, like graph title, comment section- `Done✔?` #> `i` TODO outlineremove ggtext markup from plot title.- `Done✔?` #> `i` FIXME outline comments are now interpreted as section- `Done✔?` #> `i` TODO outline todos in qmd file inside html comment- `Done✔?` @@ -417,7 +416,7 @@ outline #> #> ── `NEWS.md` 🕒 reuseme (development version) #> -#> ── `README.Rmd` 🕒 +#> ── `README.Rmd` #> `i` reuseme #> `i` Installation #> `i` Getting started diff --git a/TODO.R b/TODO.R index c92df9d..94e9572 100644 --- a/TODO.R +++ b/TODO.R @@ -15,7 +15,6 @@ # TODO [outline] roxygen comments processing should be left to {.fn roxygen2::parse_file} # TODO [outline] show key like {.fn pak::pkg_deps_tree} does. # TODO [outline] roxygen function title -# TODO [outline] truncate other things, like graph title, comment section. # TODO [outline] remove ggtext markup from plot title. # FIXME outline comments are now interpreted as section # TODO outline todos in qmd file inside html comment