(40, 91),
)
}
let ranges = highlight(db, file_id, None);
let text = parse.tree().syntax().to_string();
let mut prev_pos = TextSize::from(0);
let mut buf = String::new();
buf.push_str(&STYLE);
buf.push_str("");
// TODO: unusize
for range in &ranges {
if range.range.start() > prev_pos {
let curr = &text[usize::from(prev_pos)..usize::from(range.range.start())];
let text = html_escape(curr);
buf.push_str(&text);
}
let curr = &text[usize::from(range.range.start())..usize::from(range.range.end())];
let class = range.highlight.to_string().replace('.', " ");
let color = match (rainbow, range.binding_hash) {
(true, Some(hash)) => {
format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash))
}
_ => "".into(),
};
buf.push_str(&format!("{}", class, color, html_escape(curr)));
prev_pos = range.range.end();
}
// Add the remaining (non-highlighted) text
let curr = &text[usize::from(prev_pos)..];
let text = html_escape(curr);
buf.push_str(&text);
buf.push_str("
");
buf
}
//FIXME: like, real html escaping
fn html_escape(text: &str) -> String {
text.replace("<", "<").replace(">", ">")
}
const STYLE: &str = "
";