openKB icon indicating copy to clipboard operation
openKB copied to clipboard

Mermaid diagrams won't show up

Open vjsrinath opened this issue 7 years ago • 3 comments

Any mermaid diagram is not shown. The problem is caused by how sanitizeHtml module is used.

 var cleanHTML = sanitizeHtml(fixed_html, {
            allowedTags: [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol',
                'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'code', 'hr', 'br', 'div',
                'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'img' 
            ]
        });

The fixed_html is cleaned before rendered on to page which loses all the html attributes.

For example if I have the following mermaid markdown,

<div class="mermaid" mardown="1">
graph LR;
    A[Square Rect] -- Link text --> B((Circle));
    A --> C(Round Rect);
    B --> D{Rhombus};
    C --> D;	
</div>

The cleanHTML will not have "mermaid" class in the div causing the mermaid documents failing to render.

<div>
graph LR;
    A[Square Rect] -- Link text --> B((Circle));
    A --> C(Round Rect);
    B --> D{Rhombus};
    C --> D;	
</div>

The possible fix is [**Updated]

        var cleanHTML = sanitizeHtml(fixed_html, {
            allowedTags: [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol',
                'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'code', 'hr', 'br', 'div',
                'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'img' 
            ],
            allowedAttributes: Object.assign({},sanitizeHtml.defaults.allowedAttributes, {
                '*': ['class']
            })
        });

@mrvautin I have raised a pull request fixing the issue. #194

vjsrinath avatar Jul 26 '17 08:07 vjsrinath

@vjsrinath I have tried this but it stops images from displaying in articles

spatialsteve avatar Jul 27 '17 00:07 spatialsteve

Hi @spatialsteve, I have fixed image loading issues and also mermaid diagrams now properly show up even in previews. #194

vjsrinath avatar Jul 29 '17 21:07 vjsrinath

I think 42fbeeb40cc891977b0f6a3bd52925567a28cde2 solves this as well.

savikko avatar Jul 31 '17 12:07 savikko