@@ -3,7 +3,7 @@ use syntect::easy::HighlightLines;
33use syntect:: highlighting:: ThemeSet ;
44use syntect:: html:: {
55 ClassStyle , ClassedHTMLGenerator , IncludeBackground , append_highlighted_html_for_styled_line,
6- start_highlighted_html_snippet,
6+ css_for_theme_with_class_style , start_highlighted_html_snippet,
77} ;
88use syntect:: parsing:: { SyntaxReference , SyntaxSet } ;
99use syntect:: util:: LinesWithEndings ;
@@ -34,6 +34,10 @@ impl Syntax {
3434 self . syntax_set = builder. build ( ) ;
3535 }
3636
37+ pub fn css_theme_name ( ) -> & ' static str {
38+ CSS_THEME
39+ }
40+
3741 pub fn has_theme ( & self , name : & str ) -> bool {
3842 name == CSS_THEME || self . theme_set . themes . contains_key ( name)
3943 }
@@ -46,6 +50,16 @@ impl Syntax {
4650 themes. into_iter ( )
4751 }
4852
53+ fn css_class_style ( ) -> ClassStyle {
54+ ClassStyle :: SpacedPrefixed { prefix : "c-" }
55+ }
56+
57+ /// Get the content of a css file to apply the specified color theme when using the 'css' theme
58+ pub fn css_for_theme ( & self , name : & str ) -> String {
59+ let theme = & self . theme_set . themes [ name] ;
60+ css_for_theme_with_class_style ( theme, Self :: css_class_style ( ) ) . unwrap ( )
61+ }
62+
4963 pub fn syntaxes ( & self ) -> impl Iterator < Item = String > + ' _ {
5064 fn reference_to_string ( sd : & SyntaxReference ) -> String {
5165 let extensions = sd. file_extensions . join ( ", " ) ;
@@ -101,7 +115,7 @@ impl Syntax {
101115 let mut html_generator = ClassedHTMLGenerator :: new_with_class_style (
102116 syntax,
103117 & self . syntax_set ,
104- ClassStyle :: SpacedPrefixed { prefix : "c-" } ,
118+ Self :: css_class_style ( ) ,
105119 ) ;
106120
107121 for line in LinesWithEndings :: from ( code) {
0 commit comments