Trivial bug: a heading X results in a [X] in the TOC section, which will be rendered as a checkbox.
I suggest this edge case be handled specially. For example, [ X] gives the wanted output.
Simply generate the TOC for # X:
<!-- toc -->
- [X](#X)
<!-- tocstop -->
# X
I found another edge case: # []
# X
# [ctrl]
# [link](google.com)
# - a
# * a
# + a

Most helpful comment
I found another edge case:
# []Environment