Wikilinking having issues with space in filenames

Viewed 21

Sometimes when using the wikilink "a b" it will be rendered as [a b](./a b.md) or [[ab]].

When I change the wikilink to "ab" the rendering is correct as ab (linking to the document ab.md).

Both files ("a b.md" and "ab.md") are in the same directory as the "linking" markdown file.

This behavior is happening not always but most of the time.

Changing the settings - convert [[wiki links]] and resetting does not solve the problem.


I am testing Marked 3 on Seqoia 15.7.3 on M1 Pro.

3 Answers

When both files exist in the directory, Marked won't know which you mean. It tries to normalize the file name based on what actually exists in the directory, but it's going to stop scanning when it finds what seems like the intended file name. The solution would be to either change the filename with spaces to something like a-b.md, or use the extension in the wiki link like [[a b.md]] to avoid ambiguity.

In wikis it's very rare that you would have both a b.md and ab.md, so this is kind of an edge case.

I am having the same issue.

Here is the MD file:

# Crows

---

Linked notes: [[Index]], [[Rook vs Carrion Crow ID]], [[Raven and Buzzard nesting]], [[Crows ID]]

Tags: #crow

---

- [[Carrion Crow]]
- [[Chough]]
- [[Hooded Crow]]
- [[Jackdaw]]
- [[Jay]]
- [[Magpie]]
- [[Raven]]
- [[Rook]]


For now:

- [[Cuckoo]]

All file names are unique. It is not inserting '%20' into the file names with a space when creating hyperlink (it fails to convert it). Only works for names without space.

I would expect something like:

<a href="./Carrion%20Crow.md">Carrion Crow</a></li>

It creates this:

<h1 id="crows">Crows</h1>

<hr />

<p>Linked notes: <a href="./Index.md">Index</a>, [Rook vs Carrion Crow ID](./Rook vs Carrion Crow ID.md), [Raven and Buzzard nesting](./Raven and Buzzard nesting.md), [Crows ID](./Crows ID.md)</p>

<p>Tags: #crow</p>

<hr />

<ul>
<li>[Carrion Crow](./Carrion Crow.md)</li>
<li><a href="./Chough.md">Chough</a></li>
<li>[Hooded Crow](./Hooded Crow.md)</li>
<li><a href="./Jackdaw.md">Jackdaw</a></li>
<li><a href="./Jay.md">Jay</a></li>
<li><a href="./Magpie.md">Magpie</a></li>
<li><a href="./Raven.md">Raven</a></li>
<li><a href="./Rook.md">Rook</a></li>
</ul>

<p>For now:</p>

<ul>
<li><a href="./Cuckoo.md">Cuckoo</a></li>
</ul>

Let me know if you need any more info. Thanks


FYI Wiki links worked in Marked 2 if you added the following ruby preprocessor (with code placed in a somename.rb file). I can't get it to work as a preprocessor using 'run command' in the custom processor rules screen.

#!/usr/bin/ruby
require 'uri'

def class_exists?(class_name)
  klass = Module.const_get(class_name)
  return klass.is_a?(Class)
rescue NameError
  return false
end

if class_exists? 'Encoding'
  Encoding.default_external = Encoding::UTF_8 if Encoding.respond_to?('default_external')
  Encoding.default_internal = Encoding::UTF_8 if Encoding.respond_to?('default_internal')
end

begin
  input = STDIN.read.force_encoding('utf-8')
rescue
  input = STDIN.read
end

input.gsub!(/\[\[(.*?)\]\]/) do |m|
  match = Regexp.last_match
  "[#{match[1]}](#{URI.escape(match[1])}.md)"
end

print input

Hi Brett thanks for coming back to me. But I still have trouble understanding what is going on.

I created a new file named "something completly different.md" wikilinked it and it gets rendered as [something completly different](./something completly different.md) when I remove the spaces it works as expected.

There is no filename closely related to this in the same directory.

I also have the feeling that some background indexing is going on which does not always catch up with the real names in the folder. This only a feeling which I can't nail down. Sometimes clicking on a wikilink gets an error message which disappears when I check again sometime later. Refreshing doesn't solve the issue.