This is a [link to an existing confluence page](ac:Pagetitle)
And this is how to link when the linktext is the same as the [Pagetitle](ac:)
Link to a [page title containing spaces](<ac:With Multiple Words>)A relative link to another Markdown file is replaced with a link to the Confluence page that file publishes:
See [the other page](./other.md) and [a heading in it](./other.md#setup).The target file is read to find its Space and Title, and the page is looked
up by those. The title is the one publishing the file gives it, so with
--parents-from-path a link to a directory's README.md finds the page titled
after the directory, and a --title-append-generated-hash title is hashed over
the parents the path gives. That holds for a file the run publishes; one it
does not is read by its own headers. Links are rewritten to Confluence tiny
links
(/x/AbCdEf), which survive page renames and moves.
The path is read the way an image's is: other%20page.md and
<other page.md> both name other page.md, and other\_page.md and
a&b.md name other_page.md and a&b.md. The name as written is tried
first, so a file whose name really contains a % still resolves to itself.
A link is left exactly as written when it has a scheme (https:, mailto:),
is a bare #fragment, points at a directory or a non-text file, or names a
file that has no mark metadata and so is never published.
So is a link to a file whose extension is not a Markdown one (.sh, .py,
.txt), unless that file is published as a page. A file published through
--files "docs/**/*.rst", say, is a page, titled as any document is, whether
from its headers, its heading under --title-from-h1 or its name under
--title-from-filename. A file the run does not publish is a page only when
it sets its own Title and has a Space, its own or the one given by
--space; a title taken from the filename or heading does not count there.
Only the first 64 KiB of such a file is read to tell, so its headers have to
come first, and one that cannot be read is left as written like a script. A link to a file
that is a page is looked up like any other. With --attach-referenced it is
not attached once the page exists, or while the run that publishes the file
has yet to create it; a script or data file is attached, and so is a file with
such headers that the run does not publish and that has no page. A file with
no extension at all is read like a Markdown one, so LICENSE and Makefile
are looked up when titles come from file names. Links are resolved on
the parsed document, so a link that appears inside a code span or a fenced or
indented code block is left alone -- a page documenting Markdown gets to show
its examples unchanged. Files pulled in with Include are resolved along with
the document that includes them.
A link is resolved by finding the page it points at, so a document linking to another that the same run is creating has nothing to find yet.
Mark notes those documents and publishes them again once everything exists, so links resolve within a single run. Only the documents that were waiting are published a second time, and only on the run that creates their targets: once the pages are there, later runs find them the first time and nothing is published twice.
Nothing is published again on --dry-run or --compile-only, where no page is
being created for a link to wait for.
By default a link that cannot be resolved is left exactly as written, which in
Confluence means a link that leads nowhere. --check-links makes that a failure
instead:
mark publish --check-links internal,confluence --files "docs/**/*.md"ERR unable to compile markdown: link "./architecure.md" does not resolve:
there is no such file
It reports in every mode, including --compile-only and --dry-run, so a pull
request gate can check links without publishing anything:
mark publish --compile-only --check-links all --files "docs/**/*.md"A link to a file that exists but is not a page -- a script, a PDF, an image, a
text file with no headers -- is not reported, whether or not it can be read:
it is no document, so there is no page to look for. It is left as written,
which on the page is a relative address that leads nowhere unless
--attach-referenced attaches the file. A link to one that does not exist is
reported. A file named as a Markdown one, or with no extension, is read as a
document, and is reported when it is not text or has no title.
Some of the answers come from Confluence. A relative link to a document is
rewritten to that document's page, which is looked up, and a confluence link
is a lookup too. A --compile-only run given neither --url nor --base-url
has no Confluence to ask: a relative link to a document is checked against the
files and left as written, and an ac: link fails the confluence check, as
there is nothing to look it up in. Given a Confluence, a compile looks both up,
so that what it prints is what a real run would publish. In a Go program this
is ModeConfig.Offline.
A page the run itself would publish is never created by a dry run or a
compile, so an ac: link to it, or to a parent a real run would create for
it, counts as found rather than being looked for.
| Value | Checks |
|---|---|
internal |
relative links to other Markdown files in the repository |
confluence |
ac: links, which name a Confluence page by title |
external |
requests each URL with a scheme to see whether it answers |
all |
all three |
The values are a set, not a mode: repeat the flag or separate them with commas,
and pick whichever combination suits. The three cost very different things --
internal is answered from the filesystem, confluence costs a lookup per link,
and external leaves the building -- so internal,confluence in CI with no
network checking is a perfectly reasonable choice, and the one above.
An internal link fails the run when the file it names is missing, is a
directory, or is a document that never becomes a page -- one with no title, so
there is nothing for the link to point at.
A link is looked for beside the document that contains it, and then beside each file that document includes. A fragment reads as a document in its own right, so a link inside one is written from where the fragment lives rather than from wherever it is pulled into. The document's own directory is always tried first, so this cannot change what an unambiguous link already meant. Only the files a document includes directly are considered, not what those files include in turn.
A link is looked for beside the document mark reads. A build that renders its documents into a staging directory and publishes them from there has its links answered by the staged copies, which are not where the links were written: a link to a file the build did not stage is reported as missing, however present it is in the repository.
--links-staged-root and --links-source-root say which tree the copies came
from. A link that names no file beside the staged document is then looked for at
the same place in the source tree, both when it is checked and when it is
rewritten to the page it names:
mark publish --check-links internal \
--links-staged-root build/docs --links-source-root docs \
--files "build/docs/**/*.md"A file the link would have found without the roots -- beside the staged
document, or beside a fragment it includes -- still comes first, since that copy is the one that publishes, with
whatever headers the build gave it. A link inside an included fragment that was
staged is looked for under the source tree in the same way. The two are given
together, each must be a directory, and a document outside the staged root is
refused before anything is published rather than resolved against wherever it
happens to be. In a Go program they are LinkConfig.StagedRoot and
LinkConfig.SourceRoot. PublishConfig.Validate refuses the link settings
Run would, as a *LinkConfigError naming the field and its flag; which
documents sit under the staged root is only known once they are named, so
Publisher.Publish refuses one outside it on its own.
A file found only in the source tree is read for its page the way a staged one
is, and the source copy is not what publishes: without the headers the build
gives it, a checked link to it fails as never published, an unchecked one is
left as written, and under --title-from-filename or --title-from-h1 it is
taken for whatever page bears the title its name or heading gives. With
--links-source-root-check-only (LinkConfig.SourceRootCheckOnly) the source
tree answers the check alone: a link to a file found only there passes
--check-links internal and is left as written, and a link to a staged file is
rewritten as before. Left as written, the link is a relative path that leads
nowhere in Confluence, so each is a source-only-link warning of its document
in the report.
One case is reported but does not fail: a link to a document that exists and has a title, but is not in the space and is not being published by this run either. A page the run is about to create is waited for rather than complained about -- see below -- so this is left for the genuinely absent.
A confluence link is checked by looking for a page of that title in the
document's own space, which is what an ac: link resolves against. The title is
read the way the renderer reads it: whatever follows the colon, or the link text
when nothing does, so [Some Page](ac:) is checked as Some Page.
These are checked once the run has finished rather than as each document compiles, because a page named this way is often published by another file in the same run. Each page is looked up once however many documents link to it.
external needs network access from wherever Mark runs, and makes publishing
dependent on every site you link to being up. Each URL is requested once per run
however many pages mention it. HEAD is tried first and a refusal is retried
with GET, since plenty of servers reject HEAD while serving the URL
perfectly well.
Bare #fragments, mailto: links and rooted paths are not links Mark resolves,
and are never checked.
Every broken link in a document is reported, not just the first, so a page with several of them takes one run to find out rather than one run each.
--check-links-warn-only reports the same links without failing the run, which
is how to see the list before the build starts failing over it:
mark publish --check-links all --check-links-warn-only --files "docs/**/*.md"Pages still publish exactly as they would have. It is a separate flag from
--continue-on-error, which is about files rather than links and still fails
the run at the end: use --check-links-warn-only to not fail at all, and
--continue-on-error to attempt every file before failing.
With --output-format github each warning is annotated against the file and the
line-less document it came from, so it appears in the pull request rather than
only in the build log:
::notice file=docs/doc.md::published "Doc" to https://confluence.example.com/display/DOCS/1003
::warning file=docs/doc.md::link "guide" does not resolve: it is a directory, not a documentWithout the flag the same link fails the run and is annotated as an ::error
instead.
By default a heading's anchor is derived from its text. To name it yourself, use
the {#custom-id} syntax:
## Release Notes {#rel}
[link to it](#rel)<h2 id="rel">Release Notes</h2>The braces are consumed rather than rendered, so the heading reads as written.
A custom id replaces the derived one rather than adding to it, so the slug of
the heading text no longer resolves -- [link](#release-notes) above would be
left exactly as written. That is what other Markdown tools do too: a custom id
is the id, not an alias.
Mark generates Confluence-compatible heading anchors, which keep their capitals
and punctuation: ## My Heading becomes id="My-Heading". A link written the
way every other Markdown tool expects -- [jump](#my-heading) -- would not name
that anchor, and would quietly go nowhere.
Mark now points such links at the anchor it actually generated, so both spellings work:
## My Heading
[slug style](#my-heading) and [exact style](#My-Heading) both resolve.Matching is on the letters and digits only, because the two conventions disagree
about which punctuation survives: a heading API/v2 Guide becomes
API/v2-Guide, while a slug of it is apiv2-guide. If two headings differ only
in punctuation that matching drops, the link is left exactly as written rather
than guessed at.
Both ends are published in the storage format's own terms rather than as HTML.
Confluence keeps no id on a heading — it generates its own from the element's
text — so a heading a link points at carries the Anchor macro, and the link
becomes <ac:link ac:anchor="…">. That is what footnotes have always used, and
it is the difference between a link that works and one that renders, is
clickable, and does nothing.
Only a heading something links to carries an anchor; the rest are left as they were.
To mark a place no heading names, write an anchor by hand — Confluence keeps
neither the name nor the id, so mark turns it into the same macro a heading
gets:
<a name="details"></a>
...later: [see the details](#details)An anchor on another page is written after the page's title:
[the setup](<ac:Other Page#Setup>)The part after the last # is taken as an anchor only if it has no whitespace
in it, which is true of every anchor mark generates — so a page whose title
contains a #, like <ac:C# Guide>, is still just a title.
A relative link to a section of another document works the same way, and is written the way every other Markdown tool expects:
[the setup](./other.md#setup-guide)The slug is folded onto the id mark gave that heading, exactly as a same-page link is, and the link is published as an anchor on that page rather than as a URL with a fragment — a fragment on a Confluence address names nothing, since Confluence keeps a heading's anchor in the macro rather than in the address.
Two limits, both deliberate. The document has to be published to the same space, because a page named without a space key is looked for in the current one; a link across spaces keeps its URL. And a fragment naming no heading in that document is left exactly as written, since guessing which section was meant would send the reader somewhere the author did not choose.