code: def _sec_to_chap(lines):
      for i, l in enumerate(lines):
          # e.g., {Section \ref{\detokenize{chapter_dlc/index:chap-dlc}}} matches
          # {Section \ref{\detokenize{chapter_prelim/nd:sec-nd}}} does not match
          # Note that there can be multiple {Section } in one line
  
          longest_balanced_braces = regex.findall(
              "\{(?>[^{}]|(?R))*\}", l
          )
          for src in longest_balanced_braces:
              if src.startswith("{Section \\ref") and "index:" in src:
                  tgt = src.replace("Section \\ref", "Chapter \\ref")
                  lines[i] = lines[i].replace(src, tgt)
  
file_path: d2l-en/static/post_latex/main.py
imports: import os
  import re
  import regex
  import sys
label_desc: Use image node_id 2 for calling a global function with example usage: _sec_to_chap(lines) without return types