locatorFromLink method

Locator? locatorFromLink(
  1. Link link, {
  2. MediaType? typeOverride,
})

Creates a Locator pointing at the given link.

Resolves the resource type from the manifest when possible, falling back to typeOverride. Returns null if no type can be determined.

Implementation

Locator? locatorFromLink(final Link link, {final MediaType? typeOverride}) {
  final (href, fragments) = link.href.splitPathAndFragment();
  final resourceLink = linkWithHref(href);
  final type = resourceLink?.type ?? typeOverride?.name;
  final linkIndex = resourceLink == null ? -1 : readingOrder.indexOf(resourceLink);
  return type == null
      ? null
      : Locator(
          href: href,
          type: type,
          title: resourceLink!.title ?? link.title,
          text: LocatorText(),
          locations: Locations(
            cssSelector: fragments != null && fragments.isNotEmpty ? '#$fragments' : null,
            fragments: fragments == null ? [] : [fragments],
            progression: fragments == null ? 0 : null,
            position: linkIndex == -1 ? null : linkIndex + 1,
          ),
        );
}