diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-09 13:09:15 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-09 13:09:15 +0000 |
commit | 939ca83b34f9a5648d196f85e5cc7d844ba22604 (patch) | |
tree | a007952a8870e4d8c0b5fa1e0e0a088b399a8c8d /crates/ide/src/syntax_highlighting/html.rs | |
parent | 625ec9e1ae69168f194cbc5bf20846870f03e149 (diff) | |
parent | 4a8d2c098d88da6f36f3cf95f424b471987c5daa (diff) |
Merge #7216
7216: Highlighting improvements r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide/src/syntax_highlighting/html.rs')
-rw-r--r-- | crates/ide/src/syntax_highlighting/html.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 44f611b25..0ee7bc96e 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs | |||
@@ -20,26 +20,26 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo | |||
20 | ) | 20 | ) |
21 | } | 21 | } |
22 | 22 | ||
23 | let ranges = highlight(db, file_id, None, false); | 23 | let hl_ranges = highlight(db, file_id, None, false); |
24 | let text = parse.tree().syntax().to_string(); | 24 | let text = parse.tree().syntax().to_string(); |
25 | let mut buf = String::new(); | 25 | let mut buf = String::new(); |
26 | buf.push_str(&STYLE); | 26 | buf.push_str(&STYLE); |
27 | buf.push_str("<pre><code>"); | 27 | buf.push_str("<pre><code>"); |
28 | for range in &ranges { | 28 | for r in &hl_ranges { |
29 | let curr = &text[range.range]; | 29 | let chunk = html_escape(&text[r.range]); |
30 | if range.highlight.is_empty() { | 30 | if r.highlight.is_empty() { |
31 | format_to!(buf, "{}", html_escape(curr)); | 31 | format_to!(buf, "{}", chunk); |
32 | continue; | 32 | continue; |
33 | } | 33 | } |
34 | 34 | ||
35 | let class = range.highlight.to_string().replace('.', " "); | 35 | let class = r.highlight.to_string().replace('.', " "); |
36 | let color = match (rainbow, range.binding_hash) { | 36 | let color = match (rainbow, r.binding_hash) { |
37 | (true, Some(hash)) => { | 37 | (true, Some(hash)) => { |
38 | format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash)) | 38 | format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash)) |
39 | } | 39 | } |
40 | _ => "".into(), | 40 | _ => "".into(), |
41 | }; | 41 | }; |
42 | format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, html_escape(curr)); | 42 | format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, chunk); |
43 | } | 43 | } |
44 | buf.push_str("</code></pre>"); | 44 | buf.push_str("</code></pre>"); |
45 | buf | 45 | buf |