Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] custom replacement to modify selectedText #77

Open
Benature opened this issue Jan 23, 2024 · 2 comments
Open

[FR] custom replacement to modify selectedText #77

Benature opened this issue Jan 23, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Benature
Copy link
Owner

Benature commented Jan 23, 2024

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

@Benature Benature added the enhancement New feature or request label Jan 23, 2024
@Benature Benature changed the title custom js code to modify selectedText [FR] custom js code to modify selectedText Mar 6, 2024
@Benature
Copy link
Owner Author

Benature commented Mar 7, 2024

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 Benature closed this as completed Mar 7, 2024
@Benature Benature changed the title [FR] custom js code to modify selectedText [FR] custom replacement to modify selectedText Mar 7, 2024
@Benature
Copy link
Owner Author

Benature commented Mar 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

1 participant