Skip to content

Commit 231cf08

Browse files
committed
Finish HTML POC
1 parent e438656 commit 231cf08

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

Diff for: src/renderers/ascii_default/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ impl<S: StyleTrait> Renderer<S> {
126126
let styles = [StyleType::Emphasis, style];
127127
let indent = if range.start == 0 { 0 } else { range.start + 1 };
128128
write!(w, "{:>width$}", "", width = indent)?;
129+
let horizontal_mark = MarkKind::get(MarkKind::Horizontal);
129130
if range.start == 0 {
130-
let horizontal_mark = MarkKind::get(MarkKind::Horizontal);
131131
S::fmt(
132132
w,
133133
format_args!(
@@ -191,7 +191,7 @@ impl<S: StyleTrait> Renderer<S> {
191191
}
192192
S::fmt(
193193
w,
194-
format_args!(": {}\n", annotation.label),
194+
format_args!(": {}\n", annotation.label),
195195
&[StyleType::Emphasis],
196196
)
197197
}

Diff for: src/renderers/html/mod.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,15 @@ impl Renderer {
133133
write!(w, r#" <span class="source">{}</span>"#, text)
134134
}
135135
DisplaySourceLine::Annotation { annotation, range } => {
136+
let desc = self.get_annotation_type_style(&annotation.annotation_type);
136137
let indent = if range.start == 0 { 0 } else { range.start + 1 };
137138
write!(w, "{:>width$}", "", width = indent)?;
138139
let horizontal_mark = MarkKind::get(MarkKind::Horizontal);
139140
if range.start == 0 {
140141
write!(
141142
w,
142-
"{}{} {}",
143+
r#"<span class="{}">{}{} {}</span>"#,
144+
desc,
143145
repeat(horizontal_mark)
144146
.take(range.len())
145147
.collect::<String>(),
@@ -149,7 +151,8 @@ impl Renderer {
149151
} else {
150152
write!(
151153
w,
152-
"{} {}",
154+
r#"<span class="{}">{} {}</span>"#,
155+
desc,
153156
repeat(horizontal_mark)
154157
.take(range.len())
155158
.collect::<String>(),
@@ -171,33 +174,25 @@ impl Renderer {
171174
match line {
172175
DisplayRawLine::Origin { path, pos } => {
173176
write!(w, "{:>width$}", "", width = lineno_max)?;
174-
//S::fmt(
175-
//w,
176-
//format_args!(
177-
//"{}{}>",
178-
//MarkKind::get(MarkKind::Horizontal),
179-
//MarkKind::get(MarkKind::Horizontal),
180-
//),
181-
//&[StyleType::Emphasis, StyleType::LineNo],
182-
//)?;
183-
//write!(w, " {}", path)?;
184-
//if let Some(line) = pos.0 {
185-
//write!(w, ":{}", line)?;
186-
//}
177+
write!(
178+
w,
179+
r#"<span class="ui">{}{}></span>"#,
180+
MarkKind::get(MarkKind::Horizontal),
181+
MarkKind::get(MarkKind::Horizontal),
182+
)?;
183+
write!(w, " {}", path)?;
184+
if let Some(line) = pos.0 {
185+
write!(w, ":{}", line)?;
186+
}
187187
writeln!(w)
188188
}
189189
DisplayRawLine::Annotation { annotation, .. } => {
190190
let desc = self.get_annotation_type_style(&annotation.annotation_type);
191-
//let s = [StyleType::Emphasis, style];
192-
//S::fmt(w, desc, &s)?;
193-
//if let Some(id) = annotation.id {
194-
//S::fmt(w, format_args!("[{}]", id), &s)?;
195-
//}
196-
//S::fmt(
197-
//w,
198-
//format_args!(": {}\n", annotation.label),
199-
//&[StyleType::Emphasis],
200-
//)
191+
write!(w, r#"<span class="title"><span class="{}">{}"#, desc, desc)?;
192+
if let Some(id) = annotation.id {
193+
write!(w, "[{}]", id)?;
194+
}
195+
write!(w, "</span>: {}</span>\n", annotation.label)?;
201196
Ok(())
202197
}
203198
}
@@ -219,20 +214,25 @@ impl Renderer {
219214
w: &mut impl std::io::Write,
220215
display_mark: &DisplayMark,
221216
) -> std::io::Result<()> {
217+
let desc = self.get_annotation_type_style(&display_mark.annotation_type);
222218
let ch = match display_mark.mark_type {
223219
DisplayMarkType::AnnotationStart => MarkKind::get(MarkKind::DownRight),
224220
DisplayMarkType::AnnotationEnd => MarkKind::get(MarkKind::UpRight),
225221
DisplayMarkType::AnnotationThrough => MarkKind::get(MarkKind::Vertical),
226222
};
227-
write!(w, "{}", ch)?;
223+
write!(w, r#"<span class="{}">{}</span>"#, desc, ch)?;
228224
Ok(())
229225
}
230226

231227
fn fmt_header(&self, w: &mut impl std::io::Write) -> std::io::Result<()> {
232228
writeln!(w, "<html><head><style>")?;
233-
writeln!(w, r#".lineno {{ color: red; }}"#)?;
229+
writeln!(w, r#".lineno {{ color: blue; }}"#)?;
234230
writeln!(w, r#".line {{ color: blue; }}"#)?;
231+
writeln!(w, r#".ui {{ color: blue; }}"#)?;
235232
writeln!(w, r#".source {{ color: gray; }}"#)?;
233+
writeln!(w, r#".error {{ color: red; }}"#)?;
234+
writeln!(w, r#".warning {{ color: yellow; }}"#)?;
235+
writeln!(w, r#".title {{ font-weight: bold; }}"#)?;
236236
write!(w, "</style></head><body><pre>")
237237
}
238238

0 commit comments

Comments
 (0)