Commit e239078f authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Updating mermaid-cli version

parent 10bc6133
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for generateBaseline/dockerfile.pandoc: 1 added line, 1 removed line.
Original line number Original line Diff line number Diff line
FROM node:18.20-bookworm-slim AS nodejs
FROM node:18.20-bookworm-slim AS nodejs
FROM ghcr.io/mermaid-js/mermaid-cli/mermaid-cli:11.4.2 AS mermaidcli
FROM ghcr.io/mermaid-js/mermaid-cli/mermaid-cli:11.17.0 AS mermaidcli


FROM pandoc/latex:3.4.0-ubuntu
FROM pandoc/latex:3.4.0-ubuntu


+17 −15
Changes for generateBaseline/mermaid-filter.js: 17 added lines, 15 removed lines.
Original line number Original line Diff line number Diff line
@@ -70,24 +70,25 @@ function figureCaptionInlines(el) {
	return out;
	return out;
}
}


// stateDiagram-v2 treats unquoted "A --> B : label" as mermaid syntax.
function mermaidLibVersion() {
// HTML <br /> and extra ":" in labels (e.g. "IPE: send_goal") must be quoted.
	try {
function prepareMermaidSource(content) {
		const pkgPath = path.resolve(path.dirname(MMDC), '..', '..', '..', 'mermaid', 'package.json');
	let source = String(content).replace(/<\s*br\s*\/?\s*>/gi, '<br/>');
		return JSON.parse(fs.readFileSync(pkgPath, 'utf8')).version;
	source = source.replace(
	} catch (e) {
		/^(\s*(?:\[\*\]|[A-Za-z_][\w]*)\s*-->\s*(?:\[\*\]|[A-Za-z_][\w]*)\s*:\s*)(.*)$/gm,
		return 'unknown';
		function (_match, prefix, label) {
			const trimmed = label.replace(/\s+$/, '');
			if (!trimmed || (trimmed.charAt(0) === '"' && trimmed.charAt(trimmed.length - 1) === '"')) {
				return prefix + trimmed;
	}
	}
			if (/<|&|:/.test(trimmed)) {
				return prefix + '"' + trimmed.replace(/\\/g, '\\\\').replace(/"/g, '#quot;') + '"';
}
}
			return prefix + trimmed;

// mermaid.live accepts `A --> B : IPE: send_goal<br/>...`. Quotes around that
// label are not string syntax in stateDiagram-v2, so the inner ":" is still
// token DESCR. Unwrap them; leave the rest of the diagram unchanged.
function unwrapStateLabelQuotes(content) {
	return String(content).replace(
		/^(\s*(?:\[\*\]|[A-Za-z_][\w]*)\s*-->\s*(?:\[\*\]|[A-Za-z_][\w]*)\s*:\s*)"(.*)"\s*$/gm,
		function (_match, prefix, label) {
			return prefix + label;
		}
		}
	);
	);
	return source;
}
}


function renderMermaid(el, caption) {
function renderMermaid(el, caption) {
@@ -97,7 +98,7 @@ function renderMermaid(el, caption) {
	const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mermaid-'));
	const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mermaid-'));
	const input = path.join(tmp, 'in.mmd');
	const input = path.join(tmp, 'in.mmd');
	const output = path.join(tmp, 'out.png');
	const output = path.join(tmp, 'out.png');
	fs.writeFileSync(input, prepareMermaidSource(content), 'utf8');
	fs.writeFileSync(input, unwrapStateLabelQuotes(content), 'utf8');


	const args = [
	const args = [
		'-i', input,
		'-i', input,
@@ -124,6 +125,7 @@ function renderMermaid(el, caption) {
		});
		});
	} catch (err) {
	} catch (err) {
		const stderr = err.stderr ? err.stderr.toString() : String(err);
		const stderr = err.stderr ? err.stderr.toString() : String(err);
		fs.writeSync(2, 'mermaid ' + mermaidLibVersion() + '\n');
		fs.writeSync(2, 'mmdc failed:\n' + stderr + '\n');
		fs.writeSync(2, 'mmdc failed:\n' + stderr + '\n');
		process.exit(1);
		process.exit(1);
	}
	}