/[pub]/suikawiki/script/misc/plugins/SW09toTeX.wps
Suika

Contents of /suikawiki/script/misc/plugins/SW09toTeX.wps

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sat Feb 14 10:53:48 2004 UTC (21 years, 2 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
Removed

1 wakaba 1.1 Name:
2     SW09toTeX
3     FullName:
4     SuikaWiki/0.9 to TeX converter
5     URI:
6     IW:SuikaWiki:SuikaWiki
7     Require:
8     SuikaWiki::Plugin::SuikaWiki09XML
9     Initialize:
10     my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
11     my $NS_SW09 = 'urn:x-suika-fam-cx:markup:suikawiki:0:9:';
12    
13     {
14     Name:
15     wikiformat/SuikaWiki/0.9-to-TeX
16     FullName:
17     SuikaWiki/0.9 wiki syntax -> TeX
18     URI:
19     IW:SuikaWiki:SuikaWiki
20     Format:
21     $r = xml2tex (SuikaWiki::Plugin::SuikaWiki09XML::wiki2xml ($o->{content}, %$o), $o);
22     }
23    
24     MODULE:
25     my %_x2t;
26     %_x2t = (
27     $NS_SW09.'anchor-end' => sub {
28     my $x = shift;
29     &{$_x2t{_escape}} (q( [).$x->inner_text . q(] ));
30     },
31     $NS_SW09.'body' => sub {
32     my ($x, $opt) = @_;
33     qq(\\documentclass{jarticle}
34     \\usepackage{txfonts}
35     \\title{@{[&{$_x2t{_escape}} ($opt->{page})]}}
36     \\author{SuikaWiki}
37     \\date{@{[do {#my $d = $opt->get_data (lastmodified
38     # => split (m#//#, $opt->{page}));
39     my $d = $opt->_database->mtime ($opt->{page});
40     sprintf '%d-%02d-%02d', (gmtime $d)[5]+1900,
41     (gmtime $d)[4] + 1,
42     (gmtime $d)[3]}]}}
43     \\begin{document}
44     \\maketitle\n)
45     .&{$_x2t{_children}} ($x, $opt)
46     .qq(\\end{document}\n);
47     },
48     $NS_XHTML1.'h1' => sub {
49     my ($x, $opt) = @_;
50     qq(\\section{).&{$_x2t{_escape}} ($x->inner_text).qq(}\n);
51     },
52     $NS_XHTML1.'h2' => sub {
53     my ($x, $opt) = @_;
54     qq(\\subsection{).&{$_x2t{_escape}} ($x->inner_text).qq(}\n);
55     },
56     $NS_XHTML1.'h3' => sub {
57     my ($x, $opt) = @_;
58     qq(\\subsubsection{).&{$_x2t{_escape}} ($x->inner_text).qq(}\n);
59     },
60     $NS_XHTML1.'h4' => sub {
61     my ($x, $opt) = @_;
62     qq(\\subsubsubsection{).&{$_x2t{_escape}} ($x->inner_text).qq(}\n);
63     },
64     $NS_XHTML1.'h5' => sub {
65     my ($x, $opt) = @_;
66     qq(\\subsubsubsubsection{).&{$_x2t{_escape}} ($x->inner_text).qq(}\n);
67     },
68     $NS_XHTML1.'p' => sub {
69     my ($x, $opt) = @_;
70     qq(\n)
71     .&{$_x2t{_children}} ($x, $opt)
72     .qq(\n);
73     },
74     $NS_XHTML1.'pre' => sub {
75     my ($x, $opt) = @_;
76     qq(\\begin{verbatim}\n)
77     #.&{$_x2t{_children}} ($x, $opt)
78     .$x->inner_text
79     .qq(\\end{verbatim}\n);
80     },
81     $NS_XHTML1.'ul' => sub {
82     my ($x, $opt) = @_;
83     qq(\\begin{itemize}\n)
84     .&{$_x2t{_children}} ($x, $opt)
85     .qq(\\end{itemize}\n);
86     },
87     $NS_XHTML1.'li' => sub {
88     my ($x, $opt) = @_;
89     qq(\\item ).&{$_x2t{_children}} ($x, $opt) . qq(\n);
90     },
91     $NS_SW09.'dr' => sub {
92     my ($x, $opt) = @_;
93     qq(\\item ).&{$_x2t{_children}} ($x, $opt) . qq(\n);
94     },
95     $NS_XHTML1.'dt' => sub {
96     my ($x, $opt) = @_;
97     qq([).&{$_x2t{_children}} ($x, $opt).qq(] );
98     },
99     $NS_XHTML1.'em' => sub {
100     my ($x, $opt) = @_;
101     qq(\\sf{).&{$_x2t{_children}} ($x, $opt).qq(});
102     },
103     $NS_XHTML1.'strong' => sub {
104     my ($x, $opt) = @_;
105     qq(\\bf{\\sf{).&{$_x2t{_children}} ($x, $opt).qq(}});
106     },
107     $NS_SW09.'uri' => sub {
108     my ($x, $opt) = @_;
109     q($<$).&{$_x2t{_children}} ($x, $opt).q($>$);
110     },
111     $NS_SW09.'fragment' => sub {
112     my ($x, $opt) = @_;
113     q($ >>$).&{$_x2t{_children}} ($x, $opt).q( );
114     },
115     _children => sub {
116     my ($x, $opt) = @_;
117     my $r = '';
118     for (@{$x->child_nodes}) {
119     my $en = $_->expanded_name;
120     if ($_x2t{$en}) {
121     $r .= &{$_x2t{$en}} ($_, $opt);
122     } elsif ($_->node_type eq '#element') {
123     $r .= &{$_x2t{_children}} ($_, $opt);
124     } elsif ($_->node_type ne '#attribute') {
125     $r .= &{$_x2t{_escape}} ($_->inner_text);
126     }
127     }
128     $r;
129     },
130     _escape => sub {
131     my $s = shift;
132     $s =~ s{([\\{}\@!?\[\]<>%_\#\$])}{
133     {'','',
134     qw{\\ $\\$ ! $!$ ? $?$ [ $[$ ] $]$
135     < $<$ > $>$ % \\% _ \\_ # \\# $ \\$ & \\&
136     @ \\verb,@, ^ \\verb,^, ~ \\verb,~,
137     { \{ } \}}
138     }->{$1}
139     }ge;
140     $s;
141     },
142     );
143     sub xml2tex ($$) {
144     my ($x, $opt) = @_;
145     &{$_x2t{_children}} ($x, $opt);
146     }
147    
148     SuikaWiki::View->definition (sw09t__tex => {
149     media => {type => 'text/plain', expires => 240*3600,
150     charset => 1},
151     check => sub { ($_->[0]->{magic}||'SuikaWiki/0.9') =~ m!SuikaWiki/0\.9! ? 1 : 0 },
152     template => '%read(to=>TeX);'});
153    
154    
155     POD:LICENSE:
156     Copyright 2003 Wakaba <w@suika.fam.cx>
157    
158     %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24  
Google Analytics is used in this page; Cookies are used. 忍者AdMax is used in this page; Cookies are used. Privacy policy.