More languages should treat code in docs as actual runnable code/tests. E.g. elixir has doctests: https://hexdocs.pm/elixir/docs-tests-and-with.html
Still parts of the docs have to be handmade, and those are usually not supported directly by the ecosystem, so you have to build your own solutions.