Skip to content

Commit

Permalink
add repeated key-val options to commandline; fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Sprevak committed May 29, 2015
1 parent f5e5efc commit 7c14d45
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ Arbitrary pandoc command line options can be set using metadata via `commandline

- For pandoc flags, the value should be boolean (`true`, `false`), e.g. `no-wrap: true`.
- For pandoc key-values, the value should be a quoted inline code span, e.g. `` include-in-header: "`path/to/my/header`" ``.
- For pandoc repeated key-values, the value should be a list of inline code spans, e.g.

<!-- -->

include-in-header:
- "`file1.txt`"
- "`file2.txt`"
- "`file3.txt`"

Repeated key-value options in `comandline` are added after any provided from the command line.

`false` plays a special role. `false` means that the pandoc command line option with the field’s name, if set, should be unset. `false` can be used for both flags and key-value options (e.g. `include-in-header: false`).

Expand Down
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,18 @@ line option (e.g. ``standalone``).
e.g. ``no-wrap: true``.
- For pandoc key-values, the value should be a quoted inline code span,
e.g. ``include-in-header: "`path/to/my/header`"``.
- For pandoc repeated key-values, the value should be a list of inline
code spans, e.g.

::

include-in-header:
- "`file1.txt`"
- "`file2.txt`"
- "`file3.txt`"

Repeated key-value options in ``comandline`` are added after any
provided from the command line.

``false`` plays a special role. ``false`` means that the pandoc command
line option with the field’s name, if set, should be unset. ``false``
Expand Down
10 changes: 10 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ Arbitrary pandoc command line options can be set using metadata via `commandline

- For pandoc flags, the value should be boolean (`true`, `false`), e.g. `no-wrap: true`.
- For pandoc key-values, the value should be a quoted inline code span, e.g. ``include-in-header: "`path/to/my/header`"``.
- For pandoc repeated key-values, the value should be a list of inline code spans, e.g.

```
include-in-header:
- "`file1.txt`"
- "`file2.txt`"
- "`file3.txt`"
```
Repeated key-value options in `comandline` are added after any provided from the command line.

`false` plays a special role.
`false` means that the pandoc command line option with the field's name, if set, should be unset.
Expand Down
24 changes: 17 additions & 7 deletions panzer/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ def parse_commandline(metadata):
'map---ignoring' % key)
bad_opts += key
content = {key: content[key]
for key in content
if key not in bad_opts}
commandline = {'r': dict(), 'w': dict()}
for key in content
if key not in bad_opts}
# 2. parse remaining opts
commandline = {'r': dict(), 'w': dict()}
for key in content:
# 1. extract value of field with name 'key'
val = None
Expand All @@ -339,13 +339,23 @@ def parse_commandline(metadata):
'Syntax should be OPTION: "`VALUE`"' % key)
continue
if key in const.PANDOC_OPT_ADDITIVE:
val = [[val_c[0][const.C][1]]]
val = [get_list_or_inline(content, key)]
else:
val = val_c[0][const.C][1]
val = get_list_or_inline(content, key)[0]
# if value type is list of inline codes, add repeated --OPTION=VAL
elif val_t == 'MetaList' and key in const.PANDOC_OPT_ADDITIVE:
# TODO
pass
errs = False
for item in val_c:
if item[const.T] != 'MetaInlines' \
or item[const.C][0][const.T] != 'Code':
info.log('ERROR', 'panzer',
'Cannot read option "%s" in "commandline" field. '
'Syntax should be - OPTION: "`VALUE`"' % key)
errs = True
if not errs:
val = [[x] for x in get_list_or_inline(content, key)]
else:
continue
# otherwise, signal error
else:
info.log('ERROR', 'panzer',
Expand Down

0 comments on commit 7c14d45

Please sign in to comment.