Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion components/reference-layout/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ReferenceLayout extends ServerComponent {
<main id="content" class="reference-layout__content">
<div class="reference-layout__header">
${TranslationBanner.render(context)}
<h1>${doc.title}</h1>
<h1>${wbrify(doc.title)}</h1>
${BaselineIndicator.render(context)} ${description}
</div>
<aside class="reference-layout__toc">
Expand All @@ -42,3 +42,17 @@ export class ReferenceLayout extends ServerComponent {
`;
}
}

/**
* Insert <wbr>s to wrap code-like strings in a pretty way
* NB: don't use in client side code because we use lookbehind assertions
* which aren't baseline green (yet)
* @param {string} text
*/
function wbrify(text) {
return text
.split(
/(?=\.)|(?<=[a-z])(?=[A-Z0-9])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[A-Z])(?=[0-9])/,
)
.flatMap((part, i) => (i ? [html`<wbr />`, part] : part));
}