Skip to content

Add optional Mermaid support via the Confluence mermaid-macro output - #1022

Open
arturskavarada wants to merge 1 commit into
kovetskiy:masterfrom
arturskavarada:master
Open

arturskavarada wants to merge 1 commit into
kovetskiy:masterfrom
arturskavarada:master

Conversation

@arturskavarada

Copy link
Copy Markdown

What

Adds a third value to --mermaid-output: macro. With the mermaid feature
enabled, a ```mermaid block gets published as the Confluence macro
mermaid-macro instead of an image rendered by mark:

<ac:structured-macro ac:name="mermaid-macro">ac:plain-text-body<![CDATA[flowchart TD
A[Start] --> B[End]]]></ac:plain-text-body></ac:structured-macro>

The diagram source goes into the macro as-is, and the drawing itself is done
by the Mermaid macro installed on the instance. That means the instance needs
to have one installed - otherwise nothing renders.

Why

We run mark against a Confluence that already has the Mermaid macro, so going
through mark's own Chrome/merman pipeline is pure overhead: images,
attachments, checksums, none of it is needed.

I picked a new value on --mermaid-output instead of a separate feature flag
because mermaid already has an output flag (png/svg), so a third channel
fits right in. The plantuml feature took the feature-flag route only because
there was no output flag to extend.

Changes

  • renderer/fencedcodeblock.go - when mermaid is on and
    --mermaid-output=macro, the block renders through the macro template.
    The check sits before the image branch, so macro wins over png/svg.
  • stdlib/stdlib.go - new ac:mermaid-macro template, diagram source in a
    plain-text body CDATA.
  • util/flags.go and mark.go - macro is now accepted and validated on
    the CLI and in the public Config path. Usage text updated.
  • types/types.go - MermaidOutput comment now mentions all three values.
  • Tests: markdown/mermaid_output_test.go (macro output, drop-h1, fallback
    to a plain code block without the mermaid feature) and
    util/cli_test.go (flag validation).
  • README: new section "Render Mermaid Diagrams via the Confluence Macro".

Not changed

  • Default rendering stays png/svg; --mermaid-bundle and the scale flags
    are untouched.
  • --features semantics are the same - the macro output still needs
    mermaid to be enabled.

@mrueg

mrueg commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

There's no native renderer in confluence as far as I'm aware and only custom plugins. Is this using a custom plugin or has anything changed on confluence side?

@arturskavarada

Copy link
Copy Markdown
Author

@mrueg
Correct, Confluence comes with no built-in Mermaid renderer this only affects instances that run a Mermaid plugin provided by a third party. Our setup has org.anvard.atlassian.mermaid-plugin, v1.12.4 (Mermaid Diagrams for Confluence) installed, and the plugin declares the mermaid-macro macro.
This feature resembles the plantuml one in that the macro name is fixed and the corresponding plugin must be installed in the Confluence instance, as is written in the README part.

@arturskavarada

Copy link
Copy Markdown
Author

Hi, just a gentle reminder about this PR. When you have a moment, I’d appreciate a review. Happy to make changes if needed.

@flojon

flojon commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Checked out the branch: it merges cleanly into current master, and the markdown, util and mermaid tests pass.

Two small suggestions:

  1. The README says "a Mermaid macro". Naming the plugin from the thread (org.anvard.atlassian.mermaid-plugin, "Mermaid Diagrams for Confluence") would help users check they have the right one, since other Mermaid plugins may use a different macro key.
  2. With macro, --mermaid-scale and --mermaid-bundle have no effect. A line in the flag help would save confusion. I didn't check whether --mermaid-bundle without svg still errors in that case.

@arturskavarada

Copy link
Copy Markdown
Author

@flojon thanks for the review.

  1. README now names the plugin we use — org.anvard.atlassian.mermaid-plugin (Mermaid Diagrams for Confluence) - with a note that other plugins may use a different macro key.
  2. Added a note to --mermaid-output and --mermaid-bundle help that both --mermaid-scale and --mermaid-bundle have no effect with macro.

On your last point: --mermaid-bundle with macro used to fail with a misleading "nowhere in a PNG" error. It is now a no-op, since the macro output already publishes the diagram's source verbatim - there is nothing for a bundle to add. --mermaid-bundle with png still errors as before.

@flojon

flojon commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Thanks @arturskavarada!

Sorry, I've changed my mind on one of my earlier suggestions. Instead of documenting that --mermaid-scale and --mermaid-bundle do nothing with macro, I think we should reject those combinations. Details below.

Whether to take this feature is @mrueg's call. I'm just sharing my view.

1. Reject invalid flag combinations instead of documenting them

--mermaid-bundle is already an error with png, so rejecting it with macro is consistent. I'd handle the three flags like this:

  • --mermaid-bundle: error with macro.
  • --mermaid-scale and --mermaid-engine: both have defaults, so error only when set explicitly (command.IsSet).
  • The usage text for --mermaid-output=macro doesn't mention --mermaid-engine yet, so please cover it there too.

2. Make the macro key configurable, under a --mermaid-macro-* prefix

Your README notes that other plugins may use a different macro key. I'd add --mermaid-macro-name (env MARK_MERMAID_MACRO_NAME, default mermaid-macro), escaped with xmlesc. It should error if it's empty, or if it's set without --mermaid-output=macro.

The prefix leaves room for other plugin types later, such as ones that take the diagram source as a parameter or an attachment, without changing these flags. I wouldn't implement those here, since each needs someone running that plugin to test it.

@arturskavarada

Copy link
Copy Markdown
Author

@flojon thanks, both make sense.

  1. --mermaid-bundle, --mermaid-scale and --mermaid-engine are now
    refused with --mermaid-output=macro instead of documented as no-ops.
    The bundle errors like it already does with png; the scale and engine
    carry defaults, so they are refused only when set explicitly. The public
    Config path (prepare) is held to the same rules, so a library caller
    gets the same refusal. The --mermaid-output usage now names the engine
    too.

  2. Added --mermaid-macro-name (env MARK_MERMAID_MACRO_NAME, default
    mermaid-macro), escaped with xmlesc. It errors when empty or when set
    without --mermaid-output=macro. The --mermaid-macro-* prefix leaves
    room for other plugin types later, as you suggested; I left those out for
    now.

One asymmetry worth flagging: the CLI rejects an explicitly-empty name, but
the library path treats an empty name as "use the default", since it has no
IsSet. The default lives in one place (types.MermaidMacroDefaultName),
shared by the flag and the renderer.

Whether to take this feature is @mrueg call - happy to adjust either way.

@flojon

flojon commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Thanks @arturskavarada, this is close. One blocker: with the CLI, --mermaid-output macro on its own fails with MermaidEngine has no effect with MermaidOutput "macro". util/cli.go always copies the defaults (chrome, 1.0) into Config, and prepare() now rejects them. Like the macro name, engine and scale should only be copied when cmd.IsSet(...). A test that goes from the CLI to prepare() would catch it.

Also, the --mermaid-output usage still says engine, scale and bundle "have no effect" with macro; it should say they're refused.

@arturskavarada

Copy link
Copy Markdown
Author

@flojon Fixed:

  • util/cli.go no longer copies the engine and scale defaults into Config:
    MermaidEngine and MermaidScale are now read only when cmd.IsSet(...),
    like the macro name, so --mermaid-output=macro on its own works.
  • The --mermaid-output usage says the three are refused, not that they
    "have no effect".
  • Added TestMermaidMacroOutputNeedsNoDrawingFlags, which runs the CLI with
    --mermaid-output=macro and asserts it passes through prepare().

@flojon

flojon commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Thanks! Looks good to me!

@flojon

flojon commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Re-reviewed at 1a1a6258, after the force-push and the plantuml refactor. This supersedes my earlier "no issues" comment, which was written against the previous head. I found no correctness issues.

  • Plantuml refactor: output is byte-identical. The new ac:plain-text-macro template keeps the same cdata body, and plantuml renders only in renderer/fencedcodeblock.go, so both compile paths share it.
  • Flags: zero values are handled consistently, including env and TOML sources, and the macro-name and engine/scale/bundle refusals look right.
  • Renderer: the macro branch sits inside the mermaid feature check, and the name is escaped.

One optional nit: the pasted mark --help block in the README (around lines 1963-1964) is stale. --mermaid-output and --mermaid-bundle don't mention macro, and there is no --mermaid-macro-name line, so it differs from the real --help output. The new prose section is accurate.

Thanks for the PR!

@arturskavarada

Copy link
Copy Markdown
Author

@flojon thanks — also refreshed the pasted mark --help block in the README:
--mermaid-output and --mermaid-bundle now mention macro, and
--mermaid-macro-name is listed.

@arturskavarada

Copy link
Copy Markdown
Author

Hi, just a gentle reminder about this PR. When you have a moment, I’d appreciate a review. Happy to make changes if needed.

@flojon

flojon commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for this. Review notes below; none of them are blockers on their own.

Behavior

  1. util/flags.go (macro check): command.IsSet("mermaid-engine"/"mermaid-scale") is also true when the value comes from an env var or the TOML config. Someone with MARK_MERMAID_SCALE or mermaid-engine in their config gets a hard error with --mermaid-output=macro and can't override it from the CLI. Consider warning and ignoring instead of refusing.
  2. util/cli.go: only engine/scale/macro-name are now conditional on IsSet, while d2-scale, math-scale etc. are still passed unconditionally. Relying on 0 / "" meaning "default" everywhere downstream works today, but the conventions now differ between fields. Doing the "has no effect" check only in CheckFlags (where IsSet exists) would avoid reshaping Config.
  3. --mermaid-output=macro / --mermaid-macro-name aren't checked against the mermaid feature being enabled. Without it a mermaid fence silently stays a plain code block (the test ...MermaidMacroNeedsTheFeature locks that in). A warning would help.

Tests
4. No golden fixture (testdata/mermaid-macro.md / .html) like the other renderers have, only inline expectations. It would also be worth confirming that the target plugin accepts a plain-text body with no parameters.
5. The three macro tests in markdown/mermaid_output_test.go repeat the same document/expected block; a table would be shorter. TestMermaidMacroOutputNeedsNoDrawingFlags exercises util.RunMark from markdown/, where util/cli_test.go already has the harness.

Cleanup
6. The same mermaid rules (bundle needs svg, engine/scale refused with macro, name needs macro) are implemented in both prepare() and CheckFlags with different messages; a shared helper would prevent drift.
7. ac:plantuml in stdlib/stdlib.go is kept but no longer used by the renderer; either define it via ac:plain-text-macro or drop it.
8. A few comments describe history ("used to read the flag defaults"); the repo style is to comment only the non-obvious why.

Note: I ran the tests locally (Windows). go build, go vet and go test ./... pass for the touched packages (mermaid, util, renderer, stdlib, attachment). The branch is 7 commits behind master, and without master's Windows test fixes and .gitattributes, a few unrelated tests fail here (markdown golden files, d2, manifest). With current master merged in locally, everything passes except TestManifestPageByIDAcrossTwoSpaces, which also fails on master. Please merge or rebase master. CI shows no check runs for this head commit (likely fork workflows awaiting approval).

@arturskavarada

Copy link
Copy Markdown
Author

@flojon thanks, all eight addressed — and current master merged in.

Behavior

  1. --mermaid-engine / --mermaid-scale beside macro, and --mermaid-macro-name beside an image output, now warn and are ignored instead of refused. The warning lives in util/cli.go: the Before hook runs before the logger is configured, so the message would otherwise be unformatted, and IsSet is available there too — an env or TOML value no longer fails a run.
  2. Config is uniform again: every mermaid setting is copied from its flag, and prepare() no longer refuses "has no effect" combinations — it validates only values that cannot be honoured.
  3. --mermaid-output=macro without the mermaid feature now warns in prepare(), so it is said whichever entry point the caller used.

Tests
4. Added testdata/mermaid-macro.md with mermaid-macro.html, -droph1.html and -macro.html, mirroring the plantuml fixture, plus TestCompileMarkdownMermaidMacroGolden. I could not exercise the plugin itself here; the body is the same plain-text shape plantuml already relies on.
5. The three macro render tests are one table, and TestMermaidMacroOutputNeedsNoDrawingFlags moved to util/cli_test.go, next to the flag harness.

Cleanup
6. ValidateMermaidOutput and ValidateMermaidBundle in the root package are called by both prepare() and CheckFlags, so the two cannot drift.
7. ac:plantuml kept on purpose: it is a public template name that include templates may call, and Go templates cannot alias it to ac:plain-text-macro with a fixed Name without a dict helper. Dropping it would be a separate breaking change.
8. Removed the history comments in the touched code.

Also merged current master (8 commits) and renormalised the Windows testdata checkout. go build, go vet and go test ./... pass, except the four attachment symlink tests, which need the Windows symlink privilege.

CI may still need approval for the fork workflows.

@flojon

flojon commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Thanks @arturskavarada, re-checked at 1ab256a. Points 1, 2, 3, 5 and 8 are addressed, and I accept keeping ac:plantuml. A few things remain, two of which I'd ask you to change. I built the head and ran the CLI to confirm them.

Please change

  1. Invalid values still abort a macro run. The comment in prepare() says engine and scale are not refused with macro, but:

    • MARK_MERMAID_SCALE=-1 mark -f x.md --compile-only --mermaid-output=macro exits with invalid value for --mermaid-scale: -1.
    • --mermaid-engine=bogus with macro exits with invalid value for --mermaid-engine.
    • prepare() also still rejects a bad MermaidScale when the mermaid feature is on (around mark.go:274).

    Nothing is drawn in this mode, so these checks should be skipped when the output is macro.

  2. An empty --mermaid-macro-name is refused for every output. MARK_MERMAID_MACRO_NAME= with the default png fails with --mermaid-macro-name must not be empty, although the name is unused there. That is the case you now warn about instead of refusing. Refuse it only when the output is macro.

Smaller

  1. Point 6 is half done. CheckFlags still has its own png/svg/macro switch, and ValidateMermaidOutput is only called from prepare(), though its doc comment says it is shared. Please call it from CheckFlags too.
  2. The bundle error is vague. The shared ValidateMermaidBundle message says "needs the svg output" for png and macro alike. It names no flag, and for macro it doesn't say why (the source is already published verbatim).
  3. README. Line ~1662 still says "Unlike Mermaid and D2 which are rendered locally"; with macro, Mermaid is drawn by Confluence.
  4. ac:plantuml stays, with a test. Includes and macros can call stdlib templates by name, so keeping it is reasonable. A small test comparing ac:plantuml with ac:plain-text-macro for Name=plantuml would stop the two bodies drifting.
  5. Plugin check (point 4). The golden fixtures are good, but nobody has run the plugin. Could someone with org.anvard.atlassian.mermaid-plugin confirm that a plain-text body with no parameters renders?
  6. FYI, no change needed. The macro branch ignores a fence title, as plantuml does. It might be worth a line in the docs.

@arturskavarada

Copy link
Copy Markdown
Author

@flojon all of it is in, current master is merged, and the plugin check is
done.

Please change

  1. A macro run now validates only what it uses. --mermaid-scale and
    --mermaid-engine are skipped in checkPublishFlags when the output is
    macro, and the MermaidScale check in prepare() is skipped too, so a
    negative MARK_MERMAID_SCALE or an engine mark does not know no longer
    aborts a run that draws nothing. Both still warn.

  2. An emptied --mermaid-macro-name is refused only with
    --mermaid-output=macro. Beside an image output it is the "has no effect"
    case, which warns rather than refuses.

Smaller

  1. checkPublishFlags calls ValidateMermaidOutput as well; the
    png/svg/macro switch is gone from both sides.

  2. The bundle error is wrapped per caller, with a reason: --mermaid-bundle needs --mermaid-output=svg: a PNG has nowhere to keep the diagram's source, or ...: the macro publishes the diagram's source itself.

  3. docs/formatting.md, where the rendering reference moved, says "rendered
    locally by default" and points at --mermaid-output=macro for Mermaid.

  4. TestPlantumlTemplateMatchesPlainTextMacro compares ac:plantuml with
    ac:plain-text-macro for Name=plantuml, so the two bodies cannot drift.

  5. Checked against a Confluence running
    org.anvard.atlassian.mermaid-plugin. A page written with mark's output --
    ac:plain-text-body, no parameters -- renders as the plugin's own block:

    <div class="mermaid conf-macro output-block" data-hasbody="true"
         data-macro-name="mermaid-macro"> ... </div>
    

    No "Unknown macro", no error, and the diagram draws in the browser. So the
    body shape is the one the plugin expects.

  6. docs/formatting.md says the fence's title is not used by the macro.

Current master was merged in (the CLI moved to commands, the docs to
docs/); the pasted --help block was regenerated from the binary.
go build, go vet and go test ./... pass; the four attachment symlink
tests need the Windows symlink privilege here and pass with it.

@flojon

flojon commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Re-checked at 84425bd. Everything from my last comment is addressed (macro runs validate only what they use, the empty name is refused only with macro, ValidateMermaidOutput is shared, the bundle error says why, docs and the ac:plantuml test are in). Thanks for checking the plugin. I found no blocking issues; a few small things remain.

Worth changing

  1. Macro name is not trimmed or validated beyond non-empty (util/flags.go ~802, renderer/fencedcodeblock.go ~419). MARK_MERMAID_MACRO_NAME=" " or "mermaid-macro " (a stray space from an env file or TOML) passes the empty check and is written verbatim into ac:name. Confluence then shows "Unknown macro" and mark exits 0. Trimming the name, or refusing a blank one, would cover it.
  2. Empty name differs between CLI and library. The CLI refuses "", the library falls back to the default inside the renderer. Normalising once in prepare()/markConfig() would put the default in one place.
  3. The macro special case is in three places. The scale loop in checkPublishFlags, the engine block, and prepare() each have their own "macro draws nothing" branch. A single predicate next to ValidateMermaidOutput would keep them in step if another output is added later.
  4. ValidateMermaidOutput / ValidateMermaidBundle are exported from the root package, which is the library API, only so util/ can share them. They could live in an internal package or types/.

Tests and docs
5. testdata/mermaid-macro.html (and -droph1.html) hold the feature-off output, with ac:name="code"; the real macro output is mermaid-macro-macro.html. A name like mermaid-macro-nofeature.html (as plantuml-nofeature.html) would be less confusing. There is no drop-h1 variant for the macro output.
6. No test pins a ]]> in the diagram body, or a fence with a title, under macro. The first is the cdata guarantee; the second is the documented behaviour.
7. docs/formatting.md: --mermaid-macro-name is described twice, and "the mermaid feature must also be enabled" reads like a new requirement although it is on by default.
8. Some new comments (util/cli.go ~640, util/flags.go ~867 and ~885, mark.go ~146) are multi-sentence accounts of why a refusal became a warning. The repo style is one line for the non-obvious why.

Minor: with the mermaid feature off, the "macro needs the feature" warning comes from prepare(), so a library caller using ProcessFile gets it once per call.

@arturskavarada

Copy link
Copy Markdown
Author

@flojon all eight points are in, on top of current master (the processFile
split), plus a pass over the tests and the docs.

Worth changing

  1. The macro name is trimmed by types.MermaidMacroNameOrDefault, and a blank
    name -- empty or only space -- is refused where it would be written into
    ac:name: in the flag, in the config file and in the environment. Tests
    cover all three sources, plus the library path; an unset value still means
    the default.
  2. The default lives in one place, types.MermaidMacroNameOrDefault:
    markConfig() applies it for the published Config, and CompileMarkdown /
    CompileMarkdownLegacy apply it once for every caller of the MarkConfig API.
    The renderer now uses the field as it is given. The CLI still refuses an
    explicitly emptied value, which is the one thing it can tell apart from an
    unset one -- and that is what the usage and the docs now say.
  3. types.MermaidDraws is the single predicate: the scale loop, the engine
    block, prepare() and the renderer all ask it instead of comparing the
    output themselves.
  4. ValidateMermaidOutput, ValidateMermaidBundle, MermaidDraws and
    MermaidMacroNameOrDefault moved to types/; the root package no longer
    exports them for util/'s sake.

Tests and docs
5. mermaid-macro.html now holds the macro output, -droph1 the macro with
--drop-h1, -nofeature the code block, and -nofeature-droph1 the code
block with --drop-h1 (the combination the old -droph1 covered); one table
drives all four.
6. A ]]> in the body and a fence title are pinned. The drawing-settings
test now turns the mermaid feature on, so it really exercises the scale
guard; the CLI test passes an invalid engine and scale and asserts the
published macro; a ProcessFile test checks the trimmed and default name in
ac:name, and markConfig has its own normalisation test; the env and TOML
sources and the "has no effect" / "needs the feature" warnings have tests;
the bundle messages and the accepted output formats are asserted.
7. docs/formatting.md no longer describes --mermaid-macro-name twice, says
the mermaid feature is on by default, documents the name rules
(surrounding space ignored, blank refused, anything else as written) and
notes that mark export keeps the macro as storage.
8. The multi-sentence comments are one line each.

The invalid --mermaid-output error names the flag again, and the pasted
--help block was regenerated.

go build, go vet and go test ./... pass; the four attachment symlink
tests need the Windows symlink privilege here.

The "macro needs the feature" warning is emitted once per operation: once for a
Run, and once for each ProcessFile call, which is a separate publish. A
process-wide dedupe would hide it from a later, differently-configured call,
so it stays per operation.

@flojon

flojon commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Review of 837d053, the commits since my last comment. These were checked by reading the code at that head; I did not build or run it, and I did not go through the test files and golden fixtures.

The escaping holds: the macro name goes through xmlesc and the body through cdata. Macro output creates no attachment, so the checksum rules don't apply.

  1. The macro-name default is applied outside the renderer. renderer/fencedcodeblock.go:294 writes MermaidMacroName as given. The default is applied in markdown/markdown.go:512 and :556 and again in mark.go:2005. The renderer is only built inside markdown/markdown.go (lines 64 and 654), so mark's own paths are safe; someone driving the exported extension types directly gets ac:name="". Low impact.
  2. An empty mermaid-macro-name is treated differently by the CLI and the library. The CLI, config file and env var reject an empty or blank name with macro output (util/cli_test.go:253, :259, :366, :379). Config.prepare (mark.go:197-203) only rejects a non-empty blank name, and MermaidMacroNameOrDefault turns "" into the default (types/mermaid.go:46). Probably a design choice, but worth stating.
  3. The "macro output needs the mermaid feature" warning repeats. It is at mark.go:204, inside prepare(), which is called once from Run (mark.go:289) and again from processOneFile (mark.go:758), so it logs N+1 times for N files.
  4. Unrelated comment deletions. The PR removes the rationale comments in prepare() and the CLI bundle-check comment. Nothing in the macro feature needs that, and the comments explain why both the CLI and Config validate.

@flojon

flojon commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Follow-up on my comment above, against c1e3e9d, which landed after I wrote it.

  • Point 1 (default applied outside the renderer): addressed. NewConfluenceFencedCodeBlockRenderer now normalises the name and the compile entries no longer do. TestFencedCodeBlockNormalisesTheMacroName passes.
  • Point 3 (warning repeats): withdrawn. I read prepare() being called from Run and from processOneFile and concluded the warning logs N+1 times. The new TestMermaidMacroFeatureWarningIsOncePerRun shows one warning for two files, and it passes at this head. As the commit message says, Run's per-file loop goes through processFile, not ProcessFile.
  • Point 4 (deleted rationale comments): addressed. They are restored.
  • Point 2 (an empty mermaid-macro-name is rejected by the CLI, config file and env var, but the library takes "" as the default): unchanged. It reads as a design choice, so I'd only keep it as a note.

@arturskavarada

Copy link
Copy Markdown
Author

@flojon thanks for the re-check.

On 2: deliberate, and stated in the flag usage, docs/formatting.md and the
Config field comment. The CLI can tell an explicitly emptied value (IsSet)
from an unset one and refuses it with macro output; a Config cannot, so its
zero value means the default, and only a name that is only space is refused
there. A note is the right place for it.

go build, go vet and go test ./... pass; the four attachment symlink
tests need the Windows symlink privilege here.

The PR is up to date with master and clean to merge.

@arturskavarada

Copy link
Copy Markdown
Author

@flojon @mrueg gentle ping -- the PR is up to date with master, all five CI
checks are green, and the points from the last review are addressed. Ready for
a final look.

@arturskavarada
arturskavarada force-pushed the master branch 2 times, most recently from de815b3 to d0ff8bc Compare November 5, 2026 14:49
@arturskavarada

Copy link
Copy Markdown
Author

@flojon @mrueg v17.0.0 is out, so I've ported the branch to it. The PR is now
a single commit on eacff19; the v16 history is kept at the
v16-mermaid-port tag on my fork, and the old review comments still describe
the same behaviour.

What changed is where the feature plugs in, not what it does:

  • MermaidOutput is its own type, mermaid.Output (png, svg, macro), rather
    than imageformat.Format. d2 and math keep imageformat, so
    --d2-output=macro cannot become a thing; the mermaid flag has its own
    parser and error.
  • MermaidMacroName is in markdown.Options and RenderingConfig; the
    renderer normalises it where the DiagramConfig is consumed, so the exported
    extensions and a direct renderer get the default too.
  • A macro run does not start an engine and creates no attachment:
    --mermaid-engine and --mermaid-scale are unused (warned),
    --mermaid-bundle is refused with "the macro publishes the diagram's source
    itself", and a blank name is refused where the macro would use it.
  • plantuml now goes through the shared ac:plain-text-macro; ac:plantuml
    is kept for macro templates that call it by name.
  • The golden fixtures (mermaid-macro, -droph1, -nofeature,
    -nofeature-droph1), the ]]> and title tests, the name tests and the
    CLI/env/TOML/warning tests are ported.

go build, go vet and go test ./... pass. One export test
(TestOKFIndexHeadingKeepsTrailingHashes) fails on Windows because it looks a
map up with filepath.Join while the keys are slash-separated; it passes on
Linux and is unrelated to this change.

CI needs its workflows approved again for the new head.

@flojon

flojon commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Thanks @arturskavarada, and thanks for your patience through all the review rounds. Everything has been addressed, the plugin check is done, and the port to v17 looks clean from where I sit.

I'm only an outside reader here, so the call is @mrueg's. @mrueg, whenever you have a moment, could you say whether this is something you'd like in core? Even a short "not for now" would help Artur know where it stands.

Ported to v17: MermaidOutput is its own type (png, svg or macro) rather than an
imageformat.Format shared with d2 and math, because the macro is not an image;
MermaidMacroName lives in markdown.Options and RenderingConfig, and the
renderer normalises it where the DiagramConfig is consumed.

The macro publishes the fence's source as a plain-text macro, adds no
attachment, and makes --mermaid-engine/--mermaid-scale unused and
--mermaid-bundle contradictory; those are refused or warned about in validate
and the CLI, and no engine is created for a macro run.

Golden fixtures, the ]]> and title tests, the name tests and the CLI/env/TOML
tests are ported; the README help block and docs/formatting.md describe the
output.
@arturskavarada

arturskavarada commented Nov 26, 2026 •

Copy link
Copy Markdown
Author

@mrueg gentle nudge - the feature is ported to v17, flojon has signed off, and
all review points are closed. Is this something you'd want in core? A "not for
now" is a fine answer; I'd just like to know whether to keep it rebased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants