(&mut self, c: Cursor)
| 33 | |
| 34 | impl<'a, T: fmt::Write> CursorSink for HTMLHighlightCursorStream<'a, T> { |
| 35 | fn append(&mut self, c: Cursor) { |
| 36 | if self.last_token.is_none() { |
| 37 | if let Err(err) = self.writer.write_str( |
| 38 | r#" |
| 39 | <!DOCTYPE html> |
| 40 | <head> |
| 41 | <style> |
| 42 | :root { background: #22272E; color: hotpink } |
| 43 | .Tag { color: #8ddb8c } |
| 44 | .Punctuation { color: #d1d7e0 } |
| 45 | .Property { color: #6cb6ff } |
| 46 | .PseudoClass { color: #6cb6ff } |
| 47 | |
| 48 | .unknown { color: grey } |
| 49 | .deprecated { text-decoration: line-through } |
| 50 | .experimental { text-decoration: wavy underline #bf4b8a 0.5px } |
| 51 | </style> |
| 52 | </head> |
| 53 | <body> |
| 54 | <pre> |
| 55 | <code> |
| 56 | "#, |
| 57 | ) { |
| 58 | self.err = Some(err); |
| 59 | } |
| 60 | } |
| 61 | if self.err.is_some() { |
| 62 | return; |
| 63 | } |
| 64 | if let Some(last) = self.last_token { |
| 65 | if last.needs_separator_for(c.into()) { |
| 66 | if let Err(err) = self.writer.write_char(' ') { |
| 67 | self.err = Some(err); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | if self.err.is_some() { |
| 72 | return; |
| 73 | } |
| 74 | self.last_token = Some(c.into()); |
| 75 | let highlight = self.highlighter.get(c.into()); |
| 76 | if let Some(highlight) = highlight { |
| 77 | if let Err(err) = |
| 78 | self.writer.write_str(format!(r#"<span class="{}{}">"#, highlight.kind, highlight.modifier).as_str()) |
| 79 | { |
| 80 | self.err = Some(err); |
| 81 | } |
| 82 | } |
| 83 | if let Err(err) = write!(&mut self.writer, "{}", SourceCursor::from(c, c.str_slice(self.source_text))) { |
| 84 | self.err = Some(err); |
| 85 | } |
| 86 | if highlight.is_some() { |
| 87 | if let Err(err) = self.writer.write_str(r#"</span>"#) { |
| 88 | self.err = Some(err); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
no test coverage detected