section method

List<DVDocsBlock>? section(
  1. String anchor
)

The blocks from the block anchored anchor to the next heading of the same or a higher level, or null when nothing carries that anchor.

What a decision record's `field:User.email` link points at: the field's own row, and the rest of the model it sits in, so a reader who follows one lands on the field rather than at the top of the page.

Implementation

List<DVDocsBlock>? section(String anchor) {
  final int start = blocks.indexWhere((DVDocsBlock b) => b.anchor == anchor);
  if (start == -1) return null;
  final int level =
      blocks[start] is DVDocsHeading
          ? (blocks[start] as DVDocsHeading).level
          : 2;
  final int end = blocks.indexWhere(
    (DVDocsBlock b) => b is DVDocsHeading && b.level <= level,
    start + 1,
  );
  return blocks.sublist(start, end == -1 ? blocks.length : end);
}