How to edit paragraph using a function?

I need some reformatting shortcut for paragraphs. What is the way to run particular function on particular paragraph and replace it’s content with what the function returned? It should work as new command with keyboard shortcut…

This something SB is still struggling I think. You can look at how the core plugins implement something like the strikethrough command. It’s basically a lot of singular edits to the page.
I think your best bet would go like this: Invoke the command → Generate a markdown tree of the current page → Iterate the tree until you find the node in which the cursor is (There is nodeAtPos for plugs, I don’t know how good that implementation is tho SpaceLua has nodeParentOfType, you would see how well it fits your needs or if you need to modify it) → Make the modifications you need to the node text → Get from and to from the node and run an editor.replaceRange command with your new command.
(You could also modify the tree, render it back and replace the complete page, but I wouldn’t trust myself not f..ing it up or SB not rendering something back correctly + It’s probably better for codemirror, because it’s really well optimized for local edits like this)

Yeah … that’s about as easy as it gets, not great, not terrible

1 Like

Thank you! Your insight into Silberbullet is excellent. Once having it done, I will paste the code here for others to use. What I need is reformatting a paragraph of text with some extra properties than to make it max. 72 chars wide. For example, external links should go on separate line. I will need to support it for list items, quotes and headings too, I guess. That would not be as easy, I think. So it may last some time until I get it done. :slightly_smiling_face:

P.S. I think I will try to make it a slash command (/reformat) in the end.