From 190d516a1a7ca5c177fcc4716351507461dbec7c Mon Sep 17 00:00:00 2001 From: Kevin Barrett Date: Fri, 4 Jul 2025 13:40:05 -0400 Subject: [PATCH] add remove checkboxes compile step --- .rules | 13 +++++ src/compile/steps/index.ts | 2 + src/compile/steps/remove-tasks.ts | 56 +++++++++++++++++++ .../.obsidian/core-plugins.json | 4 +- .../projects 2.0/A Novel/fourth.md | 5 +- .../projects 2.0/A Novel/manuscript.md | 2 +- 6 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 .rules create mode 100644 src/compile/steps/remove-tasks.ts diff --git a/.rules b/.rules new file mode 100644 index 0000000..e4b5d47 --- /dev/null +++ b/.rules @@ -0,0 +1,13 @@ +# LLM Rules + +This file provides general guidance for LLMs working in this codebase. + +## Overview + +This codebase is for Longform, an Obsidian plugin that assists in novel-writing. It enables users to order notes as _scenes_, to nest/indent those scenes, and to _compile_ those scenes into a single manuscript file. + +## Adding/Editing Compile Steps + +Compile steps make up workflows that turn scenes into manuscripts. They're defined in the `src/compile/steps` folder and exported in `src/compile/steps/index.ts`. Any steps in the `BUILTIN_STEPS` constant are available to users, in addition to their own custom scripts. + +Built-in compile steps like the ones you can add or edit call `makeBuiltinStep` with an object that describes the step, including a `compile` function. diff --git a/src/compile/steps/index.ts b/src/compile/steps/index.ts index f716c78..6a66c02 100644 --- a/src/compile/steps/index.ts +++ b/src/compile/steps/index.ts @@ -3,6 +3,7 @@ import { PrependTitleStep } from "./prepend-title"; import { RemoveCommentsStep } from "./remove-comments"; import { RemoveLinksStep } from "./remove-links"; import { RemoveStrikethroughsStep } from "./remove-strikethroughs"; +import { RemoveTasksStep } from "./remove-tasks"; import { StripFrontmatterStep } from "./strip-frontmatter"; import { WriteToNoteStep } from "./write-to-note"; import { AddFrontmatterStep } from "./add-frontmatter"; @@ -14,6 +15,7 @@ export const BUILTIN_STEPS = [ RemoveCommentsStep, RemoveLinksStep, RemoveStrikethroughsStep, + RemoveTasksStep, StripFrontmatterStep, WriteToNoteStep, ]; diff --git a/src/compile/steps/remove-tasks.ts b/src/compile/steps/remove-tasks.ts new file mode 100644 index 0000000..2a0c8bf --- /dev/null +++ b/src/compile/steps/remove-tasks.ts @@ -0,0 +1,56 @@ +import type { + CompileContext, + CompileInput, + CompileManuscriptInput, + CompileSceneInput, +} from ".."; +import { CompileStepKind, makeBuiltinStep } from "./abstract-compile-step"; + +export const RemoveTasksStep = makeBuiltinStep({ + id: "remove-tasks", + description: { + name: "Remove Checkboxes", + description: "Removes Markdown checkboxes and task list items.", + availableKinds: [CompileStepKind.Scene, CompileStepKind.Manuscript], + options: [], + }, + compile(input: CompileInput, context: CompileContext): CompileInput { + const removeTasksFromContent = (contents: string): string => { + const lines = 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 resultLines.join("\n"); + }; + + if (context.kind === CompileStepKind.Scene) { + return (input as CompileSceneInput[]).map((sceneInput) => { + const contents = removeTasksFromContent(sceneInput.contents); + return { + ...sceneInput, + contents, + }; + }); + } else { + return { + ...(input as CompileManuscriptInput), + contents: removeTasksFromContent((input as any).contents), + }; + } + }, +}); diff --git a/test-longform-vault/.obsidian/core-plugins.json b/test-longform-vault/.obsidian/core-plugins.json index ba5d617..4088959 100644 --- a/test-longform-vault/.obsidian/core-plugins.json +++ b/test-longform-vault/.obsidian/core-plugins.json @@ -28,5 +28,7 @@ "canvas": true, "bookmarks": true, "properties": true, - "webviewer": false + "webviewer": false, + "footnotes": false, + "bases": true } \ No newline at end of file diff --git a/test-longform-vault/projects 2.0/A Novel/fourth.md b/test-longform-vault/projects 2.0/A Novel/fourth.md index c0ce658..1cf4639 100644 --- a/test-longform-vault/projects 2.0/A Novel/fourth.md +++ b/test-longform-vault/projects 2.0/A Novel/fourth.md @@ -1 +1,4 @@ -hello! asdsadsad \ No newline at end of file +hello! asdsadsad + +- [ ] this is a task +- [x] this one is checked off \ No newline at end of file diff --git a/test-longform-vault/projects 2.0/A Novel/manuscript.md b/test-longform-vault/projects 2.0/A Novel/manuscript.md index 206dacc..191e189 100644 --- a/test-longform-vault/projects 2.0/A Novel/manuscript.md +++ b/test-longform-vault/projects 2.0/A Novel/manuscript.md @@ -8,4 +8,4 @@ a a a a a a a a aa a a a a a a a aa a a a a a a a aa a a a a a a a aa a a a a a # fourth -hello! asdsadsad \ No newline at end of file +hello! asdsadsad