Skip to content
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

Fix exceptions for empty lines #4436

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cypress/integration/rendering/sequencediagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ context('Sequence diagram', () => {
{}
);
});
it('should handle empty lines', () => {
imgSnapshotTest(
`
sequenceDiagram
Alice->>John: Hello John<br/>
John-->>Alice: Great!
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
John-->>Alice: Great!
John-->>Alice: Great<br/><br/>day!

`,
{}
);
});
it('should handle line breaks and wrap annotations', () => {
imgSnapshotTest(
`
Expand Down
3 changes: 3 additions & 0 deletions packages/mermaid/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ export const calculateTextDimensions: (
let cheight = 0;
const dim = { width: 0, height: 0, lineHeight: 0 };
for (const line of lines) {
if (!line) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

Although this fixes the symptom, it doesn't solve the root cause of the issue.
If we add <br/><br/><br/> it should render three empty lines, now, it seems like it won't render anything.

Maybe, if we replace the continue with line = ' ';, it might work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! I end up with zero-width spaces as they don't occupy horizontal space and won't be collapsed inside DOM elements.

const textObj = getTextObj();
textObj.text = line;
const textElem = drawSimpleText(g, textObj)
Expand Down