-
-
Notifications
You must be signed in to change notification settings - Fork 170
feat: support markdown user scripts #1066
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
base: master
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds Markdown-backed user script support: QuickAdd can execute JavaScript embedded in a single fenced Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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 renamingjavascriptFilestoscriptFiles.The property name
javascriptFilesis slightly inconsistent with the broader terminology shift to "script files" now that.mdfiles are also supported. This is a minor naming nitpick and can be deferred.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
docs/docs/Choices/MacroChoice.mddocs/docs/UserScripts.mdsrc/constants.tssrc/gui/MacroGUIs/CommandSequenceEditor.tssrc/gui/MacroGUIs/ConditionalCommandSettingsModal.tssrc/gui/MacroGUIs/noScriptsFoundNotice.tssrc/utilityObsidian.test.tssrc/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.tssrc/gui/MacroGUIs/ConditionalCommandSettingsModal.tssrc/utilityObsidian.test.tssrc/utilityObsidian.tssrc/gui/MacroGUIs/noScriptsFoundNotice.tssrc/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.tssrc/gui/MacroGUIs/ConditionalCommandSettingsModal.tssrc/utilityObsidian.test.tssrc/utilityObsidian.tssrc/gui/MacroGUIs/noScriptsFoundNotice.tssrc/gui/MacroGUIs/CommandSequenceEditor.ts
**/*.{ts,tsx,svelte}
📄 CodeRabbit inference engine (AGENTS.md)
Use PascalCase for classes and Svelte components.
Files:
src/constants.tssrc/gui/MacroGUIs/ConditionalCommandSettingsModal.tssrc/utilityObsidian.test.tssrc/utilityObsidian.tssrc/gui/MacroGUIs/noScriptsFoundNotice.tssrc/gui/MacroGUIs/CommandSequenceEditor.ts
src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Route logging through the
loggerutilities for consistent output.
Files:
src/constants.tssrc/gui/MacroGUIs/ConditionalCommandSettingsModal.tssrc/utilityObsidian.test.tssrc/utilityObsidian.tssrc/gui/MacroGUIs/noScriptsFoundNotice.tssrc/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.tssrc/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
.jsand.mdextensions 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
.jsand.mdextensions.src/gui/MacroGUIs/ConditionalCommandSettingsModal.ts (1)
14-14: LGTM!The import and filter logic correctly use the new
USER_SCRIPT_FILE_EXTENSION_REGEXto support both.jsand.mdfiles.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
extractSingleJavascriptCodeBlockfunction correctly parses markdown to find exactly onejs/javascriptfenced code block:
- Properly handles variable-length fence markers (3+ backticks)
- Case-insensitive language tag matching
- Returns
nullfor unclosed fences, multiple JS blocks, or no JS blocks- Clean line-by-line parsing approach
972-987: LGTM!The
getUserScriptintegration correctly:
- Detects
.mdfiles 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::exportNamesyntax.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_REGEXto include both.jsand.mdfiles 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:
- Exact path match
- Match by file name (with extension)
- Match by basename (without extension)
This allows flexibility in how users reference scripts while correctly resolving to the file path.
520-540: LGTM!The
showScriptPickercorrectly displays full paths for disambiguation (helpful when multiple scripts share the same name) and finds the selected file by path.
Summary
Testing
Issue