Fragment Checking
What Are Fragments?
A fragment is the #section part of a URL like page.html#section. It points to a specific element in the target page, one with a matching id or name attribute.
By default, Raclette only checks that the target file or URL exists. Fragment checking goes further and verifies that the anchor target actually exists in the page.
Enable Fragment Checking
Raclette raclette = Raclette.builder()
.includeFragments(true)
.build();
How It Works
When includeFragments is enabled and a URI contains a fragment:
- Raclette checks that the target file exists (as usual)
- It parses the HTML and collects all
idandnameattributes - It checks if the fragment matches any of those attributes
- If no match is found, the check returns an
InvalidFragmenterror
Fragment sets are cached per file, so checking multiple anchors in the same file doesn't re-parse it.
GitHub Compatibility
GitHub prefixes heading anchors with user-content-. Raclette handles this automatically, so a fragment #installation will match both id="installation" and id="user-content-installation".
Directory and File Resolution
Fragment checking works together with fallbackExtensions and indexFiles:
Raclette raclette = Raclette.builder()
.includeFragments(true)
.fallbackExtensions(List.of("html"))
.indexFiles(List.of("index.html"))
.build();
docs/#introresolves todocs/index.htmland checks for#intropage#sectiontriespage.htmlifpagedoesn't exist, then checks#section