dvDocsLinkSpan function

DVDocsLinkSpan dvDocsLinkSpan(
  1. DVDocsDocument document
)

How a link in a block is drawn here.

A page of this document routes, with its anchor when it carries one. A page it does not have is its own text: a link to nowhere is not a link, and a site that answered "not found" where a reader followed a decision record's reference has failed at the one job it has. An address that leaves the site is opened through the app's own way out, so a kiosk policy and a host application's handler both still see it.

Implementation

DVDocsLinkSpan dvDocsLinkSpan(DVDocsDocument document) {
  return (BuildContext context, String text, DVDocsTarget target) {
    final DVDocsStyle docs = DVDocsStyle.of(context);
    final String? href = target.href;
    if (href != null) {
      if (href.startsWith('http://') || href.startsWith('https://')) {
        return WidgetSpan(
          child: DVNavLink.external(
            href,
            semanticLabel: text,
            padding: const .symmetric(vertical: 2),
            child: Text(text, style: docs.link),
          ),
        );
      }
      // A path on this site. The document mounts inside the application it
      // documents, so its own paths are the application's.
      return WidgetSpan(
        child: _route(DVRouteTarget(href), text, docs.link),
      );
    }
    final DVDocsPage? page = document.page(target.page ?? '');
    if (page == null) return null;
    final String? anchor = target.anchor;
    return WidgetSpan(
      child: _route(
        DVRouteTarget(
          anchor == null || anchor.isEmpty ? page.path : '${page.path}#$anchor',
        ),
        text,
        docs.link,
      ),
    );
  };
}