resolveUrl method

String resolveUrl(
  1. String reference, {
  2. String? branch,
  3. String? relativeFrom,
  4. bool? isEmbeddedObject,
})

Resolves a reference in relationship with the repository, and returns:

  • the same URL if the reference is absolute,
  • the same URL if the reference is in-page anchor,
  • a new URL if the reference is relative and valid

Throws FormatException when the reference is invalid in the scope of the repository.

If branch is specified, it will override the Repository's default branch.

When present, relativeFrom specifies the file that is being rendered, and relative reference will be resolved from that location.

When reference is used inside <img> or similar tag, isEmbeddedObject should be set to true. On compatible providers the resolved URL will use the raw reference to content.

Implementation

String resolveUrl(
  String reference, {
  String? branch,
  String? relativeFrom,
  bool? isEmbeddedObject,
}) {
  final v = tryResolveUrl(
    reference,
    branch: branch,
    relativeFrom: relativeFrom,
    isEmbeddedObject: isEmbeddedObject,
  );
  if (v == null) {
    throw FormatException('Unable to resolve reference: `$reference`.');
  }
  return v;
}