[v2] Newline support in slashcommand templates?

I have created a slashcommand to insert a fenced block but would like to add a trailing newline after.

Based on the Library/Std slashcommands I have come up with:

```space-lua
slashcommand.define {
  name = "penny-jar",
  exceptContexts = {"FencedCode:space-lua", "LuaDirective"},
  run = function()
    editor.insertAtCursor([==[```#penny-jar
amount: |^|
reason: 
```]==], false, true)
  end
}

But adding a \n after the backticks renders the newline character. I saw in the source that newlines appear to work if part of a string but they don’t appear to within the templating [==[...]==] syntax.

Additionally, I noticed the fenced block breaks if I have the three backticks on a newline so I can’t simply add a newline myself within the template. Is there anything that SB could do to escape these without rendering the backslashes, as it does if I try this myself?

Loving v2 so far though!

Oh wow, you’ve hit a very obscure parsing issue here that I’m not sure how to fix because it’s somewhere burried very deep in CodeMirror. However, there is a bit of a workaround in that the template.new API actually strips 4 spaces when templates are indented, so this works:

```space-lua
slashcommand.define {
  name = "penny-jar",
  exceptContexts = {"FencedCode:space-lua", "LuaDirective"},
  run = function()
    editor.insertAtCursor((template.new[==[
    ```#penny-jar
    amount: |^|
    reason: 
    ```
]==])(), false, true)
  end
}
```

Not particularly proud of this one, but hey :smiley:

1 Like

Amazing, thanks!