@@ -112,58 +112,40 @@ mod html {
112
112
}
113
113
114
114
pub fn superscript ( n : u8 ) -> String {
115
- if n == 0 {
116
- "0" . to_owned ( )
117
- } else if n == 1 {
118
- "1" . to_owned ( )
119
- } else if n == 2 {
120
- "2" . to_owned ( )
121
- } else if n == 3 {
122
- "3" . to_owned ( )
123
- } else if n == 4 {
124
- "4" . to_owned ( )
125
- } else if n == 5 {
126
- "5" . to_owned ( )
127
- } else if n == 6 {
128
- "6" . to_owned ( )
129
- } else if n == 7 {
130
- "7" . to_owned ( )
131
- } else if n == 8 {
132
- "8" . to_owned ( )
133
- } else if n == 9 {
134
- "9" . to_owned ( )
135
- } else if n >= 10 {
136
- superscript ( n / 10 ) + & superscript ( n % 10 )
137
- } else {
138
- n. to_string ( )
115
+ match n {
116
+ 0 => "0" . to_string ( ) ,
117
+ 1 => "1" . to_string ( ) ,
118
+ 2 => "2" . to_string ( ) ,
119
+ 3 => "3" . to_string ( ) ,
120
+ 4 => "4" . to_string ( ) ,
121
+ 5 => "5" . to_string ( ) ,
122
+ 6 => "6" . to_string ( ) ,
123
+ 7 => "7" . to_string ( ) ,
124
+ 8 => "8" . to_string ( ) ,
125
+ 9 => "9" . to_string ( ) ,
126
+ x if x > 10 => ( superscript ( n / 10 ) . parse ( ) . unwrap_or ( 0 )
127
+ + & superscript ( n % 10 ) . parse ( ) . unwrap_or ( 0 ) )
128
+ . to_string ( ) ,
129
+ _ => n. to_string ( ) ,
139
130
}
140
131
}
141
132
142
133
pub fn subscript ( n : u8 ) -> String {
143
- if n >= 10 {
144
- subscript ( n / 10 ) + & subscript ( n % 10 )
145
- } else if n == 0 {
146
- "0" . to_owned ( )
147
- } else if n == 1 {
148
- "1" . to_owned ( )
149
- } else if n == 2 {
150
- "2" . to_owned ( )
151
- } else if n == 3 {
152
- "3" . to_owned ( )
153
- } else if n == 4 {
154
- "4" . to_owned ( )
155
- } else if n == 5 {
156
- "5" . to_owned ( )
157
- } else if n == 6 {
158
- "6" . to_owned ( )
159
- } else if n == 7 {
160
- "7" . to_owned ( )
161
- } else if n == 8 {
162
- "8" . to_owned ( )
163
- } else if n == 9 {
164
- "9" . to_owned ( )
165
- } else {
166
- n. to_string ( )
134
+ match n {
135
+ x if x >= 10 => ( subscript ( n / 10 ) . parse ( ) . unwrap_or ( 0 )
136
+ + & subscript ( n % 10 ) . parse ( ) . unwrap_or ( 0 ) )
137
+ . to_string ( ) ,
138
+ 0 => "0" . to_string ( ) ,
139
+ 1 => "1" . to_string ( ) ,
140
+ 2 => "2" . to_string ( ) ,
141
+ 3 => "3" . to_string ( ) ,
142
+ 4 => "4" . to_string ( ) ,
143
+ 5 => "5" . to_string ( ) ,
144
+ 6 => "6" . to_string ( ) ,
145
+ 7 => "7" . to_string ( ) ,
146
+ 8 => "8" . to_string ( ) ,
147
+ 9 => "9" . to_string ( ) ,
148
+ _ => n. to_string ( ) ,
167
149
}
168
150
}
169
151
impl HTML for String {
@@ -179,6 +161,12 @@ mod html {
179
161
let mut sup = false ;
180
162
let mut sub = false ;
181
163
let mut color: Option < Color > = None ;
164
+
165
+ // TODO: check how to make this `unwrap` more flexible..
166
+ //
167
+ // or looks better.
168
+ //
169
+ // or do some handwrite matching.
182
170
let re_color = Regex :: new ( r#"color=['"]([^'"]+)"# ) . unwrap ( ) ;
183
171
for ( i, e) in tks. chars ( ) . enumerate ( ) {
184
172
match e {
0 commit comments