Little tip when linking to source code in your docs, etc. You can link directly ...

@aral@mastodon.ar.al

Little tip when linking to source code in your docs, etc.

You can link directly to lines using anchors if the web view of your source control system supports it. e.g., for Codeberg:

codeberg.org/small-tech/jsdb/s

However, that’s brittle and will break as you add/remove code above it.

A more robust way is to use text fragments, which are newly available across major browsers¹. e.g.,

codeberg.org/small-tech/jsdb/s

The latter links to the same place and will also break if, say, you remove the method or rename it, but it will survive code changes in the rest of the file.

#dev #tip #git #codeberg #textFragments #URLs #linking #code #sourceControl

¹ caniuse.com/mdn-html_elements_