Feel-ix-343/markdown-oxide

Include Extension on link insertion

RyanGreenup opened this issue · 3 comments

Is it possible to include the extension for a completed markdown link? I appreciate the link is not needed for VS-Code and Obsidian, however it is required by wikijs, marktext and I suspect other tools 1

I apologize if I have missed this in the documentation, but I couldn't find a corresponding entry in the config.

I'll give an example to be clear.

When I complete a link by typing:

[](

And then hitting on a match, e.g.:

[](elisp

It completes as:

[Elisp Programming](elisp)

This link does not work in wikijs. I need to manually add .md:

[Elisp Programming](elisp.md)

If there is not already an option to have this, I think it would be a desirable feature.

Additionally, I'm happy to compile from source. Would you be to tell me which part of link_completer.rs I would need to look at?

Footnotes

  1. I haven't tested these, but maybe: zettlr, mdbook, mkdocs, vnote, forgejo

I was able to include the extension by modifying that file. If I have time, I'll create a config entry and make a PR if that's alright with you?

diff
diff --git a/src/completion/link_completer.rs b/src/completion/link_completer.rs
index a8dac3a..5f86e49 100644
--- a/src/completion/link_completer.rs
+++ b/src/completion/link_completer.rs
@@ -154,8 +154,8 @@ impl<'a> LinkCompleter<'a> for MarkdownLinkCompleter<'a> {
     /// Will add <$1> to the refname if it contains spaces
     fn completion_text_edit(&self, display: Option<&str>, refname: &str) -> CompletionTextEdit {
         let link_ref_text = match refname.contains(' ') {
-            true => format!("<{}>", refname),
-            false => refname.to_owned(),
+            true => format!("<{}.md>", refname),
+            false => format!("{}.md", refname),
         };
 
         CompletionTextEdit::Edit(TextEdit {
@@ -359,7 +359,7 @@ impl<'a> LinkCompleter<'a> for WikiLinkCompleter<'a> {
                 },
             },
             new_text: format!(
-                "{}{}]]${{2:}}",
+                "{}.md{}]]${{2:}}",
                 refname,
                 display
                     .map(|display| format!("|{}", display))

Ooh perfect! Thank you so much

Ooh perfect! Thank you so much

Just put up a PR in pull/114 let me know what you think.