Skip to content

Improve collapsible code sections and formatting on book.kubebuilder.io #4862

@danielskowronski

Description

@danielskowronski

I'd like to report a few issues with collapsible codeblock sections in book.kubebuilder.io that have the potential to confuse readers, especially new users.

  1. Hidden instructional text: initially collapsed sections that appear to only contain code, actually contain instructions as well (https://book.kubebuilder.io/cronjob-tutorial/webhook-implementation - "Validate object name")
  2. Misleading headers in code blocks: collapsible codeblocks have headers formatted as Golang comments and use font only slightly larger than the body of codeblock, which suggests that they are actual comments in code
  3. Insufficient separation between blocks: consecutive code blocks (collapsed by default or not collapsible) appear as single code block, which makes it difficult to follow (https://book.kubebuilder.io/cronjob-tutorial/controller-implementation - especially "5: Get the next scheduled run")
  4. Lack of highlighting for expanded sections: there's no visual indication of the section that was expanded, which is more problematic on very long pages
  5. Verbose license notices: having "Apache License" block does not contribute to the guide (but it's understandably part of the source file) and may confuse users because licence text is shown as instruction text, not codeblock
  6. Overly long lines and narrow layout: HTML template makes a hard limit on text (and codeblock) width, but there's no limit to line length in code; I could easily find a line with 390 characters, but it seems like only 89 characters fit into codeblock without horizontal scrolling
  7. Lack of proper formatting of shell commands:
    1. none of shell commands use syntax highlighting
    2. some commands are presented as very long lines, making them hard to copy
    3. some commands are formatted like Golang comments (// )
  8. Internal headers missing from TOC: if headers are originating from Golang comments, they are not included in TOC and are hard to distinguish from the main body; https://book.kubebuilder.io/cronjob-tutorial/controller-implementation
  9. Code of function split into sections is unclear: when function body is split into multiple parts, it's not clear that the body continues

Many of those issues stack and increase cognitive load even more. They are present since v2, but v1 has significantly different contents to compare. I was able to figure out how to read the book only after spending an hour preparing this bug report.

I'd like to offer some improvement suggestions, but I'm not sure whether problems originate from comments in Golang code, tooling used (litgo.sh, mdBook) or HTML templates.

  • consider disabling collapsible sections (quickest workaround, but it's already a book)
  • clearly highlight codeblock boundaries - add borders and padding on bottom
  • change style of codeblock title - invert colours, drop //
  • format Golang code (of examples in book) for web readability (e.g. force 80 columns limit)
  • add copy button to codeblocks in HTML
  • highlight contents of collapsible sections - add borders, slightly different background or consider very subtle animation; additionally add extra padding on the bottom
  • format Golang code with rendering inside HTML in mind - prefix separate chunks of functions with a comment containing "continuation of ..." or just function signature
  • ensure that only codeblock collapses and that licence headers are skipped

As a test case, I propose giving this book to someone who's new to kubebuilder and internal k8s APIs it and verify if it's obvious to read.

I think that lowering the barrier to entry will attract new users and contributors :)

If you agree with my observations and those issues are caused mainly by the HTML template used, I can offer a contribution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions