obsidian-text-format icon indicating copy to clipboard operation
obsidian-text-format copied to clipboard

[FR] custom replacement to modify selectedText

Open Benature opened this issue 1 year ago • 2 comments

The js code can be written in a textarea, the content will be eval() in the plugin.

Benature avatar Jan 23 '24 18:01 Benature

As "Use of eval is strongly discouraged", this plugin will only support custom replacement. For now, only replace one pattern for each command, i.e., text.replace(search, replace).

If the user wants to replace multi-patterns in one command, the user can modify data.json directly (setting about it is not supported yet). If you think the setting is needed, comment on this issue to let me know. :)

Example

data.json:

  "customReplaceList": [
    {
      "name": "test",
      "data": [
        {
          "search": "\\n",
          "replace": "\\n\\n"
        },
        {
          "search": "manually add second search",
          "replace": "manually add second replace"
        },
      ]
    }
  ],

The configuration works like

text.replace(/\n/g, "\n\n")
    .replace("manually add second search", "manually add second replace");

Benature avatar Mar 07 '24 12:03 Benature

As "Use of eval is strongly discouraged", this plugin will only support custom replacement.

Related work

  • Dataview disable rollup checking in rollup.config.js
  • Templater user window.eval() and it will not raise warning/error like eval().

Custom replacement should add a subpart, advanced custom replacement, for custom js

Benature avatar Mar 30 '24 02:03 Benature