Skip to content

Commit

Permalink
Fix mermaid related bugs
Browse files Browse the repository at this point in the history
1. Apparently, mermaid 9.1.7 no longer sets a `height` attribute on the
   SVG it produces. Workaround by extracting height from `viewBox`
   instead.
2. Filter out unresolvable Monaco errors from error display.

Fixes: go-gitea#21427
Ref: microsoft/monaco-editor#2962
  • Loading branch information
silverwind committed Oct 12, 2022
1 parent ac3a61e commit 68b06ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions web_src/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ import {joinPaths} from './utils.js';
// This file must be imported before any lazy-loading is being attempted.
__webpack_public_path__ = joinPaths(window?.config?.assetUrlPrefix ?? '/', '/');

const ignoreErrors = [
/vs\.editor\.nullLanguage/, // https://github.com/microsoft/monaco-editor/issues/2962
];

export function showGlobalErrorMessage(msg) {
const pageContent = document.querySelector('.page-content');
if (!pageContent) return;

for (const re of ignoreErrors) {
if (re.test(msg)) return;
}

const el = document.createElement('div');
el.innerHTML = `<div class="ui container negative message center aligned js-global-error" style="white-space: pre-line;"></div>`;
el.childNodes[0].textContent = msg;
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/markup/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function renderMermaid() {
// can't use bindFunctions here because we can't cross the iframe boundary. This
// means js-based interactions won't work but they aren't intended to work either
mermaid.mermaidAPI.render('mermaid', source, (svgStr) => {
const heightStr = (svgStr.match(/height="(.+?)"/) || [])[1];
const heightStr = (svgStr.match(/viewBox="(.+?)"/) || [])[1].split(/\s/)[3];
if (!heightStr) return displayError(el, new Error('Could not determine chart height'));
const iframe = document.createElement('iframe');
iframe.classList.add('markup-render');
Expand Down

0 comments on commit 68b06ca

Please sign in to comment.