Skip to content

Conversation

@chhoumann
Copy link
Owner

@chhoumann chhoumann commented Dec 26, 2025

Summary

  • support user scripts stored in markdown notes with a single js/javascript fence
  • extend user script pickers to include .md and improve messaging
  • document markdown-backed scripts and add extractor tests

Testing

  • not run

Issue

@vercel
Copy link

vercel bot commented Dec 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
quickadd Ready Ready Preview Dec 26, 2025 11:00am

@coderabbitai
Copy link

coderabbitai bot commented Dec 26, 2025

📝 Walkthrough

Walkthrough

Adds Markdown-backed user script support: QuickAdd can execute JavaScript embedded in a single fenced js/javascript code block inside .md notes. Documentation, UI labels, file filtering, script-loading, and tests were updated to recognize and extract code from .md files in addition to .js files.

Changes

Cohort / File(s) Summary
Documentation
docs/docs/Choices/MacroChoice.md, docs/docs/UserScripts.md
Documented Markdown-backed scripts (.md) requiring exactly one fenced js/javascript block; added examples, placement guidance, and usage syntax (e.g., script.md::exportName).
Constants
src/constants.ts
Added exported USER_SCRIPT_FILE_EXTENSION_REGEX (`/.(js
GUI Components
src/gui/MacroGUIs/CommandSequenceEditor.ts, src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts, src/gui/MacroGUIs/noScriptsFoundNotice.ts
Switched filtering to USER_SCRIPT_FILE_EXTENSION_REGEX; renamed/internal state to script-oriented names; changed suggesters/placeholders/empty states to reference "script files" and include .md; adjusted suggestion logic to use file name/path and improved path-matching behavior.
Core Utility Logic
src/utilityObsidian.ts
Added `extractSingleJavascriptCodeBlock(markdown: string): { code: string }
Tests
src/utilityObsidian.test.ts
Added tests for extractSingleJavascriptCodeBlock() covering single JS block, ignoring non-JS fences, multiple JS blocks, and no JS blocks; exported helper via __test.
Misc / UX
various
Updated user-facing messages and placeholders to reflect support for both .js and .md script sources.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GUI as CommandSequenceEditor
    participant Vault as Vault/File Loader
    participant Extractor as extractSingleJavascriptCodeBlock
    participant Runtime as Script Evaluator

    User->>GUI: Choose or pick a script file
    GUI->>Vault: Load file by path
    Vault-->>GUI: Return file content + extension
    alt file is .js
        GUI->>Runtime: Execute raw file content
        Runtime-->>GUI: Return result
    else file is .md
        GUI->>Extractor: Request single JS code block extraction
        Extractor-->>GUI: Extracted code or null
        alt extracted code present
            GUI->>Runtime: Execute extracted code
            Runtime-->>GUI: Return result
        else extraction failed
            GUI-->>User: Warn / abort script load
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit found a markdown door,
Where JavaScript hides in one fenced core,
From .js or .md the code we pluck,
One block, one hop — and scripts run quick as luck! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'feat: support markdown user scripts' directly and clearly summarizes the main change: adding support for user scripts in Markdown files alongside the existing .js file support.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 1065

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts (1)

46-46: Consider renaming javascriptFiles to scriptFiles.

The property name javascriptFiles is slightly inconsistent with the broader terminology shift to "script files" now that .md files are also supported. This is a minor naming nitpick and can be deferred.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1e2a9f and a3214a6.

📒 Files selected for processing (8)
  • docs/docs/Choices/MacroChoice.md
  • docs/docs/UserScripts.md
  • src/constants.ts
  • src/gui/MacroGUIs/CommandSequenceEditor.ts
  • src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts
  • src/gui/MacroGUIs/noScriptsFoundNotice.ts
  • src/utilityObsidian.test.ts
  • src/utilityObsidian.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx,mts,mjs,js,json}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,mts,mjs,js,json}: Use tab indentation with width 2 in TypeScript and configuration files (enforced by Biome).
Follow an 80-character line guide (enforced by Biome).

Files:

  • src/constants.ts
  • src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts
  • src/utilityObsidian.test.ts
  • src/utilityObsidian.ts
  • src/gui/MacroGUIs/noScriptsFoundNotice.ts
  • src/gui/MacroGUIs/CommandSequenceEditor.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use camelCase for variables and functions in TypeScript.
Prefer type-only imports in TypeScript.

Files:

  • src/constants.ts
  • src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts
  • src/utilityObsidian.test.ts
  • src/utilityObsidian.ts
  • src/gui/MacroGUIs/noScriptsFoundNotice.ts
  • src/gui/MacroGUIs/CommandSequenceEditor.ts
**/*.{ts,tsx,svelte}

📄 CodeRabbit inference engine (AGENTS.md)

Use PascalCase for classes and Svelte components.

Files:

  • src/constants.ts
  • src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts
  • src/utilityObsidian.test.ts
  • src/utilityObsidian.ts
  • src/gui/MacroGUIs/noScriptsFoundNotice.ts
  • src/gui/MacroGUIs/CommandSequenceEditor.ts
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Route logging through the logger utilities for consistent output.

Files:

  • src/constants.ts
  • src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts
  • src/utilityObsidian.test.ts
  • src/utilityObsidian.ts
  • src/gui/MacroGUIs/noScriptsFoundNotice.ts
  • src/gui/MacroGUIs/CommandSequenceEditor.ts
🧠 Learnings (4)
📚 Learning: 2025-12-21T07:54:34.875Z
Learnt from: CR
Repo: chhoumann/quickadd PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-21T07:54:34.875Z
Learning: Applies to **/*.{ts,tsx,mts,mjs,js,json} : Use tab indentation with width 2 in TypeScript and configuration files (enforced by Biome).

