Skip to content

Instantly share code, notes, and snippets.

@avidseeker
Created August 13, 2024 22:00
Show Gist options
  • Save avidseeker/a6d2729cd072d1bec91ea7b05c637553 to your computer and use it in GitHub Desktop.
Save avidseeker/a6d2729cd072d1bec91ea7b05c637553 to your computer and use it in GitHub Desktop.
Retrieving key from yaml-like line

If it works, it works:

TITLE=$(pandoc -t rst f.md -o /dev/null \
    -L <(echo "function Meta(m) print(pandoc.utils.stringify(m.title)) end")
)

Works for no quotes and no leading spaces:

TITLE=$(grep -m1 '^title: ' | cut -d' ' -f2)

Needs to unquote, perhaps by piping into sed 's/"//g'

awk -F': ' '/^title: / {print $2; exit}'

Not covering cases where yaml could be in the middle of a markdown file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment