]>
git.immae.eu Git - perso/Immae/Projets/Scripts/Public.git/blob - parse_bibtex_html
2 # The MIT License (MIT)
4 # Copyright (c) 2011-2015 Ismaël Bouya http://www.normalesup.org/~bouya/
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 sub parse_config_file
{
32 my ($config_line, $Name, $Value, $Config);
33 (my $File, $Config) = @_;
34 if (!open (CONFIG
, "$File")) {
35 print "ERROR: Config file not found : $File";
43 $config_line =~ s/^\s*//;
44 $config_line =~ s/\s*$//;
45 if ( ($config_line !~ /^#/) && ($config_line ne "") ){
47 $$Config{$Name} =~ s/\\$//;
48 $$Config{$Name} .= $config_line;
50 ($Name, $Value) = split (/\s*=\s*/, $config_line);
51 $Value =~ s/^~/$ENV{"HOME"}/;
52 $$Config{$Name} = $Value;
54 $multiline = ($$Config{$Name} =~ /\\$/);
61 &parse_config_file
($ENV{"HOME"}."/.parse_bibtex_html.rc", \
%Config);
63 my $biblio = $Config{"biblio"};
64 my $entete = $Config{"entete"};
65 my $avant = $Config{"avant"};
66 my $milieu = $Config{"milieu"};
67 my $apres = $Config{"apres"};
68 my $html = $Config{"html"};
70 my $dossier = $Config{"dossier"};
71 my $dossierweb = $Config{"dossier_web"};
73 # http://webdesign.about.com/library/bl_htmlcodes.htm
75 my $t = shift or return;
82 $t =~ s/{?\\'a}?/á/g;
83 $t =~ s/{?\\`a}?/à/g;
84 $t =~ s/{?\\"a}?/ä/g;
86 $t =~ s/{?\\r A}?/Å/g;
88 $t =~ s/{?\\'e}?/é/g;
89 $t =~ s/{?\\`e}?/è/g;
90 $t =~ s/{?\\'E}?/É/g;
91 $t =~ s/{?\\"e}?/ë/g;
93 $t =~ s/{?\\\^i}?/î/g;
94 $t =~ s/{?\\"i}?/ï/g;
96 $t =~ s/{?\\"o}?/ö/g;
97 $t =~ s/{?\\"o}?/ö/g;
98 $t =~ s/{?\\=o}?/ō/g;
99 $t =~ s/{?\\o}?/ø/g;
101 $t =~ s/{?\\"u}?/ü/g;
102 $t =~ s/{?\\'u}?/ú/g;
104 $t =~ s/{?\\~n}?/ñ/g;
106 $t =~ s/{?\\c{?c}?}? ?/ç/g;
107 $t =~ s/{?\\'{?c}?}? ?/ć/g;
109 $t =~ s/{?\\v{? ?s}?}? ?/š/g;
111 $t =~ s/{?\^({[^}]+}|.)}?/<sup>$1<\/sup>/g
;
117 opendir(DIR
, $dossier);
118 my @FILES = readdir(DIR
);
119 my $fh = IO
::File-
>new($biblio);
120 my $parser = BibTeX
::Parser-
>new($fh);
124 while (my $entry = $parser->next ) {
125 if ($entry->parse_ok) {
126 my $type = $entry->type;
127 my $title = $entry->field("title");
128 my $key = $entry->key;
129 my @authors = $entry->author;
130 # my @editors = $entry->editor;
132 my @authors_sort = ();
133 foreach my $author (@authors) {
134 $auth .= (($author->first)?$author->first. " ":"") .(($author->von)?$author->von." ":"") . (($author->last)?$author->last:"") . ", ";
135 push(@authors_sort,$author->last);
137 @authors_sort = sort {lc $a cmp lc $b} @authors_sort;
138 my $cle_sort = shift(@authors_sort);
139 $auth = substr $auth, 0 , -2;
140 my $suffix = '(\.|_)';
141 my @match = grep(/^$key$suffix/,@FILES);
143 my $chaine = "\t\t<li>";
145 $title = echap
$title;
146 if($auth =~ m/\\/ || $title =~ m/\\/) {
147 warn "Unparsed item : $auth, $title";
149 $chaine .= "<span class='biblio_titre'>".$title."</span><br />".$auth."<br />\n";
150 @match = sort {lc $a cmp lc $b} @match;
151 foreach my $item (@match) {
152 $chaine .= "\t\t\t<a href='".$dossierweb.$item."'>fichier ".$i++."</a> \n";
154 $chaine .="\t\t\t<a id='".$key."' href='#".$key."' class='bibtex'>BibTeX</a>\n";
155 my $raw = $entry->raw_bibtex;
157 $chaine .= "\t\t\t<pre class='bibtex'>".$raw."</pre>\n";
158 $chaine .= "\t\t\t</li>\n";
159 $liste{$cle_sort." ".$key} = $chaine;
161 warn "Error parsing file: " . $entry->error;
165 foreach my $key (sort keys %liste) {
166 print F
$liste{$key};
172 exec "cat $entete $avant $milieu $apres 1> $html" or die "$!\n";