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

Broken diagrams (due to broken HTML) #16

Closed
FuadEfendi opened this issue Nov 23, 2024 · 4 comments
Closed

Broken diagrams (due to broken HTML) #16

FuadEfendi opened this issue Nov 23, 2024 · 4 comments

Comments

@FuadEfendi
Copy link

Hi @razonyang,

Please see this discussion: https://discourse.gohugo.io/t/problem-with-two-mermaid-diagrams/52506/10

We need something like this:

<pre class="mermaid">
  {{- .Inner | htmlEscape | safeHTML }}
</pre>
{{ .Page.Store.Set "hasMermaid" true }}

Otherwise diagrams like this one will be broken:

classDiagram
    AbstractFactory <|.. ConcreteFactory1
    AbstractFactory <|.. ConcreteFactory2

    AbstractProductA <|-- ProductA1
    AbstractProductA <|-- ProductA2
    AbstractProductB <|-- ProductB1
    AbstractProductB <|-- ProductB2

    Client --> AbstractFactory
    Client --> AbstractProductA
    Client --> AbstractProductB

    class AbstractFactory {
        +CreateProductA() : AbstractProductA
        +CreateProductB() : AbstractProductB
    }

    class ConcreteFactory1 {
        +CreateProductA() : ProductA1
        +CreateProductB() : ProductB1
    }

    class ConcreteFactory2 {
        +CreateProductA() : ProductA2
        +CreateProductB() : ProductB2
    }

    class AbstractProductA {
        <<interface>>
    }

    class AbstractProductB {
        <<interface>>
    }

    class ProductA1
    class ProductA2
    class ProductB1
    class ProductB2
Loading
@FuadEfendi
Copy link
Author

wrong issue; sorry.

@razonyang
Copy link
Member

{{- .Inner | htmlEscape | safeHTML }}

According to my local testing, the diagram above displayed correctly and the diagram text was escaped by default.

With this, it seems that the input was escaped twice unnecessarily, not sure if there is an unexpected case.

image

As to the flowchart example on forum, you just need to quote the node's text by double quotes ".

Btw, the flowchart example can not be parsed by the official live editor without quoting the node texts.

@FuadEfendi
Copy link
Author

Thanks for checking,

Yes, official live editor will fail too, however: it doesn't fail if I use A[hello #40;world#41;] - as you can see, I don't use double-quotes, and it won't fail. So, there is bug somewhere... double-quotes are just workaround.

@FuadEfendi
Copy link
Author

I have many other use cases when it fails with () or {}, I don't remember all; using numerical code substitution always works but finally I feel tired ;)
I hope they will improve this, mermaid-js/mermaid#6075 (comment)
I was worried that GitHub shows the diagram correctly, but Hugo has issues. fortunately, this is not true; your module works correctly, and I don't see any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants