If you want to insert a link to a file at a specific point in a post, Discourse will do that correctly. The only, and minor, problem is that the cursor will be placed at the end of the text, and the viewport may or may not be scrolled down.
Similar to