Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite438656

Browse files
committed
Continue re-adding features for POC of HTML renderer
1 parente56d235 commite438656

File tree

2 files changed

+81
-36
lines changed

2 files changed

+81
-36
lines changed

‎src/renderers/ascii_default/mod.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ impl<S: StyleTrait> Renderer<S> {
132132
w,
133133
format_args!(
134134
"{}{} {}",
135-
repeat(horizontal_mark).take(5).collect::<String>(),
135+
repeat(horizontal_mark)
136+
.take(range.len())
137+
.collect::<String>(),
136138
MarkKind::get(MarkKind::UpLeft),
137139
annotation.label,
138140
),
@@ -141,7 +143,13 @@ impl<S: StyleTrait> Renderer<S> {
141143
}else{
142144
S::fmt(
143145
w,
144-
format_args!("{:->width$} {}","", annotation.label, width = range.len()),
146+
format_args!(
147+
"{} {}",
148+
repeat(horizontal_mark)
149+
.take(range.len())
150+
.collect::<String>(),
151+
annotation.label
152+
),
145153
&styles,
146154
)
147155
}

‎src/renderers/html/mod.rs‎

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::display_list::line::DisplaySourceLine;
88
usecrate::DisplayList;
99
use std::cmp;
1010
use std::io::Write;
11+
use std::iter::repeat;
1112

1213
pubstructRenderer{}
1314

@@ -25,12 +26,33 @@ fn digits(n: usize) -> usize {
2526
sum
2627
}
2728

29+
enumMarkKind{
30+
Vertical,
31+
Horizontal,
32+
DownRight,
33+
UpRight,
34+
UpLeft,
35+
}
36+
37+
implMarkKind{
38+
pubfnget(t:MarkKind) ->char{
39+
match t{
40+
MarkKind::Vertical =>'│',
41+
MarkKind::Horizontal =>'─',
42+
MarkKind::DownRight =>'┌',
43+
MarkKind::UpRight =>'└',
44+
MarkKind::UpLeft =>'┘',
45+
}
46+
}
47+
}
48+
2849
implRenderer{
2950
pubfnnew() ->Self{
3051
Renderer{}
3152
}
3253

3354
pubfnfmt(&self,w:&mutimplWrite,dl:&DisplayList) -> std::io::Result<()>{
55+
self.fmt_header(w)?;
3456
let lineno_max = dl.body.iter().rev().find_map(|line|{
3557
ifletDisplayLine::Source{
3658
lineno:Some(lineno),
@@ -49,6 +71,7 @@ impl Renderer {
4971
for linein&dl.body{
5072
self.fmt_line(w, line, lineno_max, inline_marks_width)?;
5173
}
74+
self.fmt_footer(w)?;
5275
Ok(())
5376
}
5477

@@ -66,7 +89,7 @@ impl Renderer {
6689
inline_marks,
6790
line,
6891
} =>{
69-
let vertical_mark ='|';
92+
let vertical_mark =MarkKind::get(MarkKind::Vertical);
7093
ifletSome(lineno) = lineno{
7194
write!(
7295
w,
@@ -90,9 +113,9 @@ impl Renderer {
90113
"",
91114
width = inline_marks_width - inline_marks.len()
92115
)?;
93-
//for mark in inline_marks {
94-
//self.fmt_display_mark(w, mark)?;
95-
//}
116+
for markin inline_marks{
117+
self.fmt_display_mark(w, mark)?;
118+
}
96119
self.fmt_source_line(w, line)?;
97120
writeln!(w)
98121
}
@@ -106,31 +129,33 @@ impl Renderer {
106129
line:&DisplaySourceLine,
107130
) -> std::io::Result<()>{
108131
match line{
109-
DisplaySourceLine::Content{ text} =>write!(w," {}", text),
132+
DisplaySourceLine::Content{ text} =>{
133+
write!(w,r#" <span class="source">{}</span>"#, text)
134+
}
110135
DisplaySourceLine::Annotation{ annotation, range} =>{
111-
//let(_, style) = self.get_annotation_type_style(&annotation.annotation_type);
112-
//let styles = [StyleType::Emphasis, style];
113-
//letindent =if range.start == 0 { 0 } else { range.start + 1 };
114-
//write!(w, "{:>width$}", "", width = indent)?;
115-
//if range.start == 0 {
116-
//let horizontal_mark = MarkKind::get(MarkKind::Horizontal);
117-
//S::fmt(
118-
//w,
119-
//format_args!(
120-
//"{}{} {}",
121-
//repeat(horizontal_mark).take(5).collect::<String>(),
122-
//MarkKind::get(MarkKind::UpLeft),
123-
//annotation.label,
124-
//),
125-
//&styles,
126-
//)
127-
//} else {
128-
//S::fmt(
129-
//w,
130-
//format_args!("{:->width$} {}", "", annotation.label, width = range.len()),
131-
//&styles,
132-
//)
133-
//}
136+
letindent =if range.start ==0{0}else{ range.start +1};
137+
write!(w,"{:>width$}","", width = indent)?;
138+
lethorizontal_mark =MarkKind::get(MarkKind::Horizontal);
139+
if range.start ==0{
140+
write!(
141+
w,
142+
"{}{} {}",
143+
repeat(horizontal_mark)
144+
.take(range.len())
145+
.collect::<String>(),
146+
MarkKind::get(MarkKind::UpLeft),
147+
annotation.label,
148+
)?;
149+
}else{
150+
write!(
151+
w,
152+
"{} {}",
153+
repeat(horizontal_mark)
154+
.take(range.len())
155+
.collect::<String>(),
156+
annotation.label
157+
)?;
158+
}
134159
Ok(())
135160
}
136161
DisplaySourceLine::Empty =>Ok(()),
@@ -194,14 +219,26 @@ impl Renderer {
194219
w:&mutimpl std::io::Write,
195220
display_mark:&DisplayMark,
196221
) -> std::io::Result<()>{
197-
//let ch = match display_mark.mark_type {
198-
//DisplayMarkType::AnnotationStart => MarkKind::get(MarkKind::DownRight),
199-
//DisplayMarkType::AnnotationEnd => MarkKind::get(MarkKind::UpRight),
200-
//DisplayMarkType::AnnotationThrough => MarkKind::get(MarkKind::Vertical),
201-
//};
202-
//S::fmt(w,ch, &[StyleType::Emphasis, style])
222+
let ch =match display_mark.mark_type{
223+
DisplayMarkType::AnnotationStart =>MarkKind::get(MarkKind::DownRight),
224+
DisplayMarkType::AnnotationEnd =>MarkKind::get(MarkKind::UpRight),
225+
DisplayMarkType::AnnotationThrough =>MarkKind::get(MarkKind::Vertical),
226+
};
227+
write!(w,"{}", ch)?;
203228
Ok(())
204229
}
230+
231+
fnfmt_header(&self,w:&mutimpl std::io::Write) -> std::io::Result<()>{
232+
writeln!(w,"<html><head><style>")?;
233+
writeln!(w,r#".lineno {{ color: red; }}"#)?;
234+
writeln!(w,r#".line {{ color: blue; }}"#)?;
235+
writeln!(w,r#".source {{ color: gray; }}"#)?;
236+
write!(w,"</style></head><body><pre>")
237+
}
238+
239+
fnfmt_footer(&self,w:&mutimpl std::io::Write) -> std::io::Result<()>{
240+
write!(w,"</pre></body></html>")
241+
}
205242
}
206243

207244
implRendererTraitforRenderer{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp