メタデータの値の型
※Luaフィルタ特有のLuaメタテーブルをもつテーブル値のことを(マニュアルに倣って)「オブジェクト(object)」と呼ぶことにする。特に、tag値がFoo
であるオブジェクトを「Fooオブジェクト」と呼ぶ。
- MetaBool: 真偽値。
- Lua真偽値で表される。
- MetaString: 文字列。
- Lua文字列値で表される。
- MetaInlines: インライン要素のリスト。
- MetaInlinesオブジェクトで表される。
- 「インライン要素オブジェクト」のListオブジェクトとして機能する。
- MetaBlocks: ブロック要素のリスト。
- MetaBlocksオブジェクトで表される。
- 「ブロック要素オブジェクト」のListオブジェクトとして機能する。
- MetaList: メタデータ値のリスト。
- MetaMap: 文字列からメタデータ値への写像。
- MetaMapオブジェクトで表される。
- “連想配列としてのテーブル”として扱える。例えば、pairs関数でキー値ペアを列挙できる。
※MetaInlinesやMetaBlocksも実質的にListオブジェクトなので、Luaシーケンスとして扱える。
仕様(documentedな話)
コマンド行のオプション(--metadata
/-M
)で指定するメタデータは必ず真偽値か文字列として扱われる。
Values will be parsed as YAML boolean or string values. If no value is specified, the value will be treated as Boolean true.
メタデータファイル(--metadata-file
)んそ指定は、Pandoc’s Markdownのメタデータブロックと同様に扱われる。(ただし入力形式がMarkdown以外でも使える。)
Generally, the input will be handled the same as in YAML metadata blocks.
既定値ファイル(--defaults
/-d
)のフィールドはコマンド行オプションに対応する。
FILE is a YAML file whose fields correspond to command-line option settings.
既定値ファイルでの設定は、コマンド行オプションによって上書きまたは拡張される。
Settings from the defaults file may be overridden or extended by subsequent options on the command line.
複数指定できるオプション(--metadata
も含む)の場合は上書きではなく拡張になる。
Note that, where command-line arguments may be repeated (…), the values specified on the command line will combine with values specified in the defaults file, rather than replacing them.
メタデータブロック(またはメタデータファイル)で設定されるメタデータ値はリストやオブジェクトでもよい。文字列のスカラー値はMarkdownのソースとして解釈される。
Metadata will be taken from the fields of the YAML object and added to any existing document metadata. Metadata can contain lists and objects (nested arbitrarily), but all string scalars will be interpreted as Markdown.
実際の動作(undocumentedな話)
コマンド行オプション(--metadata/-M)
オプションで指定した値の文字列が、そのままMetaString型のメタデータ値となる2。ただし例外として、true
/True
/TRUE
/false
/False
/FALSE
は真偽値として解釈されて3MetaBool型のメタデータ値となる。また、値を省略した場合(-M フィールド
)はMetaBool型のtrueとなる。
-M foo=Bar
→ fooの値はMetaString["Bar"]
。-M foo=42
→ fooの値はMetaString["42"]
(文字列)。-M foo=yes
→ fooの値はMetaString["yes"]
。-M foo=[42.00]
→ fooの値はMetaString["[42.00]"]
。-M foo=true
→ fooの値はMetaBool[true]
。-M foo=False
→ fooの値はMetaBool[false]
。-M foo=truE
→ fooの値はMetaString["truE"]
(文字列!)。-M foo=false,0
→ fooの値はMetaString["false,0"]
。-M foo
→ fooの値はMetaBool[true]
(値を省略)。-M foo=
→ fooの値はMetaString[""]
(値が空文字列)。
同じフィールドを複数回指定した場合は、各々のメタデータ値を順に並べたMetaList値として扱われる。オプションで指定したメタデータ値がMetaMapになることは恐らくない。
-M foo=Baz -M foo=Bar
→ fooの値はMetaList[MetaString["Baz"],MetaString["Bar"]]
。-M foo=0 -M foo=TRUE
→ fooの値はMetaList[MetaString["0"],MetaBool[true]]
。-M foo.bar=54
→ foo.barというフィールドがMetaString["54"]
に設定される。fooがMetaMapになるのではない。
既定値ファイル(--defaults/-d)
既定値ファイルの内容はYAMLのマッピング値として解釈され、そのmetadataキーに対する値(これもマッピング値でないといけない)がメタデータとして解釈される。
- YAMLのスカラー値は全て(真偽値も含めて)MetaString型の値に変換される。
- 文字列値(
!!str
型)はそのまま。 - 真偽値(
!!bool
型)は、真(true
/True
/TRUE
)はtrue
、偽(false
/False
/FALSE
)は空文字列になる。MetaBool値になるのではない。 - 数値(
!!int
型・!!float
型)は、その典型的な文字列表現になる。intの42は42
、floatの42は42.0
、無限大(.inf
)はInfinity
、等。 - Null値(
!!null
型、表記は~
/null
等)は空文字列になる4。
- 文字列値(
- YAMLのシーケンス値はそのままMetaList型の値になる。
- YAMLのマッピング値はそのままMetaMap型の値になる。
例えば次のような内容の既定値ファイルを指定したとする。
metadata: foo1: blah foo2: "false" bar1: 0x42 bar2: 042.000 gee1: True gee2: FALSE whiz1: [true,false] whie2: - false - true whiz3: boo: ! 0x42
- foo1の値は
MetaString["blah"]
。 - foo2の値は
MetaString["false"]
。(" "
囲いなのでYAMLで文字列型と見なされる。) - bar1の値は
MetaString["66"]
。(YAMLで整数の66と見なされるので) - bar2の値は
MetaString["42.0"]
。 - gee1の値は
MetaString["true"]
。(MetaBoolではない。) - gee2の値は
MetaString[""]
。(なぜかfalseは空になる。) - whiz1の値は
MetaList[MetaString["true"],MetaString[""]]
。 - whiz2の値は
MetaList[MetaString[""],MetaString["true"]]
。 - whiz3の値は
MetaMap[("boo",MetaString["0x42"])]
。(!
が文字列型を強制するのでYAMLで文字列の0x42
と解釈されている。)
(つづけ)