class_docstr: Search index is a collection of pages and sections (heading
  tags and their following content are sections).
docstr: Given a table of contents and HTML ID, iterate through
  and return the matched item in the TOC.
docstr_tok: ["Given","a","table","of","contents","and","HTML","ID",",","iterate","through","and","return","the","matched","item","in","the","TOC","."]
code: def _find_toc_by_id(self, toc, id_: str | None) -> AnchorLink | None:
      """
      Given a table of contents and HTML ID, iterate through
      and return the matched item in the TOC.
      """
      for toc_item in toc:
          if toc_item.id == id_:
              return toc_item
          toc_item_r = self._find_toc_by_id(toc_item.children, id_)
          if toc_item_r is not None:
              return toc_item_r
      return None
  
imports: from __future__ import annotations
  import json
  import logging
  import os
  import re
  import subprocess
  from html.parser import HTMLParser
  from typing import TYPE_CHECKING
label_desc: Use image node_id 2 for calling the SearchIndex obj's underlying member method code with example usage: obj._find_toc_by_id(toc, id_) and returns: None, toc_item, toc_item_r