Skip to content

Commit

Permalink
discordify
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb committed Nov 19, 2024
1 parent 242fa8c commit 540d569
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions R/reprex_render.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ reprex_render_impl <- function(input,
r = pp_md_to_r(md_file, comment = comment),
rtf = pp_highlight(pp_md_to_r(md_file, comment = comment)),
slack = pp_slackify(md_file),
discord = pp_discordify(md_file),
html = pp_html_render(md_file),
md_file
)
Expand Down Expand Up @@ -326,12 +327,28 @@ pp_slackify <- function(input) {
slack_file
}

# used when venue is "discord"
# https://www.markdownguide.org/tools/discord/
pp_discordify <- function(input) {
output_lines <- read_lines(md_file(input))
output_lines <- discord_info_string(output_lines)
output_lines <- simplify_image_links(output_lines)
discord_file <- md_file_discord(input)
write_lines(output_lines, discord_file)
discord_file
}

# remove "info strings" from opening code fences, e.g. ```r
# https://spec.commonmark.org/0.29/#info-string
remove_info_strings <- function(x) {
sub("^```[^`]*$", "```", x, perl = TRUE)
}

# remove blank space from opening code fences, e.g. ``` r
discord_info_string <- function(x) {
sub("^```[[:blank:]]?", "```", x, perl = TRUE)
}

# input: ![](https://i.imgur.com/woc4vHs.png)
# output: https://i.imgur.com/woc4vHs.png
simplify_image_links <- function(x) {
Expand Down

0 comments on commit 540d569

Please sign in to comment.