Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: adding support for lists #17

Open
IndrajeetPatil opened this issue Jul 22, 2021 · 3 comments
Open

feature request: adding support for lists #17

IndrajeetPatil opened this issue Jul 22, 2021 · 3 comments

Comments

@IndrajeetPatil
Copy link
Contributor

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)

@danielinteractive
Copy link

Agree that this would be awesome!

@etiennebacher
Copy link

etiennebacher commented Sep 22, 2023

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).

@IndrajeetPatil
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants