Pandoc::Metadata(3pm)

πŸ“¦
version 0.38 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

✨ Pandoc::Metadata ✨

okay bestie, so this is the Pandoc::Metadata page from the User Contributed Perl Documentation β€” yep, perl, she's vintage but she SERVES πŸ’… stay with me.

🌸 NAME 🌸

Pandoc::Metadata β€” pandoc document metadata. that's it, that's the name, short and iconic.


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, document metadata?? author, title, date, all that?? it can be embedded in different document formats, which is lowkey kind of a lot when you think about it.

you can hand over your metadata in Pandoc markdown format using metadata blocks (http://pandoc.org/MANUAL.html#metadata-blocks) at the top of a markdown file β€” or in YAML format, like literally this:

---
title: a title
author:
  - first author
  - second author
published: true
...

and Pandoc supports document metadata built out of all of these:

  • strings (MetaString)
  • boolean values (MetaBool)
  • lists (MetaList)
  • key-value maps (MetaMap)
  • lists of inline elements (MetaInlines)
  • lists of block elements (MetaBlocks)

simple strings and boolean values can also be specified straight through the pandoc command line option -M or --metadata, like:

pandoc -M key=string
pandoc -M key=false
pandoc -M key=true
pandoc -M key

and then the Perl module Pandoc::Elements exports functions to construct metadata elements in the internal document model β€” plus the general helper function metadata. 🫢


πŸ‘‘ COMMON METHODS πŸ‘‘

every single Metadata Element supports the common element methods β€” name, to_json, string, ... β€” and returns true for the method is_meta. no cap. ✨

🌈 value( [ $key | $pointer ] [ %options ] ) 🌈

call it with no argument and it hands you back an unblessed deep copy of the metadata element. cute, fresh, yours to keep. πŸ’–

now, for peeking into subfields you've got options:

okay important: JSON Pointer escapes slash as ~1 and the character ~ as ~0. and URI Fragment syntax is NOT supported. just so you know. 😭

look how pretty this is:

$doc->value;                   # full metadata
$doc->value("");               # full metadata, explicitly
$doc->value('/author');        # author field
$doc->value('author');         # author field, plain key
$doc->value('/author/name');   # name subfield of author field
$doc->value('/author/0');      # first author field
$doc->value('/author/0/name'); # name subfield of first author field
$doc->value('/~1~0');          # metadata field '/~'
$doc->value('/');              # field with empty string as key

returns undef if the selected field does not exist. rip. πŸ’€

as a debugging aid you can set the option strict to a true value. in that case the method will croak if it runs into:

  • an invalid pointer
  • an invalid array index
  • a non-existing key
  • a non-existing array index

instances of MetaInlines and MetaBlocks get stringified β€” unless option element is set to keep.

and setting option boolean to JSON::PP will return JSON::PP:true or JSON::PP::false for MetaBool instances. star behavior honestly ⭐


πŸŽ€ METADATA ELEMENTS πŸŽ€

πŸ“ MetaString πŸ“

a plain text string metadata value. simple. gorgeous. no notes.

MetaString $string
metadata "$string"

πŸ“ MetaBool πŸ“

a Boolean metadata value. the special values false and FALSE are recognized as false in addition to normal false values (0, undef, "", ...).

MetaBool $value
metadata JSON::true()
metadata JSON::false()

πŸ“ MetaList πŸ“

a list of other metadata elements. nesting rights!! 🌸

MetaList [ @values ]
metadata [ @values ]

πŸ“ MetaMap πŸ“

a map of keys to other metadata elements. keys, meet values, values, meet keys πŸ’œ

MetaMap { %map }
metadata { %map }

πŸ“ MetaInlines πŸ“

a container for a list of inlines in metadata.

MetaInlines [ @inlines ]

πŸ“ MetaBlocks πŸ“

a container for a list of blocks in metadata.

MetaBlocks [ @blocks ]

and hiii, one more thing β€” the string method concatenates all stringified content blocks separated by empty lines. 🧚


and that's the whole page bestie, you ate it, you understood it, go forth and metadata responsibly πŸ’…βœ¨

this was written by the 😭 User Contributed Perl Documentation crew, running on perl v5.38.2, dated 2024-08-03 β€” mwah, bye 🫢

πŸ“¦ where this page comes from