Skip to content

Commit 80dda93

Browse files
committed
fixed bug for empty statement, improved README.md
1 parent ad2f5e0 commit 80dda93

File tree

3 files changed

+63
-57
lines changed

3 files changed

+63
-57
lines changed

include-meta/README.md

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,84 @@
11
# include-meta
22

3-
This filter adds the meta-data from one or more external YAML files to
3+
This filter adds the meta-data from one or more external YAML files to
44
the metadata of the document.
55

6-
This allows defining frequently needed sets of meta-data in external files
7-
and reusing them.
6+
This allows defining frequently needed sets of meta-data in external
7+
files and reusing them.
88

9-
In contrast to the `--metadata-file` option of Pandoc, this filter allows specifying the set(s) of meta-data in the actual document header, which is
10-
more transparent than e.g. hiding them in a make script.
9+
In contrast to the `--metadata-file` option of Pandoc, this filter
10+
allows specifying the set(s) of meta-data in the actual document
11+
header, which is more transparent than e.g. hiding them in a make
12+
script.
1113

1214
## Specifying a YAML File to be included
1315

14-
Simply add the `include-meta` directive to the document header, like so:
16+
Simply add the `include-meta` directive to the document header, like
17+
so:
1518

1619
---
17-
title: My document
18-
author: Joe Doe
19-
include-meta: defaults.yaml
20+
title: My document author: Joe Doe include-meta: defaults.yaml
2021
...
2122

2223
Multiple files can be specified by using a list:
2324

2425
---
25-
title: My document
26-
author: Joe Doe
27-
include-meta:
26+
title: My document author: Joe Doe include-meta:
2827
- defaults.yaml
2928
- moredefaults.yaml
3029
...
3130

3231
## Priority Rules
3332

34-
The metadata from the external YAML files will be processed in the order of (1) the statements in the document's YAML header block and (2) the position of the file in the list.
33+
The metadata from the external YAML files will be processed in the
34+
order of (1) the statements in the document's YAML header block and
35+
(2) the position of the file in the list.
3536

3637
---
37-
title: My document
38-
author: Joe Doe
39-
include-meta:
38+
title: My document author: Joe Doe include-meta:
4039
- first.yaml
41-
- second.yaml
42-
include-meta: third.yaml
43-
include-meta:
40+
- second.yaml include-meta: third.yaml include-meta:
4441
- fourth.yaml
45-
- fifth.yaml
46-
header-includes:
42+
- fifth.yaml header-includes:
4743
- \setbeamertemplate{footline}[page number]
4844
...
4945

50-
The **metadata in the YAML header of the document** is processed **at the very end** (i.e. with the highest priority).
46+
The **metadata in the YAML header of the document** is processed **at
47+
the very end** (i.e. with the highest priority).
5148

52-
The metadata from all referenced YAML files and the YAML header in the document **is combined as follows:**
49+
The metadata from all referenced YAML files and the YAML header in the
50+
document **is combined as follows:**
5351

5452
- duplicates are ignored,
55-
- `title` and `date` are replaced by the value in the source with the highest priority (the document or the last YAML file in the list),
56-
- `author`, `header-includes` and `bibliography` values are joined into a combined list, and
57-
- values from all other properties are taken from the source with the highest priority (e.g. set according to the YAML in the document).
53+
- `title` and `date` are replaced by the value in the source with the
54+
highest priority (the document or the last YAML file in the list),
55+
- `author`, `header-includes` and `bibliography` values are joined
56+
into a combined list, and
57+
- values from all other properties are taken from the source with the
58+
highest priority (e.g. set according to the YAML in the document).
5859

59-
For instance, if you specify one author in the the first YAML and another one in the second, the final meta-data will be a list of both. The order of the list will represent the order of the processing (see above).
60+
For instance, if you specify one author in the the first YAML and
61+
another one in the second, the final meta-data will be a list of
62+
both. The order of the list will represent the order of the
63+
processing (see above).
6064

61-
**Note:** The merging rules and code are based on a [Github Issue discussion](https://github.com/jgm/pandoc/issues/3115#issuecomment-294506221).
65+
**Note:** The merging rules and code are based on a [Github Issue
66+
discussion]
67+
(https://github.com/jgm/pandoc/issues/3115#issuecomment-294506221).
6268

63-
The exact relationship between metadata from the document and the sum of the external YAML files is still evolving. I might add a mechanism for specifying the priority of e.g. the document settings.
69+
The exact relationship between metadata from the document and the sum
70+
of the external YAML files is still evolving. I might add a mechanism
71+
for specifying the priority of e.g. the document settings.
6472

6573

6674
## Work in Progress
6775

68-
This filter is work in progress.
76+
This filter is work in progress. Known limitations are as follows:
77+
78+
1. The joining of properties like `author`, `header-includes` and `bibliography` works only for the first two levels of YAML data structures. This should suffice for most cases but could cause problems if the merge mode "extendlist" is applied to additional properties.
79+
80+
2. At the moment, only relative or absolute paths can be used, but not such including environment variables, like `$MY_CONFIG/defaults.yaml`.
81+
82+
3. The combination of boolean values that default as true for RevealJS will require that the last statement uses `0` instead of `false`. For more information, [see here](https://pandoc.org/MANUAL.html#variables-for-html-slides).
83+
6984

include-meta/include-meta.lua

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,26 @@ function meta_expand (meta)
110110
local all_meta = pandoc.MetaList({})
111111
local yaml_includes = meta['include-meta']
112112
-- print(len(yaml_includes), "YAML meta file(s) to be included found.")
113-
for i, filename in pairs(yaml_includes) do
114-
yaml_file_path = stringify(filename)
115-
-- print('Processing:', yaml_file_path)
116-
local yaml_fh = io.open(yaml_file_path, "r")
117-
if not yaml_fh then
118-
io.stderr:write("Cannot open file: ", yaml_file_path, " - Skipped.\n")
119-
else
120-
local doc_from_file = pandoc.read(yaml_fh:read '*a', format)
121-
-- print(stringify(doc_from_file))
122-
yaml_fh:close()
123-
all_meta = merge_metadata(all_meta, doc_from_file.meta)
113+
if yaml_includes then
114+
for i, filename in pairs(yaml_includes) do
115+
yaml_file_path = stringify(filename)
116+
-- print('Processing:', yaml_file_path)
117+
local yaml_fh = io.open(yaml_file_path, "r")
118+
if not yaml_fh then
119+
io.stderr:write("Cannot open file: ", yaml_file_path, " - Skipped.\n")
120+
else
121+
local doc_from_file = pandoc.read(yaml_fh:read '*a', format)
122+
-- print(stringify(doc_from_file))
123+
yaml_fh:close()
124+
all_meta = merge_metadata(all_meta, doc_from_file.meta)
125+
end
124126
end
127+
-- Remove the includes-meta directive after processing
128+
meta['include-meta'] = nil
129+
return merge_metadata(all_meta, meta, merge_methods)
130+
else
131+
return
125132
end
126-
-- Remove the includes-meta directive after processing
127-
meta['include-meta'] = nil
128-
return merge_metadata(all_meta, meta, merge_methods)
129133
end
130134

131135
return { {Meta = meta_expand} }

include-meta/test.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)