longform icon indicating copy to clipboard operation
longform copied to clipboard

Compile step request: search and replace

Open pdworkman opened this issue 3 years ago • 2 comments
trafficstars

Search for a string and replace it with something else.

It would be nice to be able to add this step multiple times with different search and replace schemes.

pdworkman avatar Feb 02 '22 17:02 pdworkman

that should already be doable with the current featureset. Compile Step simply replaces every instance of "a" with "💥". (If you know regex, you can also use .replace instead of .replaceAll.)

But a more accessible workflow that offers search/replace for non-coders might make a lot of sense, too.

module.exports = {
  description: {
    name: "Sample Script",
    description: "Replaces every 'a' with an explosion emoji.",
    availableKinds: ["Manuscript", "Scene"],
    options: []
  },

  compile (input, context) {
    input.contents = input.contents.replaceAll ("a", "💥");

    return input;
  }

};

chrisgrieser avatar Feb 02 '22 17:02 chrisgrieser

I like the idea of formalizing this as a built-in step but leaving more complex versions to user steps. Good suggestion.

kevboh avatar Feb 11 '22 15:02 kevboh