I would like to write in markdown mode for example and then have a sidebar that shows me a table of contents of the buffer I am currently in.
You can get that, more or less, with
M-x speedbar. It displays the files in the current directory, and lets you expand the files to see a table of contents. (For source code, it shows a list of functions.)
However, you need to tell Speedbar to show contents for Markdown files, by customizing
speedbar-supported-extension-expressions and adding the file extension you use for Markdown files.
By default, Speedbar hides files not matching
speedbar-supported-extension-expressions entirely. You can set
t to make it show them in the list, even though it doesn't display an outline for them.