Hide lines starting with a customizable symbol

Hello!

While working on the bevy book, we write a lot of code blocks. We also want to validate those code blocks which means we need to add code to make it a valid block, but we don’t want to show that code to our readers.

I am aware of the hide_lines annotation, but it’s easy to forget to change it when editing the code block since it requires specifying line numbers.

I would like to suggest a different approach to do this.

Option1

In doc comments in rust it’s possible to add a # symbol at the start of a line to hide that line. Obviously this won’t work with every language supported by zola. My suggestion would be to make this symbol configurable and also make this feature toggleable. This would make it possible for rust code block to hide lines easily without breaking other languages.

Ideally this would be a global config so we don’t need to configure it on every block, but even if it’s a special annotation it will at least mean we can just add it everywhere and not have to remember to update it.

Option 2

Look for a comment that indicates a start and an end. Something like

<insert code that need to be hidden>
// ZOLA_BEGIN_CODE_BLOCK
<insert code that needs to be visible>
// ZOLA_END_CODE_BLOCK

and use those tags to hide the lines that are not between these.

If there’s an interest for that feature, I would be interested in implementing that feature, but I have no idea where to start and would need a bit of guidance. (@mockersf is the one that implemented the original hide_lines annotation and would also be willing to implement this if it gets approved.)

2 Likes

Hello!

Honestly I’m really not keen on those solutions. I don’t want to check every line of codeblocks for some magic strings and some custom embedded DSL (because if we add that for hiding lines, it makes sense to add it for other needs). Specifying lines is not ideal when things change I agree but having one place to control all the codeblock behaviour is better for the consistency.