Skip to content

feat: allow unlabeled SmartBlock buttons#135

Merged
mdroidian merged 5 commits intomainfrom
codex/add-option-to-exclude-label-in-smartblocks
Aug 11, 2025
Merged

feat: allow unlabeled SmartBlock buttons#135
mdroidian merged 5 commits intomainfrom
codex/add-option-to-exclude-label-in-smartblocks

Conversation

@mdroidian
Copy link
Copy Markdown
Collaborator

@mdroidian mdroidian commented Aug 11, 2025

Testing

  • npm test

https://chatgpt.com/codex/tasks/task_e_689787e1076083269001fdc1aec90bf9

Summary by CodeRabbit

  • New Features

    • Support SmartBlock buttons with no caption using {{:SmartBlock:workflow name}}.
  • Documentation

    • Updated guidance and example to show the no-caption button syntax.
  • Refactor

    • Improved SmartBlock button parsing and trigger registration for more reliable, flexible behavior.
  • Tests

    • Added comprehensive parsing tests covering various SmartBlock button scenarios.
  • Chores

    • Added source map entry to ignore list.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 11, 2025

Walkthrough

Add a new exported parser parseSmartBlockButton, replace ad‑hoc regex parsing in SmartBlock button registration/click handling to use the parser, add tests for parsing, update docs with a no‑caption button example, and add extension.js.map to .gitignore. No breaking API removals.

Changes

Cohort / File(s) Summary
Documentation: No-caption syntax
docs/060-alternative-methods.md
Replace captioned SmartBlock button example with guidance and example for a no-caption variant ({{:SmartBlock:workflow name}}).
Core: Button parsing & registration
src/index.ts
Replace inline/regex parsing with parseSmartBlockButton; use parsed fields (workflowName, variables, buttonContent) in trigger registration and click handler; remove legacy ButtonContent injection at that layer; relax observer gating and widen hideIcon param type.
Utility: New parser (exported)
src/utils/parseSmartBlockButton.ts
Add parseSmartBlockButton(label: string, text: string) (named & default export). Returns `{ index, full, buttonContent, buttonText, workflowName, variables }
Tests: Parser coverage
tests/buttonParsing.test.ts
Add tests for parsing scenarios: no-label buttons, variable parsing, workflows with spaces, sibling directive, and specific workflow extraction.
Repo config
.gitignore
Add extension.js.map to ignore list.

Sequence Diagram(s)

sequenceDiagram
  participant DOM as DOM/Button
  participant Observer as Button Observer
  participant Parser as parseSmartBlockButton
  participant Core as SmartBlock Core
  participant Workflows as Workflow Registry

  Observer->>DOM: observe element
  Observer->>Parser: parseSmartBlockButton(label, text)
  Parser-->>Observer: {index, full, buttonContent, buttonText, workflowName, variables}
  Observer->>DOM: mark element & attach click handler

  DOM->>Observer: Click
  Observer->>Workflows: resolve workflowName -> srcUid
  alt Workflow found
    Observer->>Core: run workflow with variables/buttonContent
    Core-->>DOM: apply results (keep/clear/sibling/target/order)
  else Workflow missing
    Observer-->>DOM: insert descriptive missing-workflow block
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Possibly related PRs

Poem

I clicked a button, small and neat,
The parser hopped to sort each sheet.
No regex tangles, commas escaped,
Workflows found and vars reshaped.
A rabbit nods — tests passing, sweet. 🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 817f029 and 48aef58.

📒 Files selected for processing (1)
  • src/index.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/index.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-option-to-exclude-label-in-smartblocks

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@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: 2

🧹 Nitpick comments (1)
src/utils/parseSmartBlockButton.ts (1)

40-40: Consider removing redundant ButtonContent injection.

Since buttonContent is already returned as a separate field in the result object, injecting it into the variables object creates redundancy. Based on the AI summary, the consuming code in src/index.ts now uses the parsed structure directly.

Consider removing this line if the consuming code doesn't require ButtonContent in the variables:

- variables["ButtonContent"] = buttonContent;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4c62f7 and c4a95a1.

📒 Files selected for processing (4)
  • docs/060-alternative-methods.md (1 hunks)
  • src/index.ts (3 hunks)
  • src/utils/parseSmartBlockButton.ts (1 hunks)
  • tests/buttonParsing.test.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/buttonParsing.test.ts (1)
src/utils/parseSmartBlockButton.ts (1)
  • parseSmartBlockButton (1-49)
src/index.ts (1)
src/utils/parseSmartBlockButton.ts (1)
  • parseSmartBlockButton (1-49)
🪛 ast-grep (0.38.6)
src/utils/parseSmartBlockButton.ts

[warning] 15-17: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(
{{(${trimmedLabel.replace(/\\+/g, "\\+")}):(?:42)?SmartBlock:(.*?)}}
)
Note: [CWE-1333] Inefficient Regular Expression Complexity [REFERENCES]
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
- https://cwe.mitre.org/data/definitions/1333.html

(regexp-from-variable)

🔇 Additional comments (6)
docs/060-alternative-methods.md (1)

40-41: LGTM! Clear documentation of the new unlabeled button feature.

The documentation clearly explains how to create buttons without captions by omitting the first parameter. The example is helpful and the placement within the existing section flows well.

src/utils/parseSmartBlockButton.ts (1)

30-39: LGTM! Robust argument parsing with proper comma escaping.

The argument parsing logic correctly handles commas inside [[...]] and <%...%> tokens by temporarily escaping them. This prevents incorrect splitting on commas that are part of values rather than delimiters.

src/index.ts (3)

49-49: LGTM! Clean import of the new parser utility.

The import statement properly brings in the new parseSmartBlockButton function to replace the previous regex-based parsing approach.


549-552: LGTM! Clean integration of the new parser.

The refactoring from regex-based parsing to the dedicated parser is well-implemented. Using textContent.trim() as the label parameter properly handles both labeled and unlabeled buttons.


753-753: Relaxed registration logic is safe

The new !b.hasAttribute("data-roamjs-smartblock-button") check simply prevents duplicate processing—all actual trigger registration still happens inside registerElAsSmartBlockTrigger, which calls parseSmartBlockButton and only attaches listeners when the button’s label and block text match a SmartBlock pattern. Non-SmartBlock BP3 buttons are still ignored.

No further changes needed.

tests/buttonParsing.test.ts (1)

1-68: LGTM! Comprehensive test coverage for the new parser.

The test suite thoroughly covers the key scenarios for SmartBlock button parsing:

  • Unlabeled buttons (the new feature)
  • Variable parsing with complex values
  • Workflow names containing spaces
  • Sibling directives
  • Special cases like today's entry

All tests properly verify the parser's output structure including index, full, buttonContent, workflowName, and variables fields.

mdroidian and others added 4 commits August 10, 2025 23:53
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Simplified margin assignment for icons based on text content presence.
- Consolidated margin styles into single lines for better readability.
@mdroidian mdroidian merged commit 6af57a2 into main Aug 11, 2025
2 of 3 checks passed
@mdroidian mdroidian deleted the codex/add-option-to-exclude-label-in-smartblocks branch August 11, 2025 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant