Fix Mermaid diagrams failing when node labels contain line breaks (#37296)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -68,7 +68,7 @@ async function initRepoPullRequestMergeForm(box: HTMLElement) {
|
|||||||
view.mount(el);
|
view.mount(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeScripts(elem: HTMLElement) {
|
function executeScripts(elem: Element) {
|
||||||
// find any existing nonce value from the current page and apply it to the new script
|
// find any existing nonce value from the current page and apply it to the new script
|
||||||
const scriptNonce = document.querySelector('script[nonce]')!.getAttribute('nonce')!;
|
const scriptNonce = document.querySelector('script[nonce]')!.getAttribute('nonce')!;
|
||||||
for (const oldScript of elem.querySelectorAll('script')) {
|
for (const oldScript of elem.querySelectorAll('script')) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {isDarkTheme, parseDom} from '../utils.ts';
|
import {isDarkTheme} from '../utils.ts';
|
||||||
import {displayError} from './common.ts';
|
import {displayError} from './common.ts';
|
||||||
import {createElementFromAttrs, createElementFromHTML, queryElems} from '../utils/dom.ts';
|
import {createElementFromAttrs, createElementFromHTML, queryElems} from '../utils/dom.ts';
|
||||||
import {html, htmlRaw} from '../utils/html.ts';
|
import {html, htmlRaw} from '../utils/html.ts';
|
||||||
@@ -81,7 +81,7 @@ async function loadMermaid(needElkRender: boolean) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function initMermaidViewController(viewController: HTMLElement, dragElement: SVGSVGElement) {
|
function initMermaidViewController(viewController: Element, dragElement: SVGSVGElement) {
|
||||||
let inited = false, isDragging = false;
|
let inited = false, isDragging = false;
|
||||||
let currentScale = 1, initLeft = 0, lastLeft = 0, lastTop = 0, lastPageX = 0, lastPageY = 0;
|
let currentScale = 1, initLeft = 0, lastLeft = 0, lastTop = 0, lastPageX = 0, lastPageY = 0;
|
||||||
|
|
||||||
@@ -201,8 +201,7 @@ export async function initMarkupCodeMermaid(elMarkup: HTMLElement): Promise<void
|
|||||||
try {
|
try {
|
||||||
// render the mermaid diagram to svg text, and parse it to a DOM node
|
// render the mermaid diagram to svg text, and parse it to a DOM node
|
||||||
const {svg: svgText, bindFunctions} = await mermaid.render('mermaid', source, parentContainer);
|
const {svg: svgText, bindFunctions} = await mermaid.render('mermaid', source, parentContainer);
|
||||||
const svgDoc = parseDom(svgText, 'image/svg+xml');
|
const svgNode = createElementFromHTML<SVGSVGElement>(svgText);
|
||||||
const svgNode = (svgDoc.documentElement as unknown) as SVGSVGElement;
|
|
||||||
|
|
||||||
const viewControllerHtml = html`
|
const viewControllerHtml = html`
|
||||||
<div class="view-controller auto-hide-control flex-text-block">
|
<div class="view-controller auto-hide-control flex-text-block">
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ export function isElemVisible(el: HTMLElement): boolean {
|
|||||||
return Boolean(!el.classList.contains('tw-hidden') && (el.offsetWidth || el.offsetHeight || el.getClientRects().length) && el.style.display !== 'none');
|
return Boolean(!el.classList.contains('tw-hidden') && (el.offsetWidth || el.offsetHeight || el.getClientRects().length) && el.style.display !== 'none');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createElementFromHTML<T extends HTMLElement>(htmlString: string): T {
|
export function createElementFromHTML<T extends Element>(htmlString: string): T {
|
||||||
htmlString = htmlString.trim();
|
htmlString = htmlString.trim();
|
||||||
// There is no way to create some elements without a proper parent, jQuery's approach: https://github.com/jquery/jquery/blob/main/src/manipulation/wrapMap.js
|
// There is no way to create some elements without a proper parent, jQuery's approach: https://github.com/jquery/jquery/blob/main/src/manipulation/wrapMap.js
|
||||||
// eslint-disable-next-line github/unescaped-html-literal
|
// eslint-disable-next-line github/unescaped-html-literal
|
||||||
|
|||||||
Reference in New Issue
Block a user