@@ -93,13 +93,15 @@ mod filter {
9393/// Render html to command-line
9494mod html {
9595 // use crate::Error;
96- use colored:: Colorize ;
96+ use colored:: { Color , Colorize } ;
9797 use escaper:: decode_html;
98+ use regex:: Regex ;
9899 pub enum Token {
99100 Plain ( String ) ,
100101 Bold ( String ) ,
101102 Sup ( String ) ,
102103 Sub ( String ) ,
104+ Font ( ( String , Color ) ) ,
103105 Eof ( String ) ,
104106 }
105107
@@ -176,6 +178,8 @@ mod html {
176178 let mut bold = false ;
177179 let mut sup = false ;
178180 let mut sub = false ;
181+ let mut color: Option < Color > = None ;
182+ let re_color = Regex :: new ( r#"color=['"]([^'"]+)"# ) . unwrap ( ) ;
179183 for ( i, e) in tks. chars ( ) . enumerate ( ) {
180184 match e {
181185 '<' => {
@@ -188,6 +192,9 @@ mod html {
188192 } else if sub {
189193 output. push ( Token :: Sub ( tks[ ptr..i] . to_string ( ) ) ) ;
190194 sub = false ;
195+ } else if color. is_some ( ) {
196+ output. push ( Token :: Font ( ( tks[ ptr..i] . to_string ( ) , color. unwrap ( ) ) ) ) ;
197+ color = None ;
191198 } else {
192199 output. push ( Token :: Plain ( tks[ ptr..i] . to_string ( ) ) ) ;
193200 }
@@ -200,6 +207,12 @@ mod html {
200207 "b" | "strong" => bold = true ,
201208 "sup" => sup = true ,
202209 "sub" => sub = true ,
210+ s if s. starts_with ( "font" ) => {
211+ color = re_color
212+ . captures ( s)
213+ . and_then ( |caps| caps. get ( 1 ) )
214+ . and_then ( |cap| cap. as_str ( ) . parse ( ) . ok ( ) ) ;
215+ }
203216 _ => { }
204217 } ,
205218 }
@@ -243,6 +256,7 @@ mod html {
243256 Ok ( n) => subscript ( n) ,
244257 _ => s,
245258 } ) ,
259+ Token :: Font ( ( s, color) ) => tks. push ( s. color ( color) . to_string ( ) ) ,
246260 Token :: Eof ( s) => tks. push ( s. normal ( ) . to_string ( ) ) ,
247261 }
248262 }
0 commit comments