Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
fix(core/title): handle line break in title (speced#3807)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored Oct 5, 2021
1 parent a25565d commit 5bd6ad6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ function setDocumentTitle(conf, h1Elem) {
if (!h1Elem.isConnected) {
h1Elem.textContent = document.title || `${l10n.default_title}`;
}

let documentTitle = norm(h1Elem.textContent);
// We replace ":<br>" with ":", and "<br>" with "-", as appropriate.
const tempElem = document.createElement("h1");
tempElem.innerHTML = h1Elem.innerHTML
.replace(/:<br>/g, ": ")
.replace(/<br>/g, " - ");
let documentTitle = norm(tempElem.textContent);

if (conf.isPreview && conf.prNumber) {
const prUrl = conf.prUrl || `${conf.github.repoURL}pull/${conf.prNumber}`;
Expand Down
12 changes: 12 additions & 0 deletions tests/spec/w3c/headers-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,18 @@ describe("W3C — Headers", () => {
expect(h1).toBeTruthy();
expect(h1.textContent.trim()).toBe("override!!!");
});

it("handles special case of localized spec title by doing replacement of <br> elements", async () => {
const body = `
<title>hi</title>
<h1 id="title">Requirements for Chinese Text:<br/>Layout<br/><span lang="zh">中文排版需求</span></h1>
${makeDefaultBody()}`;
const ops = makeStandardOps({}, body);
const doc = await makeRSDoc(ops);
expect(doc.title).toBe(
"Requirements for Chinese Text: Layout - 中文排版需求"
);
});
});

describe("precedence rules for h1#title is present and <title> is absent", () => {
Expand Down

0 comments on commit 5bd6ad6

Please sign in to comment.