Markdown: Implement GetNestedHierarchy()

Fixes part of #1546
Markdown: Work around some bugs in embedded JSON editors

There are still more bugs that are much harder to work around