Last month I released Conductor, a tool for handling multiple Custom Processors in Marked. It allows you to use natural language conditions to determine which command or script to run, either as preprocessor or processor for Marked. But I found a lot of my scripts were just injecting metadata or performing other simple actions, so I added a new feature to Conductor called Filters. Filters are just shortcuts to avoid having to write simple (often 3 or 4 line) scripts.

Like command: or script: actions, you can now just use filter: filterName(parameters) to do things like setting a Marked Style, injecting or stripping metadata (YAML/MMD aware), or doing search and replaces on the content. These can be run in a sequence: to combine multiple filters.

Available Filters

The available filters are:

  • addMeta(key, value)/setMeta(key, value) – adds or updates a meta key, aware of YAML and MMD
  • stripMeta – strips all metadata (YAML or MMD) from the content
  • stripMeta(key) – removes a specific key (YAML or MMD)
  • setStyle(name) – sets the Marked preview style to a preconfigured Style name
  • replace(search, replace)/replaceAll(search, replace) – performs a search and replace (global with replaceAll).
    • If search is surrounded with forward slashes followed by optional flags (i for case-insensitive, m to make dot match newlines), e.g. /contribut(ing)?/i, it will be interpreted as a regular expression. The replace value can include numeric capture groups, e.g. Follow$2.

Update to the latest version using gem install marked-conductor (may vary depending on how you installed it originally) to get the new features, see the project page for details, and check out my config to see examples.

If there are any simple procedures you’re currently using scripts to handle that aren’t covered by these, please let me know in the comments what filters you’d like to see added!

Also, easier testing

There’s now a file in the repo called test.sh that makes it way easier to test configurations from the command line. Just run test.sh FILENAME to process a file as if it were being opened in Marked. You can use -o err to output only the STDERR response, which will show which conditions are being matched, and you can use -p to define the phase as either pre or pro to run as Preprocessor or Processor, respectively.