markdownLinkOpen top-level constant

String const markdownLinkOpen

Matches only the opening of a markdown link: the [text] label followed by optional whitespace and the ( that begins the destination.

The destination itself is intentionally not captured here. The previous single-regex form \[([^\[\]]*)\]\((.*?)\) was fragile in two ways:

  • the non-greedy (.*?) stopped at the first ), so URLs containing balanced parentheses (e.g. /Primer_(film)) were truncated, and
  • the captured group swallowed any whitespace padding inside the parentheses (( url )), which then desynced the length-based end index and left )/spaces behind in format() output.

Instead we match just the opener and let MarkdownLinksExtractor scan the destination structurally (leading/trailing whitespace, optional <...> wrapping, balanced parens, and the true closing )). The \s* between ] and ( also tolerates a gap such as [text] (url); a false match is prevented downstream because the destination must still parse as a valid URL.

Implementation

const markdownLinkOpen = r'\[([^\[\]]*)\]\s*\(';