Skip to content

Enable line breaks in titles#57

Merged
DanilaFe merged 2 commits intochapel-lang:mainfrom
DanilaFe:enable-title-line-breaks
Feb 24, 2026
Merged

Enable line breaks in titles#57
DanilaFe merged 2 commits intochapel-lang:mainfrom
DanilaFe:enable-title-line-breaks

Conversation

@DanilaFe
Copy link
Contributor

@DanilaFe DanilaFe commented Feb 23, 2026

Closes #54.

This PR enables adding line breaks in post titles. These line breaks occur when the title is rendered on the page itself, as well when the title is rendered in the posts list. See examples below.

My approach has been to add a new title property (richtitle) to the posts' front matter. The reason I did so is because of the surprising number of ways in which titles were used in a non-visual context. This included:

  • alt= properties for img tags (author pages)
  • RSS feed generation
  • Pre-filled content for social media sharing URLs
  • Alphabetical sorting
  • ...more!

<br> is specifically what's needed in post titles for line breaks. This is because "rendering" titles is handled like rendering markdown, where a single \n is insignificant and \n\n indicates a paragraph break, which for titles would imply an invalid <h><p></p><p></p></h> structure. The <br> element is specifically a line-break hint without a "new paragraph" implication. However, including <br> in title tags verbatim (as it is in the new richtitle field) means that anywhere where the string isn't rendered to HTML (sample list above), we must strip the HTML tags instead. But Hugo's stripping replaces <br>s with newlines, which also aren't always appropriate. In the end, applying this change broadly causes a big HTML diff and is dubiously correct. This, combined with the fact that Hugo uses .Title for many things by default (and possibly even more things in the future), made me switch to a separate field in which markup is expected.

This led me to the richtitle field, and a design in which places where newlines in titles can work should explicitly check the richtitle field. To save the boilerplate of "use rich title if present, or regular title if not", I defined the richtitle.html partial.

I glanced the diff and as far as I can tell, nothing besides <br>s-in-titles has changed. An LLM (Claude) shares this opinion, and didn't flag anything concerning.

Reviewed by @benharsh -- thanks!

Results

Before:
Screenshot 2026-02-23 at 8 23 38 AM

After:
Screenshot 2026-02-23 at 8 23 32 AM

I've added newlines to all the posts in the "7 questions" series.

Screenshot 2026-02-23 at 8 24 37 AM

Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
@bradcray
Copy link
Member

The result looks good to me, Daniel, and I appreciate the rationale for the approach taken!

@DanilaFe DanilaFe merged commit 60b99a2 into chapel-lang:main Feb 24, 2026
1 check passed
bradcray added a commit that referenced this pull request Feb 25, 2026
Leveraging Daniel's #57, this uses the new 'richtitle' field to force
linebreaks for more titles.  Some of these are arguably silly /
inconsequential (splitting a line before a preposition rather than
after), but some feel good to me (e.g., the HPCwire interview).

The 10 myths articles are one of the most awkward cases...  I removed
the comma from the rich title because it caused "(Redux)" to start the
second line in the summary view, which felt a bit unfortunate;
however, in the full-article view, it is now on a line of its own
rather than the original line.  I still think I prefer this since the
"part n: " part of the title gets a line of its own, which feels more
important to me.

---
Signed-off-by: Brad Chamberlain <bradcray@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to force linebreaks in titles?

3 participants