nichtich / Pandoc-Elements

Perl module to create and process Pandoc documents
https://metacpan.org/release/Pandoc-Elements
Other
10 stars 6 forks source link

Add pandoc_version method and constructor field to Documents #61

Closed nichtich closed 7 years ago

nichtich commented 7 years ago

Useful feature to create a document compatible with a known pandoc release number.

$doc = new Document $meta. $blocks, pandoc_version => '1.18.1';
is $doc->api_version,  '1.17.0.4'; # derived from pandoc_version
is $doc->pandoc_version,  '1.18'; # minimum required version with api_version 1.17

$doc = new Document $meta. $blocks, api_version => 1.17;
is $doc->pandoc_version,  '1.18';  # minimum required version with api_version 1.17

$doc = new Document $meta. $blocks, pandoc_version => '1.16.0.2';
is $doc->api_version,  '1.16; # pandoc 1.16 used api 1.16
is $doc->pandoc_version,  '1.16'; # minimum required version with api_version 1.16

throws_ok { new Document $meta. $blocks, pandoc_version => 1.9 } qr/too old/;

$doc1 = new Document $meta. $blocks, pandoc_version => undef; # get installed version 
$doc2 = new Document $meta. $blocks, pandoc_version => pandoc->version;
is $doc1->pandoc_version, $doc2->pandoc_version; # compare normalized values

The constructor value pandoc_version should not stored but mapped to api_version which is then mapped back to pandoc_version (kind of compatibility normalization).