]>
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
25 # Feel like tipping/donating? https://www.immae.eu/licenses_and_tipping
34 sub parse_config_file
{
35 my ($config_line, $Name, $Value, $Config);
36 (my $File, $Config) = @_;
37 if (!open (CONFIG
, "$File")) {
38 print "ERROR: Config file not found : $File";
46 $config_line =~ s/^\s*//;
47 $config_line =~ s/\s*$//;
48 if ( ($config_line !~ /^#/) && ($config_line ne "") ){
50 $$Config{$Name} =~ s/\\$//;
51 $$Config{$Name} .= $config_line;
53 ($Name, $Value) = split (/\s*=\s*/, $config_line);
54 $Value =~ s/^~/$ENV{"HOME"}/;
55 $$Config{$Name} = $Value;
57 $multiline = ($$Config{$Name} =~ /\\$/);
64 &parse_config_file
($ENV{"HOME"}."/.parse_bibtex_html.rc", \
%Config);
66 my $biblio = $Config{"biblio"};
67 my $entete = $Config{"entete"};
68 my $avant = $Config{"avant"};
69 my $milieu = $Config{"milieu"};
70 my $apres = $Config{"apres"};
71 my $html = $Config{"html"};
73 my $dossier = $Config{"dossier"};
74 my $dossierweb = $Config{"dossier_web"};
76 # http://webdesign.about.com/library/bl_htmlcodes.htm
78 my $t = shift or return;
85 $t =~ s/{?\\'a}?/á/g;
86 $t =~ s/{?\\`a}?/à/g;
87 $t =~ s/{?\\"a}?/ä/g;
89 $t =~ s/{?\\r A}?/Å/g;
91 $t =~ s/{?\\'e}?/é/g;
92 $t =~ s/{?\\`e}?/è/g;
93 $t =~ s/{?\\'E}?/É/g;
94 $t =~ s/{?\\"e}?/ë/g;
96 $t =~ s/{?\\\^i}?/î/g;
97 $t =~ s/{?\\"i}?/ï/g;
99 $t =~ s/{?\\"o}?/ö/g;
100 $t =~ s/{?\\"o}?/ö/g;
101 $t =~ s/{?\\=o}?/ō/g;
102 $t =~ s/{?\\o}?/ø/g;
104 $t =~ s/{?\\"u}?/ü/g;
105 $t =~ s/{?\\'u}?/ú/g;
107 $t =~ s/{?\\~n}?/ñ/g;
109 $t =~ s/{?\\c\{?c\}?}? ?/ç/g;
110 $t =~ s/{?\\'\{?c\}?}? ?/ć/g;
112 $t =~ s/{?\\v\{? ?s\}?}? ?/š/g;
114 $t =~ s/{?\^({[^}]+}|.)}?/<sup>$1<\/sup>/g
;
120 opendir(DIR
, $dossier);
121 my @FILES = readdir(DIR
);
122 my $fh = IO
::File-
>new($biblio);
123 my $parser = BibTeX
::Parser-
>new($fh);
127 while (my $entry = $parser->next ) {
128 if ($entry->parse_ok) {
129 my $type = $entry->type;
130 my $title = $entry->field("title");
131 my $key = $entry->key;
132 my @authors = $entry->author;
133 # my @editors = $entry->editor;
135 my @authors_sort = ();
136 foreach my $author (@authors) {
137 $auth .= (($author->first)?$author->first. " ":"") .(($author->von)?$author->von." ":"") . (($author->last)?$author->last:"") . ", ";
138 push(@authors_sort,$author->last);
140 @authors_sort = sort {lc $a cmp lc $b} @authors_sort;
141 my $cle_sort = shift(@authors_sort);
142 $auth = substr $auth, 0 , -2;
143 my $suffix = '(\.|_)';
144 my @match = grep(/^$key$suffix/,@FILES);
146 my $chaine = "\t\t<li>";
148 $title = echap
$title;
149 if($auth =~ m/\\/ || $title =~ m/\\/) {
150 warn "Unparsed item : $auth, $title";
152 $chaine .= "<span class='biblio_titre'>".$title."</span><br />".$auth."<br />\n";
153 @match = sort {lc $a cmp lc $b} @match;
154 foreach my $item (@match) {
155 $chaine .= "\t\t\t<a href='".$dossierweb.$item."'>fichier ".$i++."</a> \n";
157 $chaine .="\t\t\t<a id='".$key."' href='#".$key."' class='bibtex'>BibTeX</a>\n";
158 my $raw = $entry->raw_bibtex;
160 $chaine .= "\t\t\t<pre class='bibtex'>".$raw."</pre>\n";
161 $chaine .= "\t\t\t</li>\n";
162 $liste{$cle_sort." ".$key} = $chaine;
164 warn "Error parsing file: " . $entry->error;
168 foreach my $key (sort keys %liste) {
169 print F
$liste{$key};
175 exec "cat $entete $avant $milieu $apres 1> $html" or die "$!\n";