Command Button with Title Alias does not work in Table

I ran into the problem that command buttons with alias {[Command|Alias]} do not render correctly inside markdown tables, while it works with page links [[Page|Alias]]


| Works? | Content | Example |
|--------|---------|---------|
| ✅ | Normal Link | [[index]] |
| ✅ | Alias Link | [[index|home]] |
| ✅ | Normal Command | {[System: Reload]}
| ❌ | Alias Command | {[System: Reload|Reload]}

Alias Command outside of table: {[System: Reload|Reload]} ✅

I don’t know if it is an issue with Silverbullet or upstream with codemirror.

Try escaping the pipe in the alias command:

| Content | Example |
|----------|----------|
| Normal Command | {[Help: Version]} |
| Alias Command | {[Help: Version\|Version]} |

Works on my machine™:

2 Likes

Escaping the Pipe is a cool trick, and the button is visible now, thanks!

But it does not end there for me:

  • On clicking the button (mouse on firefox), the button does not react, but the table goes to ‘edit mode’, showing the markdown. This is unrelated to the aliasing, but it would be good to have to buttons receive the click event and prevent the edit view
  • Second click on the button (in markdown) triggers an error:
"Error parsing command link arguments: Command Help: Version\ not found

Looks like the \ is not just escaping the | but is also added to the command name, which is consequently not found anymore. :ninja:

As the works with pagelinks, my assumption is that it has to be a difference somewhere in the guts of markdown parsing. I took a brief look at that area of the code and it is lots of regexp, which is good at parsing, but hard to parse. :thinking:

Update, I just got it to work with a very ugly hack: Just add the backslash to the name of the command as well :cowboy_hat_face: (I want to use this in templates with Command in space-lua to set page attributes):

```template
| Page | Stars |
| ---- | ----- |
{{#each {page where stars>=0}}}
|{{name}}| {{stars}}  {[Page: Set Attribute\|Add Star]({"attribute": "stars","change":1, "page":"{{name}}" })}|
{{/each}}
```


```space-lua
command.define {
  name = "Page: Set Attribute\\",
  run = function(a)
    system.invoke_command("Page: Set Attribute",a)
  end
}
```

Turns into

The Add Star button triggers the command Page: Set Attribute\\ (need to escape \ itself in lua :crazy_face: ), which calls Page: Set Attribute and the :star: is added. :star_struck:

Bonus: Side effect of using a template is that clicking the button does not enter edit mode but triggers it right away!

Messing with the command name like that feels very wrong (and pollutes the command pallete), but it gets the job done for now.

Interesting workaround XD
Didn’t even know, that having buttons/commands in tables was possible, this opens up some cool new possibilities!

The retained backslash does look like a parsing issue, but I’m neither a regex expert nor good with javascript, so I’ll pass the task of improving this to someone else :person_shrugging: