GitHub’s solution to dom clobbering is interesting: User-generated content and DOM clobbering - Brandon Keepers
Also, I posted some thoughts about scoping IDs to particular sections of a page, over in the automatic header IDs topic. Relevant here, I think? I will paste the comment for convenience:
Another issue with automatic IDs is that they may clash with other IDs on the page. Imagine two posts in a forum topic having the same header text. Now, suppose the first post is deleted. The order of the IDs would change and any links to the second post would break. As a solution, the parser could accept an optional namespace parameter that would be added to the start of the ID. The ID of the header “The Philosophy of CommonMark” would become #discourse-topic-115-post-40-the-philosophy-of-commonmark , for example.