Extra spaces with templater

What I’m trying to do

Hi, I’m trying to create a simple template that takes the current selection and subscript it. The script works but it adds a lot of useless white lines. In this state is really annoying to use. I included a video of the problem.
Templater problem

Things I have tried

<sub><%_ tp.file.selection() _%></sub>

I hope that you can help me out. Thank you.

You are quicker to report this issue on Templaters repo on Github than to ask for a provisory solution here.

Anyway, you could use Linter, this plugin strips notes of useless characters, and is very convenient to use , thanks to keyboard shortcuts

1 Like

Thank you for your help!
I will try to do as you said.

Are you sure that you didn’t have any lines after your line of code in the template and that there is no empty line after it? When I had this problem, it was due to that.
For exemple:

<sub><%_ tp.file.selection() _%></sub>

instead of :

<sub><%_ tp.file.selection() _%></sub>
1 Like

Sorry, I was hasty.

If Templater doesn’t work, consider using a QuickAdd macro with the following user script:

module.exports = ({ app }) => {
    const editor = app.workspace.activeEditor.editor;
    editor.replaceSelection('<sub>' + editor.getSelection() + '</sub>');

Screen Recording 2023-09-27 at 1.49.25

You can set your custom hotkey as well.

1 Like

I was not able to reproduce the spacing issue using a template containing simply this :

<sub><% tp.file.selection() %></sub>
1 Like

Thanks a lot guys! The solution with QuickAdd was also really good and it would have worked perfectly for me. Next time I will double-check before creating a post.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.