Applied to files:

  • src/constants.ts
📚 Learning: 2025-12-21T07:54:34.875Z
Learnt from: CR
Repo: chhoumann/quickadd PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-21T07:54:34.875Z
Learning: Applies to src/{engine,services,utils}/**/*.{ts,tsx} : Structure production code so Obsidian dependencies are injected behind interfaces to enable unit testing without loading real Obsidian modules.

Applied to files:

  • src/utilityObsidian.test.ts
  • src/utilityObsidian.ts
📚 Learning: 2025-12-21T07:54:34.875Z
Learnt from: CR
Repo: chhoumann/quickadd PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-21T07:54:34.875Z
Learning: Applies to tests/**/*.{ts,tsx} : Unit tests should target pure logic and swap in adapters or use `tests/obsidian-stub.ts` for Obsidian dependencies.

Applied to files:

  • src/utilityObsidian.test.ts
📚 Learning: 2025-12-21T07:54:34.875Z
Learnt from: CR
Repo: chhoumann/quickadd PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-21T07:54:34.875Z
Learning: Applies to tests/**/*.{test,spec}.{ts,tsx} : Use Testing Library helpers for Svelte components.

Applied to files:

  • src/utilityObsidian.test.ts
🧬 Code graph analysis (4)
src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts (1)
src/constants.ts (1)
  • USER_SCRIPT_FILE_EXTENSION_REGEX (96-96)
src/utilityObsidian.test.ts (1)
src/utilityObsidian.ts (1)
  • __test (1114-1118)
src/gui/MacroGUIs/noScriptsFoundNotice.ts (1)
tests/obsidian-stub.ts (1)
  • Notice (453-473)
src/gui/MacroGUIs/CommandSequenceEditor.ts (3)
src/constants.ts (1)
  • USER_SCRIPT_FILE_EXTENSION_REGEX (96-96)
src/types/macros/UserScript.ts (1)
  • UserScript (5-16)
src/gui/InputSuggester/inputSuggester.ts (1)
  • InputSuggester (22-195)
🪛 LanguageTool
docs/docs/UserScripts.md

[style] ~41-~41: Consider a more expressive alternative.
Context: ...cripts stored inside markdown notes. To do this, the note must contain **exactly o...

(DO_ACHIEVE)

🪛 markdownlint-cli2 (0.18.1)
docs/docs/Choices/MacroChoice.md

157-157: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (11)
src/constants.ts (1)

96-96: LGTM!

The new regex correctly matches both .js and .md extensions case-insensitively for user script file filtering.

src/gui/MacroGUIs/noScriptsFoundNotice.ts (1)

1-39: LGTM!

The UI text updates correctly reflect the expanded script file support, with clear guidance mentioning both .js and .md extensions.

src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts (1)

14-14: LGTM!

The import and filter logic correctly use the new USER_SCRIPT_FILE_EXTENSION_REGEX to support both .js and .md files.

Also applies to: 78-82

src/utilityObsidian.test.ts (1)

79-134: LGTM!

The test suite provides good coverage of the core scenarios: single JS block extraction, ignoring non-JS fences, rejecting multiple JS blocks, and handling notes without JS blocks.

docs/docs/UserScripts.md (1)

39-57: LGTM!

The new documentation section clearly explains markdown-backed scripts with a practical example. The nested fenced code block is properly escaped using 4 backticks.

src/utilityObsidian.ts (2)

901-954: LGTM!

The extractSingleJavascriptCodeBlock function correctly parses markdown to find exactly one js/javascript fenced code block:

  • Properly handles variable-length fence markers (3+ backticks)
  • Case-insensitive language tag matching
  • Returns null for unclosed fences, multiple JS blocks, or no JS blocks
  • Clean line-by-line parsing approach

972-987: LGTM!

The getUserScript integration correctly:

  • Detects .md files by extension
  • Extracts the single JS code block
  • Logs a helpful warning when extraction fails
  • Uses the extracted code for evaluation instead of raw markdown content
docs/docs/Choices/MacroChoice.md (1)

150-159: LGTM!

The new markdown-backed scripts section clearly documents the feature, including how to reference exported members using the script.md::exportName syntax.

Note: The static analysis hint about missing language specification on line 157 can be safely ignored—the code block intentionally shows a format pattern rather than executable code.

src/gui/MacroGUIs/CommandSequenceEditor.ts (3)

19-19: LGTM!

The import and filter correctly use USER_SCRIPT_FILE_EXTENSION_REGEX to include both .js and .md files in the script file list.

Also applies to: 114-118


334-378: LGTM!

The enhanced lookup logic provides a good user experience with three fallback strategies:

  1. Exact path match
  2. Match by file name (with extension)
  3. Match by basename (without extension)

This allows flexibility in how users reference scripts while correctly resolving to the file path.


520-540: LGTM!

The showScriptPicker correctly displays full paths for disambiguation (helpful when multiple scripts share the same name) and finds the selected file by path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Allow User Script to be in Note code block

2 participants