Don't auto-link to headers ending with "#"

For markdown it's the same to write

or

which allows us to differentiate between the two notiations when
generating the list of keywords relevant for the auto-linking.

Include some refactoring of the addLinkToMap function.
Accept headers with trailing hashes in current context.