Skip to content

fix:url truncates in docs#8468

Open
adwait-bruno wants to merge 2 commits into
usebruno:mainfrom
adwait-bruno:fix/docs-url-truncate
Open

fix:url truncates in docs#8468
adwait-bruno wants to merge 2 commits into
usebruno:mainfrom
adwait-bruno:fix/docs-url-truncate

Conversation

@adwait-bruno

@adwait-bruno adwait-bruno commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description

JIRA

Links containing parentheses (e.g. dashboard URLs) were being cut off early by markdown-it's link detection. Reuses the existing paren-balancing fix from the CodeMirror editor (#7406) to resolve this.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.
image

Summary by CodeRabbit

  • New Features
    • Markdown links now handle URLs with balanced parentheses more reliably, improving how some links are rendered and clicked.
  • Bug Fixes
    • Improved Markdown rendering consistency by reusing the same parser setup during display.
    • Fixed link detection so generated links are more accurately extended before being shown.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Markdown rendering now memoizes its MarkdownIt instance, applies a linkify patch that extends URLs with balanced parentheses, and keeps sanitizing rendered HTML. A new utility module implements the match extension behavior, with tests covering both helper functions.

Changes

Markdown rendering and linkify integration

Layer / File(s) Summary
Link extension helpers
packages/bruno-app/src/utils/linkify/index.js
extendMatch mutates link matches to include balanced-parentheses suffixes, and patchLinkifyToExtendUrls wraps md.linkify.matchAtStart and md.linkify.match to apply that extension.
Markdown component wiring
packages/bruno-app/src/components/MarkDown/index.jsx
MarkdownIt is created inside useMemo, configured with allowHtml and collectionPath, passed through the linkify patch, and then rendered and sanitized from the memoized instance.
Linkify utility tests
packages/bruno-app/src/utils/linkify/index.spec.js
Tests cover extendMatch balance handling and patchLinkifyToExtendUrls behavior for both linkify match methods.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MarkDown
  participant MarkdownIt
  participant DOMPurify
  MarkDown->>MarkdownIt: create memoized instance
  MarkDown->>MarkdownIt: render markdown
  MarkdownIt-->>MarkDown: HTML
  MarkDown->>DOMPurify: sanitize HTML
  DOMPurify-->>MarkDown: safe HTML
Loading

Possibly related PRs

  • usebruno/bruno#8335: Also changes packages/bruno-app/src/components/MarkDown/index.jsx and threads allowHtml into the markdown-it configuration.

Suggested reviewers: helloanoop, lohit-bruno, naman-bruno, bijin-bruno

Poem

Markdown hums, links stretch their tails,
Parentheses now stay on the rails.
Memoized pages, tidy and bright,
Rendered, patched, then sanitized right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing truncated URLs in documentation links.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

};

return md;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please move this to utils/url/index.js and write unit test cases for this function

@adwait-bruno adwait-bruno force-pushed the fix/docs-url-truncate branch from f8cc30b to 2483cc0 Compare July 6, 2026 18:17
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jul 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/bruno-app/src/components/MarkDown/index.jsx (1)

11-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting MarkdownIt setup into a custom hook.

Instance creation (config, plugin use, and linkify patching) is business/setup logic inlined in the component body. Moving it into a small custom hook (e.g. useMarkdownIt(allowHtml, collectionPath)) keeps the component focused on rendering/event wiring.

♻️ Suggested extraction
-  const md = useMemo(() => {
-    const instance = new MarkdownIt({
-      html: allowHtml,
-      breaks: true,
-      linkify: true,
-      replaceLink: (link) => link.replace(/^\./, collectionPath)
-    }).use(MarkdownItReplaceLink);
-
-    return patchLinkifyToExtendUrls(instance);
-  }, [allowHtml, collectionPath]);
+  const md = useMarkdownIt(allowHtml, collectionPath);
// utils/markdown/useMarkdownIt.js
export function useMarkdownIt(allowHtml, collectionPath) {
  return useMemo(() => {
    const instance = new MarkdownIt({
      html: allowHtml,
      breaks: true,
      linkify: true,
      replaceLink: (link) => link.replace(/^\./, collectionPath)
    }).use(MarkdownItReplaceLink);

    return patchLinkifyToExtendUrls(instance);
  }, [allowHtml, collectionPath]);
}

As per coding guidelines, "MUST: Prefer custom hooks for business logic, data fetching, and side-effects in React."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/components/MarkDown/index.jsx` around lines 11 - 20,
Extract the MarkdownIt initialization from the MarkDown component into a custom
hook such as useMarkdownIt, keeping the component focused on rendering. Move the
existing useMemo logic, including MarkdownIt config, MarkdownItReplaceLink
usage, and patchLinkifyToExtendUrls, into that hook. Preserve the allowHtml and
collectionPath inputs as hook parameters and return the memoized instance for
the component to consume.

Source: Coding guidelines

packages/bruno-app/src/utils/linkify/index.spec.js (1)

53-115: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Good wrapper-level tests — consider adding one real-integration test.

The patchLinkifyToExtendUrls tests mock md.linkify entirely, which correctly isolates the wrapper logic but never exercises the real linkify-it API shape it's wrapping. Since this PR's goal is fixing truncation during actual md.render() calls, one test using a real new MarkdownIt({ linkify: true }) instance (patched, then rendered against a URL with unbalanced parens) would guard against API drift in linkify-it.

As per coding guidelines, "Prioritise high-value tests over maximum coverage. Focus on testing behaviour that is critical, complex, or likely to break."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/utils/linkify/index.spec.js` around lines 53 - 115,
The current tests for patchLinkifyToExtendUrls only mock md.linkify, so they
don’t validate behavior against the real markdown-it/linkify-it integration used
by md.render(). Add one higher-value integration test in
patchLinkifyToExtendUrls that uses a real MarkdownIt instance with linkify
enabled, applies the patch, renders text containing a URL with unbalanced
parentheses, and asserts the rendered link is extended correctly. Keep the
existing wrapper-level tests, but use the real markdown-it API shape in the new
test to protect against linkify-it drift.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/bruno-app/src/components/MarkDown/index.jsx`:
- Around line 11-20: Extract the MarkdownIt initialization from the MarkDown
component into a custom hook such as useMarkdownIt, keeping the component
focused on rendering. Move the existing useMemo logic, including MarkdownIt
config, MarkdownItReplaceLink usage, and patchLinkifyToExtendUrls, into that
hook. Preserve the allowHtml and collectionPath inputs as hook parameters and
return the memoized instance for the component to consume.

In `@packages/bruno-app/src/utils/linkify/index.spec.js`:
- Around line 53-115: The current tests for patchLinkifyToExtendUrls only mock
md.linkify, so they don’t validate behavior against the real
markdown-it/linkify-it integration used by md.render(). Add one higher-value
integration test in patchLinkifyToExtendUrls that uses a real MarkdownIt
instance with linkify enabled, applies the patch, renders text containing a URL
with unbalanced parentheses, and asserts the rendered link is extended
correctly. Keep the existing wrapper-level tests, but use the real markdown-it
API shape in the new test to protect against linkify-it drift.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6763e90a-316c-41c1-94eb-7753ed51b9da

📥 Commits

Reviewing files that changed from the base of the PR and between f8cc30b and 2483cc0.

📒 Files selected for processing (3)
  • packages/bruno-app/src/components/MarkDown/index.jsx
  • packages/bruno-app/src/utils/linkify/index.js
  • packages/bruno-app/src/utils/linkify/index.spec.js

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.

2 participants