normalizeLinkDestination function

String normalizeLinkDestination(
  1. String destination
)

Normalizes a link destination, including the process of HTML characters decoding and percent encoding.

Implementation

// See the description of these examples:
// https://spec.commonmark.org/0.30/#example-501
// https://spec.commonmark.org/0.30/#example-502
String normalizeLinkDestination(String destination) {
  // Decode first, because the destination might have been partly encoded.
  // For example https://spec.commonmark.org/0.30/#example-502.
  // With this function, `foo%20bä` will be parsed in the following steps:
  // 1. foo bä
  // 2. foo bä
  // 3. foo%20b%C3%A4
  try {
    destination = Uri.decodeFull(destination);
  } catch (_) {}
  return Uri.encodeFull(decodeHtmlCharacters(destination));
}