Skip to content

Mermaid ELK layouts not activated #11351

Closed

Description

@Feez2403

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Mermaid uses ELK for alternative layouts, but entering the configuration for elk layouts in docusaurus mermaid blocks does not change the layout.

Reproducible demo

No response

Steps to reproduce

  1. Clone the docusaurus repo
  2. Create 2 mermaid diagrams, for example the following ER Diagrams. One has the config block with elk layout.
```mermaid
erDiagram

  COMPANY ||--o{ DEPARTMENT : has
  COMPANY ||--o{ PROJECT : undertakes
  COMPANY ||--o{ LOCATION : operates_in
  COMPANY ||--o{ CLIENT : serves

  DEPARTMENT ||--o{ EMPLOYEE : employs
  DEPARTMENT ||--o{ PROJECT : manages
  DEPARTMENT ||--o{ BUDGET : allocated

  EMPLOYEE }o--o{ PROJECT : works_on
  EMPLOYEE ||--|| ADDRESS : lives_at
  EMPLOYEE }o--o{ SKILL : has
  EMPLOYEE ||--o{ DEPENDENT : supports

  PROJECT ||--o{ CLIENT : for
  PROJECT ||--o{ TASK : contains
```
```mermaid
---
config:
  layout: elk
---
erDiagram
  COMPANY ||--o{ DEPARTMENT : has
  COMPANY ||--o{ PROJECT : undertakes
  COMPANY ||--o{ LOCATION : operates_in
  COMPANY ||--o{ CLIENT : serves

  DEPARTMENT ||--o{ EMPLOYEE : employs
  DEPARTMENT ||--o{ PROJECT : manages
  DEPARTMENT ||--o{ BUDGET : allocated

  EMPLOYEE }o--o{ PROJECT : works_on
  EMPLOYEE ||--|| ADDRESS : lives_at
  EMPLOYEE }o--o{ SKILL : has
  EMPLOYEE ||--o{ DEPENDENT : supports

  PROJECT ||--o{ CLIENT : for
  PROJECT ||--o{ TASK : contains
```
  1. Start the server (yarn install & yarn start)
  2. The diagrams are the same, ELK layout engine is ignored.

Expected behavior

On the official mermaid.live editor, we can see the expected behavior:

  • Without ELK (using the default Dagre layout engine)
Image
  • With ELK layout engine
Image

Actual behavior

On Daucusaurus, the diagrams are the same. ELK layout config is ignored.

Image

There is a package that web pages frameworks (e.g. Docusaurus) using mermaid should use, as stated in the official Mermaid github page.
Docusaurus is actually missing this import. Therefore, Memaid does not take ELK layout config into account.

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on Jul 28, 2025
  2. slorber commented on Jul 28, 2025

    @slorber
    Collaborator
    import mermaid from 'mermaid';
    import elkLayouts from '@mermaid-js/layout-elk';
    
    mermaid.registerLayoutLoaders(elkLayouts);

    We don't have that feature currently, but we could find a way to add a "layout loaders" config option I guess.


    Not even sure, but do we even support config front matter properly?
    https://mermaid.js.org/intro/syntax-reference.html?#frontmatter-for-diagram-code

    I'm not a Mermaid expert so unsure if this is built-in or if Docusaurus should parse that front matter

  3. removed
    status: needs triage
    on Jul 28, 2025
  4. Feez2403 commented on Jul 28, 2025

    @Feez2403
    ContributorAuthor

    I think Fontmatter and Directives (%%{...}%%) should be delegated to mermaid directly.
    Docusaurus already has a default config feature for mermaid, and I would not see the use case of parsing the font matter of a single diagram.

    Importing the missing library, as you mentioned, would do the job.

  5. linked a pull request that will close this issuefeat(mermaid): support elk layout #11357on Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions