Can macros take optional arguments?

I have a macro that takes an argument to build a link:

{{foo 1234}} -> [1234](

I’d like to have an optional second argument that’s part of the link text, but not included in the URL:

{{foo 1234,Cool thing}} -> [1234 Cool thing](

Can I do that with a single macro, or would I need one macro for the plain link, and a second macro for the link with a description?

  • Macro arguments are not currently optional.
  • Using two macros shouldn’t be an issue.
  • But if it is an issue, here is a hack:
    • If you define a macro like this:
      :foo "[$1$2]("
      • i.e. without space between $1 and $2
    • you can use the following for two arguments:
      {{foo 1234 ​,test}}
      • notice the space before the comma
    • and the following for single argument:
      {{foo 1234,}}
      • this uses a zero-width character after the comma, otherwise it won’t work
        • depending on your platform, you may be able to produce it with Alt + 0173

@abackstrom also you can use 🏛 Full House Templates plugin here. It supports optional arguments. See details here.

2024-03-13 10.18.45

- template:: link
	- [`c.args.$1 + when(c.args.$2, ' ${_}')`](``c.args.$1``)