Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .rules
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions src/compile/steps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -14,6 +15,7 @@ export const BUILTIN_STEPS = [
RemoveCommentsStep,
RemoveLinksStep,
RemoveStrikethroughsStep,
RemoveTasksStep,
StripFrontmatterStep,
WriteToNoteStep,
];
56 changes: 56 additions & 0 deletions src/compile/steps/remove-tasks.ts
Original file line number Diff line number Diff line change
@@ -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),
};
}
},
});
4 changes: 3 additions & 1 deletion test-longform-vault/.obsidian/core-plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
"canvas": true,
"bookmarks": true,
"properties": true,
"webviewer": false
"webviewer": false,
"footnotes": false,
"bases": true
}
5 changes: 4 additions & 1 deletion test-longform-vault/projects 2.0/A Novel/fourth.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
hello! asdsadsad
hello! asdsadsad

- [ ] this is a task
- [x] this one is checked off
2 changes: 1 addition & 1 deletion test-longform-vault/projects 2.0/A Novel/manuscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
hello! asdsadsad