Loading generateBaseline/dockerfile.pandoc +56 −3 Changes for generateBaseline/dockerfile.pandoc: 56 added lines, 3 removed lines. Original line number Diff line number Diff line FROM ghcr.io/mermaid-js/mermaid-cli/mermaid-cli:11.4.2 AS mermaidcli FROM pandoc/latex:3.4.0-ubuntu RUN apt-get update -y && \ apt-get install -y npm &&\ npm install --global mermaid-filter # mermaid diagrams: copy prebuilt mermaid-cli (mmdc) and a local pandoc # filter that shells out to it. Do not npm-install mermaid-filter — that # tree hangs for hours against registry.npmjs.org from this runner. # publish_spec.sh still uses -F mermaid-filter (this script is on PATH). ENV DEBIAN_FRONTEND=noninteractive \ DEBCONF_NOWARNINGS=yes \ PUPPETEER_SKIP_DOWNLOAD=true \ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \ MERMAID_FILTER_PUPPETEER_CONFIG=/opt/mermaid/puppeteer.json \ MERMAID_FILTER_CMD_MMDC=/opt/mermaidcli/node_modules/.bin/mmdc RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections && \ rm -f /var/lib/man-db/auto-update && \ printf '#!/bin/sh\nexit 101\n' > /usr/sbin/policy-rc.d && \ chmod +x /usr/sbin/policy-rc.d && \ printf '%s\n' \ 'path-exclude=/usr/share/doc/*' \ 'path-exclude=/usr/share/man/*' \ 'path-exclude=/usr/share/info/*' \ > /etc/dpkg/dpkg.cfg.d/01_nodoc && \ apt-get update -y && \ apt-get install -y --no-install-recommends \ nodejs \ wget \ ca-certificates \ fonts-liberation \ fonts-dejavu-core # Reuse the apt lists from the previous layer (do not apt-get update again). # Visible download, 30s network timeout so a blocked dl.google.com fails fast. RUN wget --timeout=30 --tries=2 --progress=dot:giga \ -O /tmp/google-chrome.deb \ https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \ apt-get install -y --no-install-recommends /tmp/google-chrome.deb && \ rm -f /tmp/google-chrome.deb && \ rm -rf /var/lib/apt/lists/* COPY --from=mermaidcli /home/mermaidcli/node_modules /opt/mermaidcli/node_modules COPY mermaid-filter.js /usr/local/bin/mermaid-filter RUN chmod +x /usr/local/bin/mermaid-filter && \ mkdir -p /opt/mermaid && \ printf '%s\n' \ '{' \ ' "executablePath": "/usr/bin/google-chrome-stable",' \ ' "args": [' \ ' "--no-sandbox",' \ ' "--disable-setuid-sandbox",' \ ' "--disable-dev-shm-usage",' \ ' "--disable-gpu"' \ ' ]' \ '}' \ > /opt/mermaid/puppeteer.json CMD ["/bin/sh"] Loading generateBaseline/mermaid-filter.js +93 Changes for generateBaseline/mermaid-filter.js: 93 added lines, 0 removed lines. Original line number Diff line number Diff line #!/usr/bin/env node 'use strict'; // Pandoc JSON filter (drop-in for mermaid-filter). No npm packages: // reads the AST from stdin, renders ```mermaid blocks with mmdc, writes AST to stdout. const fs = require('fs'); const os = require('os'); const path = require('path'); const { execFileSync } = require('child_process'); const MMDC = process.env.MERMAID_FILTER_CMD_MMDC || 'mmdc'; const PUPPETEER = process.env.MERMAID_FILTER_PUPPETEER_CONFIG || ''; const WIDTH = process.env.MERMAID_FILTER_WIDTH || '800'; const THEME = process.env.MERMAID_FILTER_THEME || 'default'; const BACKGROUND = process.env.MERMAID_FILTER_BACKGROUND || 'white'; function isMermaidBlock(el) { return el && el.t === 'CodeBlock' && Array.isArray(el.c) && Array.isArray(el.c[0]) && Array.isArray(el.c[0][1]) && el.c[0][1].indexOf('mermaid') >= 0; } function renderMermaid(el) { const attrs = el.c[0]; const content = el.c[1]; const id = attrs[0] || ''; const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mermaid-')); const input = path.join(tmp, 'in.mmd'); const output = path.join(tmp, 'out.png'); fs.writeFileSync(input, content, 'utf8'); const args = [ '-f', '-i', input, '-o', output, '-w', String(WIDTH), '-s', '1', '-t', THEME, '-b', BACKGROUND ]; if (PUPPETEER && fs.existsSync(PUPPETEER)) { args.unshift('-p', PUPPETEER); } try { execFileSync(MMDC, args, { stdio: ['ignore', 'pipe', 'pipe'] }); } catch (err) { const stderr = err.stderr ? err.stderr.toString() : String(err); fs.writeSync(2, 'mmdc failed:\n' + stderr + '\n'); process.exit(1); } const data = fs.readFileSync(output); const src = 'data:image/png;base64,' + data.toString('base64'); try { fs.rmSync(tmp, { recursive: true, force: true }); } catch (e) { /* ignore */ } const fig = id.startsWith('fig:') ? 'fig:' : ''; return { t: 'Para', c: [{ t: 'Image', c: [[id, [], []], [], [src, fig]] }] }; } function walk(node) { if (Array.isArray(node)) { return node.map(walk); } if (node && typeof node === 'object') { if (isMermaidBlock(node)) { return renderMermaid(node); } if (Object.prototype.hasOwnProperty.call(node, 'c')) { node.c = walk(node.c); } return node; } return node; } let raw = ''; process.stdin.setEncoding('utf8'); process.stdin.on('data', function (chunk) { raw += chunk; }); process.stdin.on('end', function () { const doc = JSON.parse(raw); process.stdout.write(JSON.stringify(walk(doc))); }); Loading
generateBaseline/dockerfile.pandoc +56 −3 Changes for generateBaseline/dockerfile.pandoc: 56 added lines, 3 removed lines. Original line number Diff line number Diff line FROM ghcr.io/mermaid-js/mermaid-cli/mermaid-cli:11.4.2 AS mermaidcli FROM pandoc/latex:3.4.0-ubuntu RUN apt-get update -y && \ apt-get install -y npm &&\ npm install --global mermaid-filter # mermaid diagrams: copy prebuilt mermaid-cli (mmdc) and a local pandoc # filter that shells out to it. Do not npm-install mermaid-filter — that # tree hangs for hours against registry.npmjs.org from this runner. # publish_spec.sh still uses -F mermaid-filter (this script is on PATH). ENV DEBIAN_FRONTEND=noninteractive \ DEBCONF_NOWARNINGS=yes \ PUPPETEER_SKIP_DOWNLOAD=true \ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \ MERMAID_FILTER_PUPPETEER_CONFIG=/opt/mermaid/puppeteer.json \ MERMAID_FILTER_CMD_MMDC=/opt/mermaidcli/node_modules/.bin/mmdc RUN echo 'man-db man-db/auto-update boolean false' | debconf-set-selections && \ rm -f /var/lib/man-db/auto-update && \ printf '#!/bin/sh\nexit 101\n' > /usr/sbin/policy-rc.d && \ chmod +x /usr/sbin/policy-rc.d && \ printf '%s\n' \ 'path-exclude=/usr/share/doc/*' \ 'path-exclude=/usr/share/man/*' \ 'path-exclude=/usr/share/info/*' \ > /etc/dpkg/dpkg.cfg.d/01_nodoc && \ apt-get update -y && \ apt-get install -y --no-install-recommends \ nodejs \ wget \ ca-certificates \ fonts-liberation \ fonts-dejavu-core # Reuse the apt lists from the previous layer (do not apt-get update again). # Visible download, 30s network timeout so a blocked dl.google.com fails fast. RUN wget --timeout=30 --tries=2 --progress=dot:giga \ -O /tmp/google-chrome.deb \ https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \ apt-get install -y --no-install-recommends /tmp/google-chrome.deb && \ rm -f /tmp/google-chrome.deb && \ rm -rf /var/lib/apt/lists/* COPY --from=mermaidcli /home/mermaidcli/node_modules /opt/mermaidcli/node_modules COPY mermaid-filter.js /usr/local/bin/mermaid-filter RUN chmod +x /usr/local/bin/mermaid-filter && \ mkdir -p /opt/mermaid && \ printf '%s\n' \ '{' \ ' "executablePath": "/usr/bin/google-chrome-stable",' \ ' "args": [' \ ' "--no-sandbox",' \ ' "--disable-setuid-sandbox",' \ ' "--disable-dev-shm-usage",' \ ' "--disable-gpu"' \ ' ]' \ '}' \ > /opt/mermaid/puppeteer.json CMD ["/bin/sh"] Loading
generateBaseline/mermaid-filter.js +93 Changes for generateBaseline/mermaid-filter.js: 93 added lines, 0 removed lines. Original line number Diff line number Diff line #!/usr/bin/env node 'use strict'; // Pandoc JSON filter (drop-in for mermaid-filter). No npm packages: // reads the AST from stdin, renders ```mermaid blocks with mmdc, writes AST to stdout. const fs = require('fs'); const os = require('os'); const path = require('path'); const { execFileSync } = require('child_process'); const MMDC = process.env.MERMAID_FILTER_CMD_MMDC || 'mmdc'; const PUPPETEER = process.env.MERMAID_FILTER_PUPPETEER_CONFIG || ''; const WIDTH = process.env.MERMAID_FILTER_WIDTH || '800'; const THEME = process.env.MERMAID_FILTER_THEME || 'default'; const BACKGROUND = process.env.MERMAID_FILTER_BACKGROUND || 'white'; function isMermaidBlock(el) { return el && el.t === 'CodeBlock' && Array.isArray(el.c) && Array.isArray(el.c[0]) && Array.isArray(el.c[0][1]) && el.c[0][1].indexOf('mermaid') >= 0; } function renderMermaid(el) { const attrs = el.c[0]; const content = el.c[1]; const id = attrs[0] || ''; const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mermaid-')); const input = path.join(tmp, 'in.mmd'); const output = path.join(tmp, 'out.png'); fs.writeFileSync(input, content, 'utf8'); const args = [ '-f', '-i', input, '-o', output, '-w', String(WIDTH), '-s', '1', '-t', THEME, '-b', BACKGROUND ]; if (PUPPETEER && fs.existsSync(PUPPETEER)) { args.unshift('-p', PUPPETEER); } try { execFileSync(MMDC, args, { stdio: ['ignore', 'pipe', 'pipe'] }); } catch (err) { const stderr = err.stderr ? err.stderr.toString() : String(err); fs.writeSync(2, 'mmdc failed:\n' + stderr + '\n'); process.exit(1); } const data = fs.readFileSync(output); const src = 'data:image/png;base64,' + data.toString('base64'); try { fs.rmSync(tmp, { recursive: true, force: true }); } catch (e) { /* ignore */ } const fig = id.startsWith('fig:') ? 'fig:' : ''; return { t: 'Para', c: [{ t: 'Image', c: [[id, [], []], [], [src, fig]] }] }; } function walk(node) { if (Array.isArray(node)) { return node.map(walk); } if (node && typeof node === 'object') { if (isMermaidBlock(node)) { return renderMermaid(node); } if (Object.prototype.hasOwnProperty.call(node, 'c')) { node.c = walk(node.c); } return node; } return node; } let raw = ''; process.stdin.setEncoding('utf8'); process.stdin.on('data', function (chunk) { raw += chunk; }); process.stdin.on('end', function () { const doc = JSON.parse(raw); process.stdout.write(JSON.stringify(walk(doc))); });