Skip to content

feature request: adding support for lists #17

Open

Description

@IndrajeetPatil
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)

Activity

  1. danielinteractive commented on Jul 6, 2022

    @danielinteractive

    Agree that this would be awesome!

  2. etiennebacher commented on Sep 22, 2023

    @etiennebacher

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

  3. IndrajeetPatil commented on Sep 22, 2023

    @IndrajeetPatil
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions