Skip to content
Discussion options

You must be logged in to vote

pkl-swift doesn't have a using: parser parameter on evaluateModule, but Pkl's stdlib ships pkl:yaml (stdlib/yaml.pkl:57, 90) and pkl:json. You can wrap the front matter in a tiny Pkl snippet and decode the parsed result directly with evaluateExpression:

let source = """
import "pkl:yaml"
parsed = new yaml.Parser {}.parse(#\"\"\"
\(fm_yaml)
\"\"\"#)
"""
let res = try await evaluator.evaluateExpression(
    source: .text(source),
    expression: "parsed",
    as: ArticleHeader.self
)

To avoid string-escaping edge cases with arbitrary front matter, pass the raw text through EvaluatorOptions.properties (e.g. properties: ["fm": fm_yaml]) and call new yaml.Parser {}.parse(read("prop:fm")).

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by carlynorama
Comment options

You must be logged in to vote
2 replies
@carlynorama
Comment options

@LucasValeQueiroz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants