Mermaid conversion not working on first try

Hidyho,

I a having an odd issue. I have a base of markdown which includes mermaid diagrams. I built a Docker image which includes your mermaid filter, mostly trying to follow https://gist.github.com/MyriaCore/75729707404cba1c0de89cc03b7a6adf but also the content in this repo. When I run pandoc against a markdown file with mermaid content, it errors out but then passes on the second try.

FROM pandoc/latex:latest-ubuntu

ENV DIST_CODENAME=jammy

ENV DEBIAN_FRONTEND=noninteractive

ENV NPM_CONFIG_CAFILE=/etc/ssl/certs/ca-certificates.crt
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
ENV SSL_CERT_DIR=/etc/ssl/certs
ENV PUPPETEER_CFG=/root/.puppeteer-config.json
ENV MERMAID_THEME='neutral'
ENV KROKI_DIAGRAM_BLACKLIST='mermaid'
ENV DISPLAY=:100.0

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update \
    && apt-get install  --no-install-recommends -y \
    ca-certificates \
    tzdata \
    libexpat1 \
    libssl3 \
    libatk-bridge2.0-0 \
    libxcomposite1 \
    openssl \
    plantuml \
    git \
    python3-pip \
    lua5.4 \
    libgbm-dev \
    libgbm1 \
    libxkbcommon-dev \
    libxdamage1 \
    libxrandr2 \
    texlive-full \
    xvfb \
    \
    && curl -fsSL https://deb.nodesource.com/setup_16.x | bash \
    && apt-get install -y nodejs \
    && npm install -g yarn \
    && yarn global add @mermaid-js/mermaid-cli \
    \
    && pip install git+https://github.com/MyriaCore/pandoc-plantuml-filter.git \
    && pip install git+https://github.com/MyriaCore/pandoc-mermaid-filter.git \
    && pip install git+https://gitlab.com/myriacore/pandoc-kroki-filter.git \
    && mkdir -p ~/.pandoc/filters ~/.pandoc/templates \
    && wget -O ~/.pandoc/filters/gitlab-math.lua https://gist.githubusercontent.com/lierdakil/00d8143465a488e0b854a3b4bf355cf6/raw/gitlab-math.lua \
    && wget -O ~/.pandoc/filters/fix-links.lua https://gist.githubusercontent.com/MyriaCore/75729707404cba1c0de89cc03b7a6adf/raw/fix-links.lua \
    && wget -O ~/.pandoc/templates/GitHub.html5 https://raw.githubusercontent.com/tajmone/pandoc-goodies/master/templates/html5/github/GitHub.html5 \
    && wget -O ~/.pandoc/templates/eisvogel.latex https://raw.githubusercontent.com/Wandmalfarbe/pandoc-latex-template/master/eisvogel.tex \
    && apt-get clean autoclean \
    && apt-get autoremove --yes \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/log/*log /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old

COPY .puppeteer-config.json /root/.puppeteer-config.json

ENTRYPOINT []

The puppeteer-config.json looks like:

{
  "args": ["--no-sandbox"]
}

Example Markdown doc:

# Deployment Framework


## GitLab CICD Pipelines

The Gitlab CI/CD documentation does a really good job of
breaking down the components. But in short, a GitLab CICD pipeline is a series
of tasks that run in one or more stages, with one or more jobs that run parallel
per stage.

```mermaid
sequenceDiagram
  participant S1 as Build
  participant S2 as Test
  participant S3 as Deploy
  S1->>S1: Build Artifact 1
  S1->>S1: Build Artifact 2
  S1->>S2: Build Finished
  S2->>S2: Test 1
  S2->>S2: Test 2
  S2->>S3: Tests Finished
  S3->>S3: Deploy AWS<br />Resources
  S3->>S3: Deploy Artifacts

The command I run:

pandoc --from markdown --to html5 --embed-resources --standalone --filter pandoc-kroki --filter pandoc-plantuml --filter pandoc-mermaid --lua-filter gitlab-math.lua --lua-filter fix-links.lua --katex=https://cdn.jsdelivr.net/npm/katex@latest/dist/ --template=GitHub.html5 --table-of-contents --strip-comments --verbose -o index.html README.md
[INFO] Running filter pandoc-kroki
[INFO] Completed filter pandoc-kroki in 1 ms
[INFO] Running filter pandoc-plantuml
[INFO] Completed filter pandoc-plantuml in 1 ms
[INFO] Running filter pandoc-mermaid
Created directory mermaid-images
Created image mermaid-images/7c04737efea1944e8cf7230b1c14c38dec1dc5cd.svg
Error running filter pandoc-mermaid:
Error in $: Failed reading: not a valid json value at 'Generatingsinglemermaidchart'

And with no other changes, I run it again...

pandoc --from markdown --to html5 --embed-resources --standalone --filter pandoc-kroki --filter pandoc-plantuml --filter pandoc-mermaid --lua-filter gitlab-math.lua --lua-filter fix-links.lua --katex=https://cdn.jsdelivr.net/npm/katex@latest/dist/ --template=GitHub.html5 --table-of-contents --strip-comments --verbose -o index.html README.md
[INFO] Running filter pandoc-kroki
[INFO] Completed filter pandoc-kroki in 1 ms
[INFO] Running filter pandoc-plantuml
[INFO] Completed filter pandoc-plantuml in 1 ms
[INFO] Running filter pandoc-mermaid
Could not create directory "mermaid-images"
[INFO] Completed filter pandoc-mermaid in 2 ms
[INFO] Running filter /root/.pandoc/filters/gitlab-math.lua
[INFO] Completed filter /root/.pandoc/filters/gitlab-math.lua in 3 ms
[INFO] Running filter /root/.pandoc/filters/fix-links.lua
[INFO] Completed filter /root/.pandoc/filters/fix-links.lua in 3 ms
[INFO] No value for 'lang' was specified in the metadata.
  It is recommended that lang be specified for this format.
[WARNING] This document format requires a nonempty <title> element.
  Defaulting to 'README' as the title.
  To specify a title, use 'title' in metadata or --metadata title="...".
[INFO] Loaded mermaid-images/7c04737efea1944e8cf7230b1c14c38dec1dc5cd.svg from mermaid-images/7c04737efea1944e8cf7230b1c14c38dec1dc5cd.svg