Try this https://github.com/cqroot/joplin-outline. A toc sidebar plugin for joplin.
Modify from https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/toc/
Fixed the problem that #
in the code block would be abnormally matched and simply adjusted the style.