roxygen2md
                                
                                 roxygen2md copied to clipboard
                                
                                    roxygen2md copied to clipboard
                            
                            
                            
                        feature request: adding support for lists
library(roxygen2md)
text <- c(
  "Here are the items:
  \\itemize{
   \\item{item-1}
   \\item{item-2}
  }"
)
text
#> [1] "Here are the items:\n  \\itemize{\n   \\item{item-1}\n   \\item{item-2}\n  }"
markdownify(text)
#> [1] "Here are the items:\n  \\itemize{\n   \\item{item-1}\n   \\item{item-2}\n  }"
Created on 2021-07-22 by the reprex package (v2.0.0)
Agree that this would be awesome!
Hi I'm not familiar with rex so I don't make a PR but here's some base R regexes to fix some very simple cases if someone wants to build on that:
text <- c(
"#' Here are the items:
#' \\itemize{
#'  \\item{item-1}
#'  \\item{item-2}
#' }
#' And another list:
#' \\itemize{
#'  \\item item-1 with some very
#'    long text
#'  \\item item-2
#' }
"
)
cat(text)
#> #' Here are the items:
#> #' \itemize{
#> #'  \item{item-1}
#> #'  \item{item-2}
#> #' }
#> #' And another list:
#> #' \itemize{
#> #'  \item item-1 with some very
#> #'    long text
#> #'  \item item-2
#> #' }
# \item{here's some text} 
# -> * here's some text
tmp <- gsub("\\\\item\\{([^}]+)\\}", "\\* \\1", text)
# \itemize{\n * whatever is here \n \item foo \n} 
# -> \n * whatever is here \n \item foo \n
tmp <- gsub("\\\\itemize\\{([^}]+)\\}", "\\1", tmp)
# \item another bullet point
# -> * another bullet point
tmp <- gsub("\\\\item ", "\\* ", tmp)
cat(tmp)
#> #' Here are the items:
#> #' 
#> #'  * item-1
#> #'  * item-2
#> #' 
#> #' And another list:
#> #' 
#> #'  * item-1 with some very
#> #'    long text
#> #'  * item-2
#> #'
Note that the example above won't work with \\item \\strong{item-2} for example so it should come as the last step of the conversion process (if implemented as-is).
That's a great start, Etienne! Thanks.
In addition to the caveats you mentioned, I think the function will also need to deal with the recursive case where the list items may themselves contain lists.