silverbulletmd / silverbullet

The knowledge hacker's notebook
https://silverbullet.md
MIT License
2.14k stars 155 forks source link

Support multiple replacement pairs in replace() function #710

Closed zefhemel closed 5 months ago

zefhemel commented 5 months ago

So that @paletochen doesn't have to nest them 10 levels deep.

zefhemel commented 5 months ago

Implementation of replace is here: https://github.com/silverbulletmd/silverbullet/blob/main/lib/builtin_query_functions.ts#L8

paletochen commented 5 months ago

Are you considering also allowing regex in the second argument of the replacement function?

zefhemel commented 5 months ago

I still don't know what that would do. I don't know of any regex library that supports this. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

paletochen commented 5 months ago

I still don't know what that would do. I don't know of any regex library that supports this. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

The idea would be to have replacements like this below, to avoid the need of making several pair-replacements

Screenshot_20240218-132035.png

replace(readPage(name),/(\w+)(@)/,/\[\[$1\]\]/)
zefhemel commented 5 months ago

You can already do that, just use " quotes instead of / in the second argument. "[[$1]]"

paletochen commented 5 months ago

You can already do that, just use " quotes instead of / in the second argument. "[[$1]]"

Oh, I didn't realize that.

I just tried it and it works, it replaced the name@ correctly with [[name]] values. However, these [[name]] results are not clickable.

Any chance to fix that?

UPDATE: Easy fix, i didn't need to escape the "[" characters