This commit is contained in:
2025-07-29 00:59:37 +08:00
parent ed607c70f0
commit 63e372e81d
12 changed files with 124 additions and 465 deletions
+28 -2
View File
@@ -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)
```