---
subtitle: "Abstract"
author: ""
engine: knitr
---

```{r}
#| echo: false
#| out-width: 100%
# dwfun::ggsavep("./figures/GA20240729.pdf", loadit = TRUE)
```


```{r}
#| echo: false
#| cache: false
#| output: asis
# 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)
```
