Skip to content

Compile Step: Remove checkboxes #277

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

Open
pdworkman opened this issue Nov 8, 2024 · 1 comment
Open

Compile Step: Remove checkboxes #277

pdworkman opened this issue Nov 8, 2024 · 1 comment
Labels
compile Pertaining to the Compile feature. enhancement New feature or request

Comments

@pdworkman
Copy link

What should this step do?
I'd like a step that removes all checkbox paragraphs/tasks, checked or unchecked

Should this step affect scenes, manuscripts, or join the two?
scenes/manuscripts

@pdworkman pdworkman added compile Pertaining to the Compile feature. enhancement New feature or request labels Nov 8, 2024
@pdworkman
Copy link
Author

Here is a script to remove all tasks

module.exports = {
  description: {
    name: "Remove Markdown Tasks",
    description: "Removes Markdown task list items and one blank line after each.",
    availableKinds: ["Scene"],
    options: [],
  },

  compile(input, context) {
    return input.map(scene => {
      const lines = scene.contents.split("\n");
      const resultLines = [];

      for (let i = 0; i < lines.length; i++) {
        const line = lines[i];

        // Check for a Markdown task item
        if (/^\s*[-*]\s+\[[ xX]\]/.test(line)) {
          // Skip this task line
          // Also check if the next line exists and is blank — skip that too
          const nextLine = lines[i + 1];
          if (nextLine !== undefined && /^\s*$/.test(nextLine)) {
            i++; // skip the blank line too
          }
          continue;
        }

        resultLines.push(line);
      }
      return {
        ...scene,
        contents: resultLines.join("\n"),
      };
    });
  },
};

To add this custom step to your vault:

  1. create a /steps folder inside your vault.
  2. copy the above text into a text file and save it as remove-tasks.js
  3. go into the settings for the longform plugin and select /steps as the location for User script step folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compile Pertaining to the Compile feature. enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant