Skip to content

Commit

Permalink
Truncate subtitles and second level headings
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed May 9, 2024
1 parent 1406d7a commit 95e1b74
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
17 changes: 13 additions & 4 deletions R/outline.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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_
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bench::mark(
#> # A tibble: 1 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 outline <- proj_outline() 623ms 623ms 1.61 18MB 3.21
#> 1 outline <- proj_outline() 434ms 453ms 2.21 19MB 4.42
```

<details>
Expand Down Expand Up @@ -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 (<https://https://en.wikipedia.org/wiki/Street_art>) data
#> `i` data wrangling
#> `i` Write my streets
#> `i` TODO Create a new version- `Done✔?`
Expand All @@ -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
#>
Expand Down Expand Up @@ -409,15 +409,14 @@ 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✔?`
#> `i` TODO reframe more than one issue. nw drive- `Done✔?`
#>
#> ── `NEWS.md` 🕒 reuseme (development version)
#>
#> ── `README.Rmd` 🕒
#> ── `README.Rmd`
#> `i` reuseme
#> `i` Installation
#> `i` Getting started
Expand Down
1 change: 0 additions & 1 deletion TODO.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95e1b74

Please sign in to comment.