aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/markdown.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-18 11:37:45 +0000
committerAleksey Kladov <[email protected]>2020-02-18 11:37:45 +0000
commit865759925be6b72f7ef39124ed0e4c86c0412a69 (patch)
tree0fc36373073a66c2bbd6c7cfae6cb734527d847f /crates/ra_lsp_server/src/markdown.rs
parentc855e36696afa54260773a6bc8a358df67d60dea (diff)
Rename folder
Diffstat (limited to 'crates/ra_lsp_server/src/markdown.rs')
-rw-r--r--crates/ra_lsp_server/src/markdown.rs75
1 files changed, 0 insertions, 75 deletions
diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/ra_lsp_server/src/markdown.rs
deleted file mode 100644
index 76bef45cc..000000000
--- a/crates/ra_lsp_server/src/markdown.rs
+++ /dev/null
@@ -1,75 +0,0 @@
1//! Transforms markdown
2
3pub(crate) fn format_docs(src: &str) -> String {
4 let mut processed_lines = Vec::new();
5 let mut in_code_block = false;
6 for line in src.lines() {
7 if in_code_block && code_line_ignored_by_rustdoc(line) {
8 continue;
9 }
10
11 if line.starts_with("```") {
12 in_code_block ^= true
13 }
14
15 let line = if in_code_block && line.starts_with("```") && !line.contains("rust") {
16 "```rust"
17 } else {
18 line
19 };
20
21 processed_lines.push(line);
22 }
23 processed_lines.join("\n")
24}
25
26fn code_line_ignored_by_rustdoc(line: &str) -> bool {
27 let trimmed = line.trim();
28 trimmed == "#" || trimmed.starts_with("# ") || trimmed.starts_with("#\t")
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[test]
36 fn test_format_docs_adds_rust() {
37 let comment = "```\nfn some_rust() {}\n```";
38 assert_eq!(format_docs(comment), "```rust\nfn some_rust() {}\n```");
39 }
40
41 #[test]
42 fn test_format_docs_skips_comments_in_rust_block() {
43 let comment =
44 "```rust\n # skip1\n# skip2\n#stay1\nstay2\n#\n #\n # \n #\tskip3\n\t#\t\n```";
45 assert_eq!(format_docs(comment), "```rust\n#stay1\nstay2\n```");
46 }
47
48 #[test]
49 fn test_format_docs_keeps_comments_outside_of_rust_block() {
50 let comment = " # stay1\n# stay2\n#stay3\nstay4\n#\n #\n # \n #\tstay5\n\t#\t";
51 assert_eq!(format_docs(comment), comment);
52 }
53
54 #[test]
55 fn test_format_docs_preserves_newlines() {
56 let comment = "this\nis\nultiline";
57 assert_eq!(format_docs(comment), comment);
58 }
59
60 #[test]
61 fn test_code_blocks_in_comments_marked_as_rust() {
62 let comment = r#"```rust
63fn main(){}
64```
65Some comment.
66```
67let a = 1;
68```"#;
69
70 assert_eq!(
71 format_docs(comment),
72 "```rust\nfn main(){}\n```\nSome comment.\n```rust\nlet a = 1;\n```"
73 );
74 }
75}