Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core/title): handle line break in title #3807

Merged
merged 3 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
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
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