Quoting all lines in web capture selection

Is there any way to iterate over all the lines in selection/selection_markdown in a Mustache web capture template?

I have the obvious use case of wanting to do exactly what the default template is set up to do – formatting captured text as a Markdown quote – but actually handling line breaks in the selection by prefixing every line with > .

That would not be possible. Mustache isn’t a programming tool, so it can’t do things like split values. You would have to post-process with an action.

The type of solution I was imagining was actually that there be an alternate property available to Mustache which was a list of lines, rather than a single string, that could be iterated over in this way.

So something like selection_lines and selection_markdown_lines would be lists of strings, not individual strings, so the Mustache template could work per-line.

Post-processing with an action doesn’t fit well into a workflow for quick capture while browsing the web, since it is much more heavy-weight and requires switching apps and taking many more manual steps. The above suggestion seems like the most straightforward solution and likely something people might generally want – it fits very naturally with the spirit of your default web capture template, after all, which arguably misbehaves for multi-line selections.

However, a heavier-weight but more general alternative might include the ability to set an action to run automatically at capture time and could do this sort of reformatting, or run any other arbitrary logic.

There are several other ways to approach it. You could have your capture template simply markup your incoming content for processing and tag it as needing processing – then have a bulk processing action that did a sweep of any unprocessed capture drafts, removing that tag after it updated the formatting. That would also give you additional flexibility to do any additional logic you might come up with later (generate an AI summary, etc.)

I’ll put it on the list to consider adding the availability of pre-split lines for the mustache templates. Seems like something that would not be too hard to add.

1 Like

Added this is Beta Build 44.5 (495) if you want to try it out you can join the beta group, or just wait for the next update to ship.

1 Like

Thanks! This seems to work wonderfully so far:

{{#selection}}{{#selection_markdown_lines}}>{{.}}
{{/selection_markdown_lines}}
Source: {{/selection}}[{{title}}]({{url}})

This quotes every line, and puts the source at the end, or if there is no selection it avoids any wasted whitespace or the Source: prefix.

3 Likes