File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -318,6 +318,40 @@ impl Term {
318318 }
319319 writeln ! ( buffer, r#" </div>"# ) . unwrap ( ) ;
320320 }
321+
322+ /// Returns the various parts needed to create an HTML page.
323+ pub fn render_html_fragments ( & self , ansi : & str ) -> HtmlFragments {
324+ let mut styled = adapter:: AnsiBytes :: new ( ) ;
325+ let mut elements = styled. extract_next ( ansi. as_bytes ( ) ) . collect :: < Vec < _ > > ( ) ;
326+ preprocess_invert_style ( & mut elements, self . bg_color , self . fg_color ) ;
327+
328+ let styled_lines = split_lines ( & elements) ;
329+
330+ let mut style = String :: new ( ) ;
331+ let mut body = String :: new ( ) ;
332+
333+ self . render_classes ( & mut style, & elements) ;
334+ self . render_content ( & mut body, styled_lines) ;
335+ HtmlFragments { style, body }
336+ }
337+ }
338+
339+ /// Contains the different parts of a HTML rendered page.
340+ pub struct HtmlFragments {
341+ style : String ,
342+ body : String ,
343+ }
344+
345+ impl HtmlFragments {
346+ /// Content that can be used directly in a `<style>` tag.
347+ pub fn style ( & self ) -> & str {
348+ & self . style
349+ }
350+
351+ /// Content that can be put in the HTML body or any tag inside the `<body>`.
352+ pub fn body ( & self ) -> & str {
353+ & self . body
354+ }
321355}
322356
323357const FG_COLOR : anstyle:: Color = anstyle:: Color :: Ansi ( anstyle:: AnsiColor :: White ) ;
You can’t perform that action at this time.
0 commit comments