aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-18 10:57:43 +0100
committerGitHub <[email protected]>2021-04-18 10:57:43 +0100
commite8e145f13c7e018a52213ba24b7a5a33bff8438a (patch)
tree642d7bfc88cd66ae2f983843449bf3135933574a /crates/ide
parent2ace128dd4c9c2e5d59d21402da53654acb0c7e4 (diff)
parent6c287e150433e848c97b89c7211a3464a5675634 (diff)
Merge #8561
8561: Accept `E<error_number>` notation in doctests r=Veykril a=ChayimFriedman2 ```` ```compile_fail,E0000 ``` ```` The code was stolen from rustdoc at https://github.com/rust-lang/rust/blob/392ba2ba1a7d6c542d2459fb8133bebf62a4a423/src/librustdoc/html/markdown.rs#L866-L867 Co-authored-by: Chayim Refael Friedman <[email protected]>
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/syntax_highlighting/inject.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs
index 04fafd244..855c7fba8 100644
--- a/crates/ide/src/syntax_highlighting/inject.rs
+++ b/crates/ide/src/syntax_highlighting/inject.rs
@@ -90,6 +90,13 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
90 "edition2021", 90 "edition2021",
91]; 91];
92 92
93fn is_rustdoc_fence_token(token: &str) -> bool {
94 if RUSTDOC_FENCE_TOKENS.contains(&token) {
95 return true;
96 }
97 token.starts_with('E') && token.len() == 5 && token[1..].parse::<u32>().is_ok()
98}
99
93/// Injection of syntax highlighting of doctests. 100/// Injection of syntax highlighting of doctests.
94pub(super) fn doc_comment( 101pub(super) fn doc_comment(
95 hl: &mut Highlights, 102 hl: &mut Highlights,
@@ -174,8 +181,7 @@ pub(super) fn doc_comment(
174 is_codeblock = !is_codeblock; 181 is_codeblock = !is_codeblock;
175 // Check whether code is rust by inspecting fence guards 182 // Check whether code is rust by inspecting fence guards
176 let guards = &line[idx + RUSTDOC_FENCE.len()..]; 183 let guards = &line[idx + RUSTDOC_FENCE.len()..];
177 let is_rust = 184 let is_rust = guards.split(',').all(|sub| is_rustdoc_fence_token(sub.trim()));
178 guards.split(',').all(|sub| RUSTDOC_FENCE_TOKENS.contains(&sub.trim()));
179 is_doctest = is_codeblock && is_rust; 185 is_doctest = is_codeblock && is_rust;
180 continue; 186 continue;
181 } 187 }