Skip to content

Code block enhancements: filename titles and line highlighting #6

@engineervix

Description

@engineervix

Summary

Two related improvements to fenced code blocks that authors commonly expect from modern doc tools:

  1. Filename/title annotation```go title="main.go" renders a filename label above the block
  2. Line highlighting```go {3,5-8} highlights specific lines to draw attention

Proposed behaviour

Filename title

```go title="cmd/root.go"
package main
```

Renders a label bar above the code block showing the filename.

Line highlighting

```go {2,4-6}
line 1
line 2  ← highlighted
line 3
line 4  ← highlighted
line 5  ← highlighted
line 6  ← highlighted
```

Implementation notes

  • Both are implemented as a custom goldmark code block renderer (extending the existing Chroma integration in internal/parser/highlight.go)
  • Parse extra attributes from the opening fence info string
  • Title: inject a <div class="code-title"> before the <pre> block
  • Line highlighting: wrap highlighted lines in <span class="highlight-line">, style with CSS
  • No new dependencies needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    contentContent authoring featuresenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions