MCPcopy Create free account
hub / github.com/csskit/csskit / append

Method append

crates/csskit_highlight/src/test_helpers.rs:35–91  ·  view source on GitHub ↗
(&mut self, c: Cursor)

Source from the content-addressed store, hash-verified

33
34impl<'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}

Callers 1

render_textMethod · 0.45

Calls 4

write_strMethod · 0.80
needs_separator_forMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected