update
This commit is contained in:
@@ -13,7 +13,33 @@ dwfun::ggsavep("./figures/GA20240729.pdf", loadit = TRUE)
|
||||
|
||||
```{r}
|
||||
#| echo: false
|
||||
#| cache: false
|
||||
#| output: asis
|
||||
cat(system("grep '^abstract: ' ./MS/MS.qmd | sed -e 's/^abstract: \"*\\(.*\\).$/\\1/g'", intern = TRUE))
|
||||
# function
|
||||
extract_abstract <- function(file) {
|
||||
content <- readLines(file, warn = FALSE)
|
||||
abstract_line <- grep("^# Abstract[^:]", content, ignore.case = TRUE)[1]
|
||||
if (length(abstract_line) == 0) return(NA)
|
||||
start <- abstract_line + 1
|
||||
while (start <= length(content) && trimws(content[start]) == "") {
|
||||
start <- start + 1
|
||||
}
|
||||
if (start > length(content)) return(NA)
|
||||
end <- start
|
||||
while (
|
||||
end <= length(content) &&
|
||||
trimws(content[end]) != "" &&
|
||||
!grepl("^#", content[end])
|
||||
) {
|
||||
end <- end + 1
|
||||
}
|
||||
paste(content[start:(end - 1)], collapse = " ")
|
||||
}
|
||||
# extract
|
||||
file <- "./MS/MS.qmd"
|
||||
abstract <- rmarkdown::yaml_front_matter(file)$abstract
|
||||
if (is.null(abstract)) {
|
||||
abstract <- extract_abstract(file)
|
||||
}
|
||||
cat(abstract)
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user