You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm developing a package that can insert author metadata in YAML header of Quarto files. I do this by rewriting YAML blocks using the following steps:
# extract YAML from file
yaml.load()
# add new data
as.yaml()
# insert YAML back into file
The problem is that some information are lost in the process, including folded blocks:
lines<-" bar: > Lorem ipsum Vivamus quis"yaml::yaml.load(lines) |>yaml::as.yaml() |>
cat()
#> bar: |#> Lorem ipsum Vivamus quis
My question is: is there any way to preserve folded blocks in that case? I'm not aware of a special type I can use to target the > with a handler.
I'm considering to insert author data in a separate YAML header when my insert function detects complex cases (e.g. the use of custom tags, repeated blocks, comments being dropped due to the libyaml dependency, etc.). I would prefer to do that on rare occasions though.
The text was updated successfully, but these errors were encountered:
arnaudgallou
changed the title
Preserving folded blocks when rewriting YAML blocks
Preserving folded blocks when rewriting YAML
Dec 26, 2023
This would require preserving meta-information about the storage format in the converted objects. R could do this utilizing attributes. However, this library utilizes the libyaml library. This meta-information is stripped before it's tokenized. Without diving into the next library down it's not possible.
> lines <- "
+ bar: >
+ Lorem ipsum
+ Vivamus quis
+ "
>
> invisible(yaml::yaml.load(lines, handlers=list(str=function(x) {print(x); x})))
[1] "bar"
[1] "Lorem ipsum Vivamus quis\n"
The str handler is what passed from the yaml tokenizer. If I get down into that level I'll be finishing yaml 1.2 compliance.
I'm developing a package that can insert author metadata in YAML header of Quarto files. I do this by rewriting YAML blocks using the following steps:
The problem is that some information are lost in the process, including folded blocks:
My question is: is there any way to preserve folded blocks in that case? I'm not aware of a special type I can use to target the
>
with a handler.I'm considering to insert author data in a separate YAML header when my insert function detects complex cases (e.g. the use of custom tags, repeated blocks, comments being dropped due to the libyaml dependency, etc.). I would prefer to do that on rare occasions though.
The text was updated successfully, but these errors were encountered: