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: handle empty newlines before diagrams in md #455

Conversation

aloisklink
Copy link
Member

📑 Summary

Handles empty newlines before and after diagrams in Markdown.

For example, the following Markdown:

My text.

```mermaid
  my diagram
```

Should get converted to:

My text.

![diagram](./my-diagram)

However, currently, the empty newline is removed.
We can fix this by making sure that our Regex ignores newlines outside of the Mermaid diagram code.

Fixes: 9d7b4b2 (where bug was introduced)
Fixes: #413

📏 Design Decisions

Instead of using \s to find all whitespace, I'm instead using [^\S\n] to find anything that is not a non-whitespace character nor \n (basically any \s that is not \n).

In the future, it might be worth instead using https://github.com/remarkjs/remark to handle Markdown parsing, since there are probably a bunch of edge-cases that we can't handle using simplistic regex.

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added unit/e2e tests (if appropriate)
  • 🔖 targeted master branch

Handles empty newlines before and after diagrams in Markdown.

For example, the following Markdown:

````markdown
My text.

```mermaid
  my diagram
```
````

Should get converted to:

```markdown
My text.

![diagram](./my-diagram)
```

However, currently, the empty newline is removed.
We can fix this by making sure that our Regex ignores newlines outside
of the Mermaid diagram code.

Fixes: 9d7b4b2
Fixes: mermaid-js#413
@github-actions github-actions bot added the fix label Dec 24, 2022
@MindaugasLaganeckas MindaugasLaganeckas merged commit a0888a4 into mermaid-js:master Jan 2, 2023
@aloisklink aloisklink deleted the fix/413-handle-leading-newlines-in-markdown branch January 2, 2023 19:31
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.

mmdc removing leading and trailing newlines of mermaid code blocks
2 participants