]> git.lizzy.rs Git - rust.git/commitdiff
Fix: correct markdown link form.
authorDezhi Wu <wu543065657@163.com>
Fri, 29 Oct 2021 10:25:32 +0000 (18:25 +0800)
committerDezhi Wu <wu543065657@163.com>
Fri, 29 Oct 2021 10:25:32 +0000 (18:25 +0800)
crates/rust-analyzer/src/config.rs
editors/code/package.json

index 32e4e8ebeeb6af58172f8331d83761d0a7510f8d..81f4ccd365c3aca1288d0b942aa247f1813367ef 100644 (file)
@@ -1290,6 +1290,8 @@ fn generate_package_json_config() {
         schema.push_str(",\n");
 
         // Transform the asciidoc form link to markdown style.
+        //
+        // https://link[text] => [text](https://link)
         let url_matches = schema.match_indices("https://");
         let mut url_offsets = url_matches.map(|(idx, _)| idx).collect::<Vec<usize>>();
         url_offsets.reverse();
@@ -1298,8 +1300,14 @@ fn generate_package_json_config() {
             // matching on whitespace to ignore normal links
             if let Some(link_end) = link.find(|c| c == ' ' || c == '[') {
                 if link.chars().nth(link_end) == Some('[') {
-                    schema.insert(idx, '(');
-                    schema.insert(idx + link_end + 1, ')');
+                    if let Some(link_text_end) = link.find(']') {
+                        let link_text = link[link_end..(link_text_end + 1)].to_string();
+
+                        schema.replace_range((idx + link_end)..(idx + link_text_end + 1), "");
+                        schema.insert(idx, '(');
+                        schema.insert(idx + link_end + 1, ')');
+                        schema.insert_str(idx, &link_text);
+                    }
                 }
             }
         }
index fffaf6c9b8617a691199009a599a25a9d69aef39..336081e88c5eb2a9882f04fc455b43cf944232e0 100644 (file)
                     ]
                 },
                 "rust-analyzer.assist.importGroup": {
-                    "markdownDescription": "Group inserted imports by the (https://rust-analyzer.github.io/manual.html#auto-import)[following order]. Groups are separated by newlines.",
+                    "markdownDescription": "Group inserted imports by the [following order](https://rust-analyzer.github.io/manual.html#auto-import). Groups are separated by newlines.",
                     "default": true,
                     "type": "boolean"
                 },