Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template conditions fail with fields containing YAML objects. #1133

Closed
barraq opened this issue Jan 30, 2014 · 1 comment
Closed

Template conditions fail with fields containing YAML objects. #1133

barraq opened this issue Jan 30, 2014 · 1 comment

Comments

@barraq
Copy link

barraq commented Jan 30, 2014

Hello,

As described in #851 "if a field has a YAML object as its content, it will not create a metadata record at all". Although there may be a valid reason for that, it is annoying that it implies that template conditions will not work properly on such fields.

Testing the existence of a field that contains complexe metadata can be really useful. Could it be possible to extend the template conditions to work with any fields in the YAML tree instead of only meta records'?

Below is an illustration:

Suppose a test.md file containing the following:


---
address:
  city: Grenoble
  country: France
extra:
  - key: key1
    value: value1
  - key: key2
    value: value2
  - key: key3
    value: value3
  - key: key4
    value: value4
tags:
  - tag1
  - tag2
  - tag3
...

Template test.

Suppose a test.plain template file containing the following:

with if(address)
--
$if(address)$
$address.city$
$address.country$
$endif$
--

without if(address)
--
$address.city$
$address.country$
--

with if(extra)
--
$if(extra)$
$for(extra)$
- $extra.key$: $extra.value$
$endfor$
$endif$
--

without if(extra)
--
$for(extra)$
- $extra.key$: $extra.value$
$endfor$
--

with if(tags)
--
$if(tags)$
$for(tags)$
- $tags$
$endfor$
$endif$
--

without if(tags)
--
$for(tags)$
- $tags$
$endfor$
--

Now lets process test.md with the custom test.plain template:

$ pandoc --standalone --template=test.plain --from markdown+yaml_metadata_block --to plain -o test.txt test.md

The output is the following:

with if(address)
--
--

without if(address)
--
Grenoble
France
--

with if(extra)
--
--

without if(extra)
--
- key1: value1
- key2: value2
- key3: value3
- key4: value4
--

with if(tags)
--
- tag1
- tag2
- tag3
--

without if(tags)
--
- tag1
- tag2
- tag3
--

Best,
Rémi

@alexis-mignon
Copy link

I can confirm the bug in the freshly installed 1.12.3.3 version of pandoc on a ubuntu 13.10 system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants