Hacker News new | ask | show | jobs
by programbreeding 2017 days ago
Just curious: What is the benefit/reason for the readfile shortcode for displaying code snippets as opposed to just pasting the code in and using the typical syntax highlighting?

I suppose if the actual source file changes then the page would be updated as well which is neat, but if you're specifying certain lines to read from then that could easily become a problem.

Considering how few shortcodes you're using I just felt like there must be a good reason to use it in this way and I was curious why.

1 comments

The readfile shortcode was added because this sort of code inclusion was used previously and when converting the documentation I needed something with similar semantic. Another advantage is that it allows me to have a compilable code examples that can be easily downloaded using gitlab support for creating zip from directories[0].

More interesting are the doxysnippet shortcode[1] that provides the extraction from the source code or the custom rendering of links[2] that allows this sort of markdown links: [Overlay](docs:kirigami2;OverlayDrawer)

[0]: https://invent.kde.org/documentation/develop-kde-org/-/archi...

[1]: https://invent.kde.org/documentation/develop-kde-org/-/blob/...

[2]: https://invent.kde.org/documentation/develop-kde-org/-/blob/...