Skip to content

Conversation

@ryanwjackson
Copy link

@ryanwjackson ryanwjackson commented Dec 29, 2024

📑 Summary

Add support for markdown-style links on line messages and notes

Resolves #1279

📏 Design Decisions

This currently only affects line messages and notes on sequence diagrams

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@changeset-bot
Copy link

changeset-bot bot commented Dec 29, 2024

🦋 Changeset detected

Latest commit: ba259a0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mermaid Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the Type: Enhancement New feature or request label Dec 29, 2024
@netlify
Copy link

netlify bot commented Dec 29, 2024

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit ba259a0
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/67cf30858cca380007d49451
😎 Deploy Preview https://deploy-preview-6158--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 29, 2024

Open in Stackblitz

npm i https://pkg.pr.new/mermaid-js/mermaid@6158
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/mermaid-zenuml@6158
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/layout-elk@6158
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/parser@6158

commit: ba259a0

@codecov
Copy link

codecov bot commented Dec 29, 2024

Codecov Report

❌ Patch coverage is 5.47945% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 3.88%. Comparing base (df636c6) to head (ba259a0).
⚠️ Report is 1937 commits behind head on develop.

Files with missing lines Patch % Lines
packages/mermaid/src/diagrams/sequence/svgDraw.js 0.00% 63 Missing ⚠️
packages/mermaid/src/diagrams/sequence/styles.js 0.00% 3 Missing ⚠️
packages/mermaid/src/diagrams/common/common.ts 60.00% 2 Missing ⚠️
packages/mermaid/src/utils.ts 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #6158      +/-   ##
==========================================
- Coverage     4.48%   3.88%   -0.60%     
==========================================
  Files          383     399      +16     
  Lines        54038   42121   -11917     
  Branches       596     638      +42     
==========================================
- Hits          2425    1638     -787     
+ Misses       51613   40483   -11130     
Flag Coverage Δ
unit 3.88% <5.47%> (-0.60%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/mermaid/src/utils.ts 18.08% <50.00%> (-23.91%) ⬇️
packages/mermaid/src/diagrams/common/common.ts 33.18% <60.00%> (-19.84%) ⬇️
packages/mermaid/src/diagrams/sequence/styles.js 0.00% <0.00%> (ø)
packages/mermaid/src/diagrams/sequence/svgDraw.js 0.00% <0.00%> (ø)

... and 386 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ryanwjackson ryanwjackson marked this pull request as ready for review December 30, 2024 16:39
@bernhardkaindl
Copy link

Works great in the preview!!!

@ryanwjackson, the link in

"Look at MermaidJS"

appears to be slightly below the "Look at" at the preview link above for me.
Do you know if this is expected or can be fixed?

@ryanwjackson
Copy link
Author

@bernhardkaindl do you have an image of it? I see it as vertically aligned. The underline of the linked text is underneath, but the top and bottom of the text lines up for me. Let me know if I'm missing something.

image

@DanielSmithGK
Copy link

DanielSmithGK commented Feb 25, 2025

Hi @ryanwjackson thanks a bunch for implementing!

I've tested in the preview (thanks @bernhardkaindl for pointing this out). And links on arrow messages are working, the alignment also seems as expected (using latest Edge).

M -->> C: [Test URL](https://www.google.com)

image

The note link also basically works when it's a "simple" URL:

note over M: [Note link](https://mermaid.js.org/intro/syntax-reference.html)

image

However, I've noticed two things:

  1. As soon as I introduce an anchor inside a URL, it reverts from interpreting the URL as a link back to regular text, e.g.
    note over M: [Note link](https://mermaid.js.org/intro/syntax-reference.html#configuration)

    image

  2. When you look at the simple URL case, the displayed text / link title is very short, however, the note box seems as wide as the URL is long and gets wider the more characters are in the URL (this seemingly doesn't happen with arrow messages).
    Example for: note over M: [Note link](https://mermaid.js.org/intro/syntax-reference.html)

    image

    Example for: note over M: [Note link](https://mermaid.js.org/intro/syntax-reference.htmlAAAAAAAAAAAAAAAAAAAAAAA)

    image

    It'd be great if only the necessary displayed text / link title is deciding the note width.

Thanks and regards!
Daniel

EDIT:
The anchor issue with reverting to text is also true for arrow messages, just checked again:
M -->> C: [Test URL](https://mermaid.js.org/intro/syntax-reference.html#configuration)

image

@fornax-a
Copy link

  1. As soon as I introduce an anchor inside a URL, it reverts from interpreting the URL as a link back to regular text, e.g.
    note over M: [Note link](https://mermaid.js.org/intro/syntax-reference.html#configuration)
    image
    ....

EDIT: The anchor issue with reverting to text is also true for arrow messages, just checked again: M -->> C: [Test URL](https://mermaid.js.org/intro/syntax-reference.html#configuration) image

Hi @DanielSmithGK - Encoding the # seems to resolve this problem, though not terribly intuitive for users it might be an acceptable workaround.

M -->> C: [Test URL](https://mermaid.js.org/intro/syntax-reference.html%23configuration)

@argos-ci
Copy link

argos-ci bot commented Mar 10, 2025

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) 👍 Changes approved 1 changed, 1 added Mar 10, 2025, 6:44 PM

@ryanwjackson
Copy link
Author

I made some updates to address those issues. Let me know if that resolves them.

@DanielSmithGK
Copy link

Hi @ryanwjackson thanks for the updates, I've checked the stuff I reported and these look resolved. Thank you!

@ryanwjackson
Copy link
Author

@DanielSmithGK any clue who can review this or how to get it merged?

@awangatsanjel
Copy link

@DanielSmithGK Any progress on this?

@rngcntr
Copy link

rngcntr commented Oct 22, 2025

@ryanwjackson Cool addition! Do you think it's possible to apply the same to the participant names in the diagram? I'd imagine it to be very helpful to be able to link documentation pages for each participant.

@awangatsanjel
Copy link

@rngcntr You can adding link to participant in current version. It is under Actor Menus in the sequence diagram page.

I really don't understand why this feature didn't get into release after it had been done for 10 months. Mermaid diagram is adopted by AI mostly. Its slow progress of evolution makes me disappointed.

@rngcntr
Copy link

rngcntr commented Oct 23, 2025

@awangatsanjel I thought more of a direct link without the need of a drop down, ideally with the capability to reference relative document locations instead of full URLs.
But to be fair, I'm new to this project and I don't know if that's even a feature that is in the scope of mermaid itself or rather implementing parties like GitHub or GitLab.

@awangatsanjel
Copy link

@rngcntr I am with you on the thought of direct link. Mermaid was started as a diagram drawing tool, however it occasionally used markdown as the descripting language. Since AI adopted it markdown because it is pure text can be processed by the LLM, Mermaid became the default diagram language unless you request other specific diagram format. So, Mermaid is turning to a modeling tool. That the way I have used Mermaid for use. GitHub makes it as extension, it is used a lot in the issues and wiki. So it is evolved from offline diagraming tool to online tool. I don't know if the developers had realized this trends. I hope they can move this feature to the production faster.

@DanielSmithGK
Copy link

Hi @sidharthv96,

I've no idea if you could help with this or point us in any direction with this issue here (or maybe tag the correct person, if you know them): The argos check fails for this PR, and it seems like a false-positive. There are no changes noticeable for us, however, the AI thinks there's something off.

Do you perhaps know if this can be approved manually (or skip it) somehow?

Apologies if you're the wrong person, I've just (desperately) checked the last couple repo activities, perhaps you have some insights how we could advance with this.

Thanks and kind regards!
Daniel

Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

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

The code, implementation, and documentation is great for this particular feature. The text below is not a reflection of the work you've done, but rather due to a tricky situation mermaid is in regarding markdown support.

We have an ongoing issue with consistent (and universal) markdown support, mainly around syntax for markdown.

The main issue I see is that we have a proposed syntax for flowcharts, and some diagrams support markdown without that syntax. So it creates confusion.

Currently sequence diagrams do not support markdown strings. So adding just URL support, without the other formatting options, and without the markdown syntax, creates more edge cases while we try to unify markdown syntax across the diagrams.

I will bring this PR for discussion in our next team meeting and give you an update. Thanks for your patience.

Comment on lines +82 to 91
it('should render links', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->John: Look at [MermaidJS](https://mermaid.js.org/)
John->>Alice: Thanks for the link
`
);
});
it('should handle different line breaks', () => {
Copy link
Member

Choose a reason for hiding this comment

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

We need more test cases, with the edge cases that have been discussed in previous comments.

'mermaid': minor
---

feat:Added support for markdown-style links in line messages and notes
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
feat:Added support for markdown-style links in line messages and notes
feat(sequence): Add support for markdown-style links in line messages and notes

@sidharthv96
Copy link
Member

Standardising markdown support was discussed as the exclusive topic in today's weekly call.
We will be fixing and merging #7057 and then continue expanding support to other diagram types. Please hold further work on this PR, as the approach might change on how labels are drawn, and how we support markdown.

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

Labels

Type: Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sequenceDiagram Links

7 participants