summaryrefslogtreecommitdiff
path: root/pandoc-cs1
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2015-01-10 05:32:21 +0100
committerJonas Smedegaard <dr@jones.dk>2015-01-10 05:32:21 +0100
commit7c8fed57a7c3d95fd1fd7c68a5bf628e0d685cbd (patch)
tree252ee93c4bbd150f2b9d011ab212e54f9b3059d6 /pandoc-cs1
parent3dc780f668a50e894e9807e1b26643becb404378 (diff)
Recode CS1 "web" as biblatex "online".
Diffstat (limited to 'pandoc-cs1')
-rwxr-xr-xpandoc-cs124
1 files changed, 17 insertions, 7 deletions
diff --git a/pandoc-cs1 b/pandoc-cs1
index 89595b2..1a2f843 100755
--- a/pandoc-cs1
+++ b/pandoc-cs1
@@ -9,11 +9,15 @@ no if $] >= 5.018, warnings => "experimental::smartmatch";
use Pandoc::Filter 0.05;
use Pandoc::Elements;
+use Text::BibTeX::Entry;
use Path::Tiny;
use List::Util qw(pairmap);
+use DateTime::Format::Flexible;
+
my $bibfilename = $ENV{'PANDOC_CITEPROC_FILE'} || 'bibliography.bib';
my $bibfile = path($bibfilename);
+my $bibdata = new Text::BibTeX::Entry;
my (@a, $i);
@@ -27,10 +31,21 @@ pandoc_filter sub {
my @data = pairmap { $b =~ s/"/\\"/g; "$a=\"$b\"" }
map { /^\s*(\w+)\s*=\s*"?(.*?)"?\s*$/ }
split( /\|/, $2 );
- push @a, join ",\n",
+ $bibdata->parse_s (join ",\n",
'@'.$1.'{'.$id,
@data,
- '}';
+ '}');
+ if ( $bibdata->type =~ /web/i ) {
+ $bibdata->set_type('online');
+ if ( my $urldate = $bibdata->get('accessdate') ) {
+ my $dt = DateTime::Format::Flexible->parse_datetime($urldate);
+ $bibdata->set( 'urldate', $dt->format_cldr('yyyy-MM-dd') );
+ $bibdata->delete('accessdate');
+ };
+ };
+ $bibfile->spew( '' )
+ if ( $i <= 1 );
+ $bibfile->append_utf8( $bibdata->print_s );
return Cite(
[{
'citationId' => $id,
@@ -61,8 +76,3 @@ pandoc_filter sub {
}
}
};
-
-END {
- $bibfile->spew_utf8( join "\n\n", @a )
- if (@a);
-}