Skip to content

Preserving folded blocks when rewriting YAML #137

@arnaudgallou

Description

@arnaudgallou

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions