Check-in [c02a8003d5]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Sync Tex2fb2 with spacians version
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c02a8003d5d8e6744382b6e08722ee05f369deae
User & Date: vitus@wagner.pp.ru 2017-07-17 18:27:48
Context
2017-07-23
18:21
Пико и жрец Эксгиля check-in: 9eda9104d3 user: vitus@wagner.pp.ru tags: trunk
2017-07-17
18:27
Sync Tex2fb2 with spacians version check-in: c02a8003d5 user: vitus@wagner.pp.ru tags: trunk
18:17
Fix new perl warnings check-in: 5856b45662 user: vitus@wagner.pp.ru tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Tex2fb2.

1

2
3
4
5
6
7
8
..
31
32
33
34
35
36
37


38
39

40
41

42

43
44
45
46
47
48
49
..
96
97
98
99
100
101
102

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
...
190
191
192
193
194
195
196
197
198
199












200
201
202
203
204
205
206
207
208



209

210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/perl -CDS

use utf8;
use POSIX qw(strftime);
use MIME::Base64;
# char-level modes
my $poetry = 0;
my $verbatim = 0;
my @sections;
................................................................................
	if (/<version>(\d*)(.\d*)?<\/version>/) {
		my $ver = $1+time()/1E10;
		$_=tag(sprintf("%g",$ver),"version")."\n";
	}
	# Если  существует cover.png, добавляем coverpage
	if (/<coverpage \/>/) {
		$_="";


		if (-f "cover.png") { 
			my $id = "cover_png";

			$_ = "<coverpage>\n<image l:href=\"#$id\" />\n</coverpage>\n";
			$pics .= mkbinary("cover.png",$id);

		}

	}
	print $_;
}
close F;
print "<body>\n";
my $header =1;
LINE:
................................................................................
s/>/&gt;/g;
#normal mode: 
if (!$verbatim) {
#strip TeX comments 
s/([^\\])%.*$/$1/;
s/^%.*$//;
# strip \sloppy

s/\\sloppy\s+//g;
s/\\sloppy\{\}//g;
s/\\sloppy([^\w])/$1/g;
# strip extra space
s/^\s+//;
s/\s+$//;
s/(\s)\s+/$1/g;
#replace TeX ligatures ~ --- << >> \% with appropriate unicode symbols
s/~/\xA0/g;
s/\\-/\xAD/g;
s/---/—/g;
s/<</«/g;
s/>>/»/g;
s/\\%/%/g;
s/\\dots/\x{2026}/g;
s/\\verb(.)(.*)\1/<code>$2<\/code>/;
}

if ($poetry) {
	chomp;
	if ($poetic_buffer) {
		$_ = $poetic_buffer." ".$_;
		$poetic_buffer = undef;
	}
	if (/{[^}]+$/) {
		$poetic_buffer=$_;
		next LINE;
	}
	s/\\footnote\{(.*)\}/push_footnote($1)/e;
	s/\s*\\\\$//;
  $buffer.=tag($_,'v')."\n";
} elsif ($verbatim) {
	add_to_section(tag(tag($_,"code"),"p"));
} else {
  $buffer.=" ".$_;
}
}
if ($buffer) {
................................................................................
			last LEVEL;
		}
	}
	# if found, flush everything below
	while (scalar(@sections) > $found) {
		flushsection;
	}
	push @sections,{level=>$level,title=>$title,data=>""};
}













sub tag {
	my ($content,$name) = @_;
	$content =~s/^\s+//s;
	return "" unless $content;
	return "<$name>$content</$name>";
}

sub flushbuffer {
	local $_ = shift;



	s/\{\\(em|it|bf)(?:\s+|\{\})([^{}]+)\}/<emphasis>$2<\/emphasis>/g;

	s/\\(emph|textit|textbf)\{([^{}]+)\}/<emphasis>$2<\/emphasis>/g;
	s/\\footnote\{(.*)\}/push_footnote($1)/e;
	s/[{}]//g;
	return $_;
}


sub push_footnote {
	my $id = "note_".(++$idseq);
	$footnotes.="<section id=\"$id\">".tag(shift,'p')."</section>\n";
	return "<a l:href=\"#$id\" type=\"note\">$idseq</a>";
}

sub mkbinary {
	my ($filename,$id) = @_;
	my $f;
	open $f,"<",$filename;
	binmode $f;
	local $/;
	my $data = encode_base64(<$f>);
	return "<binary id=\"$id\" content-type=\"image/png\">$data</binary>\n";
	close $f;
}

>







 







>
>
|
|
>
|
|
>
|
>







 







>








|
<
<
<
<
<
<
<












<

|







 







|


>
>
>
>
>
>
>
>
>
>
>
>









>
>
>
|
>

<







|













1
2
3
4
5
6
7
8
9
..
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118







119
120
121
122
123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
139
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/perl -CDS

use utf8;
use POSIX qw(strftime);
use MIME::Base64;
# char-level modes
my $poetry = 0;
my $verbatim = 0;
my @sections;
................................................................................
	if (/<version>(\d*)(.\d*)?<\/version>/) {
		my $ver = $1+time()/1E10;
		$_=tag(sprintf("%g",$ver),"version")."\n";
	}
	# Если  существует cover.png, добавляем coverpage
	if (/<coverpage \/>/) {
		$_="";
		COVER:
		for $file ("cover.jpg","cover.png") {
			if (-f $file) { 
				my $id = $file;
				$id=~tr/./_/;
				$_ = "<coverpage>\n<image l:href=\"#$id\" />\n</coverpage>\n";
				$pics .= mkbinary($file,$id);
				last COVER;
			}
		}	
	}
	print $_;
}
close F;
print "<body>\n";
my $header =1;
LINE:
................................................................................
s/>/&gt;/g;
#normal mode: 
if (!$verbatim) {
#strip TeX comments 
s/([^\\])%.*$/$1/;
s/^%.*$//;
# strip \sloppy
s/\\(\w+)\\sloppy/\\$1/g;
s/\\sloppy\s+//g;
s/\\sloppy\{\}//g;
s/\\sloppy([^\w])/$1/g;
# strip extra space
s/^\s+//;
s/\s+$//;
s/(\s)\s+/$1/g;
#replace TeX ligatures ~ --- << >> \% with appropriate unicode symbols
$_ = fix_ligatures($_);







}

if ($poetry) {
	chomp;
	if ($poetic_buffer) {
		$_ = $poetic_buffer." ".$_;
		$poetic_buffer = undef;
	}
	if (/{[^}]+$/) {
		$poetic_buffer=$_;
		next LINE;
	}

	s/\s*\\\\$//;
  $buffer.=tag(flushbuffer($_),'v')."\n";
} elsif ($verbatim) {
	add_to_section(tag(tag($_,"code"),"p"));
} else {
  $buffer.=" ".$_;
}
}
if ($buffer) {
................................................................................
			last LEVEL;
		}
	}
	# if found, flush everything below
	while (scalar(@sections) > $found) {
		flushsection;
	}
	push @sections,{level=>$level,title=>fix_ligatures($title),data=>""};
}

sub fix_ligatures {
	local $_=shift;
	s/~/\xA0/g;
	s/\\-/\xAD/g;
	s/---/—/g;
	s/<</«/g;
	s/>>/»/g;
	s/\\%/%/g;
	s/\\dots/\x{2026}/g;
	s/\\verb(.)(.*)\1/<code>$2<\/code>/;
	return $_;
}	
sub tag {
	my ($content,$name) = @_;
	$content =~s/^\s+//s;
	return "" unless $content;
	return "<$name>$content</$name>";
}

sub flushbuffer {
	local $_ = shift;

	s/\\footnote\{(.*)\}/push_footnote($1)/e;
	$_.="}" if (/^\s*\{.*?[^}]$/) ;
	s/\{\\(em|it|bf)(?:\s+| \{\})([^{}]+)}/<emphasis>$2<\/emphasis>/g;
	s/\{\\(tt)(?:\s+|\{\})([^{}]+)}/<code>$2<\/code>/g;
	s/\\(emph|textit|textbf)\{([^{}]+)\}/<emphasis>$2<\/emphasis>/g;

	s/[{}]//g;
	return $_;
}


sub push_footnote {
	my $id = "note_".(++$idseq);
	$footnotes.="<section id=\"$id\">".tag(flushbuffer(shift),'p')."</section>\n";
	return "<a l:href=\"#$id\" type=\"note\">$idseq</a>";
}

sub mkbinary {
	my ($filename,$id) = @_;
	my $f;
	open $f,"<",$filename;
	binmode $f;
	local $/;
	my $data = encode_base64(<$f>);
	return "<binary id=\"$id\" content-type=\"image/png\">$data</binary>\n";
	close $f;
}