Ok, it’s a bit clunky, but it seems to work. If you are up to do it in a script that accepts the two parameters of input.md and output.md or whatever you need, you know, go ahead and share
awk '{ gsub("#","\t", $1); print }' input.md| awk NF | sed 's/^[ ]*//'| sed 's/ / - /' > output.md