Skip to content

Commit

Permalink
Fix double backtick issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andrie committed Nov 9, 2022
1 parent d357317 commit e67ab04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
42 changes: 21 additions & 21 deletions R/convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,15 @@ convert_to_md <- function(path = "temp", verbose = FALSE) {
}



regex_replace_md <- function(path = "temp", verbose = TRUE) {
file_list <- fs::dir_ls(path = path, glob = "*.md")



if (verbose) cli::cli_progress_bar("Replacing regular expressions")

# create progress bar
for (filename in file_list) {
# message(filename)
filename %>%
read_lines() %>%
regex_replace <- function(x) {
x %>%
# remove empty hyperlinks [](...)
gsub("^\\[\\]\\{.*?\\}$", "", .) %>%
# remove {.sample}
gsub("`\\{\\.variable\\}`", "", .) %>%
gsub("\\{\\.variable\\}", "", .) %>%
gsub("`\\{\\.sample\\}`", "", .) %>%
gsub("\\{\\.sample\\}", "", .) %>%
gsub("`{.variable}`", "", ., fixed = TRUE) %>%
gsub("{.variable}", "", ., fixed = TRUE) %>%
gsub("`{.sample}`", "", ., fixed = TRUE) %>%
gsub("{.sample}", "", ., fixed = TRUE) %>%
# fix footnote cross-references
gsub("\\[\\^(\\d+)\\^\\]\\(#FOOT\\d+\\)\\{#DOCF\\d+\\}", "[^\\1]", .) %>%
gsub("\\[\\^(\\d+)\\^\\]\\(#FOOT\\d+\\)\\{#DOCF\\d+\\}", "[^\\1]", .) %>%
Expand All @@ -142,16 +131,27 @@ regex_replace_md <- function(path = "temp", verbose = TRUE) {
# insert missing colon in footnote references
gsub("^(\\[\\^\\d+\\])$", "\\1:", .) %>%
# replace double backtick `` occurrences
# gsub(r"{(?<!`)``(?!`)}", "", ., perl = TRUE) %>%
gsub(r"{(?<!`)``(?!`)}", "", ., perl = TRUE) %>%
# replace ellipsis
gsub("", "...", .) %>%
# remove named sections
gsub("(^#+ .*?) {#.*? \\.(.*)}$", "\\1", ., perl = TRUE) %>%
# remove spurious named code fences
# gsub("^::: {.* \\.(chapter|(sub)*section|appendix(sec)*(tion)*|unnumbered)}", "::: {}", ., perl = TRUE) %>%

# remember to remove this line and deal with it using Lua filters.
gsub("^:::.*$", "", .) %>%
gsub("^:::.*$", "", .)
}

regex_replace_md <- function(path = "temp", verbose = TRUE) {
file_list <- fs::dir_ls(path = path, glob = "*.md")
# browser()

if (verbose) cli::cli_progress_bar("Replacing regular expressions")

# create progress bar
for (filename in file_list) {
filename %>%
read_lines() %>%
regex_replace() %>%
readr::write_lines(file = filename)
}
invisible()
Expand Down
12 changes: 2 additions & 10 deletions R/process_manual.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,11 @@ process_manual <- function(manual = "R-exts.texi",
)
}

# copy template files to book folder

# glue_quarto_yaml(
# manual = folder,
# template = "book_template/_quarto.yml",
# verbose = verbose
# ) %>%
# readr::write_lines(file = glue::glue("{book_folder}/_quarto.yml"))



# replace regular expressions
regex_replace_md(path = book_folder)

# copy template files to book folder
fs::file_copy("book_template/custom.scss", book_folder, overwrite = TRUE)
invisible()
}

0 comments on commit e67ab04

Please sign in to comment.