Class LinkRewriter

java.lang.Object
ai.redouble.docs.LinkRewriter

public class LinkRewriter extends Object
Rewrites links in a page's markdown before conversion. Two passes. Inter-doc links: every markdown link whose target is a .md file is resolved relative to the source file's directory and looked up in the page manifest; resolvable targets are rewritten to the generated page, preserving any #anchor. A link whose TEXT is itself a path (the markdown idiom [../PACKAGE.md](../PACKAGE.md), right for reading in the tree) gets the resolved page's title as its text - a reader of the site should see the package's name, never a relative path. A target that does not resolve by path falls back to a unique-basename match across the manifest; if that fails too the link is left untouched, and a warning goes to stderr when it names no file at all. External (scheme-qualified) targets are never touched, and neither is a link that starts inside code. File links: a link to a file of the reactor that is not a page - a source file, a plain document, a markdown file the contents do not list - leads to a copy of the file the site ships as text. Javadoc links: backtick-wrapped class names (`Foo`, `Foo<T>`, `@Foo`), member references (`Foo.bar(...)`, `Foo#bar`, `Foo.CONSTANT` - to the class page, since prose never carries the parameter types an exact method anchor needs) and package names (`ai.redouble.nucleo.harness` - to the package summary) that match the index become links into the generated javadoc tree. Backticks are the author's "this is code" signal and the only text these passes touch; prose mentions stay prose.
Since:
0.1 (2026-09-17)
Author:
Andrey Santrosyan
  • Constructor Details

  • Method Details

    • rewriteDocLinks

      public String rewriteDocLinks(String content, Path originalMd)
      A link that starts inside code - a fenced block or an inline code span - is code, shown as written; a link whose text is code ([`Foo`](x.md)) starts in prose and is rewritten.
    • rewriteFileLinks

      public String rewriteFileLinks(String content, Path originalMd)
      A link to a file of the reactor that is not a page - a source file, a plain document like a license, a markdown file the contents do not list - leads to a copy the site ships (ship(Path)), so a reader of the site can open what a reader of the tree can. Runs after rewriteDocLinks(String, Path): a link to a page points at the generated page by then, which is no file of the tree. Images are rewriteImageLinks(String, Path)'s, a link that starts inside code stays as written, and so does a link to no file at all.
    • ship

      public String ship(Path file)
      Has the site carry a copy of a file of the reactor and answers the copy's name: the file's own name with .txt appended, so a browser shows it as text whatever its extension says. The copies sit flat beside the pages, so two different files with one name are refused.
    • shipped

      public Map<String,Path> shipped()
      The files the site ships, by the name each copy carries.
    • rewriteImageLinks

      public String rewriteImageLinks(String content, Path originalMd)
      Images are copied into the site flat, by basename; a reference that reaches its file relative to the markdown source (however many directories up) is rewritten to that basename. A reference to a file that does not exist stays as written and warns.
    • rewriteJavadocLinks

      public String rewriteJavadocLinks(String content)