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

Rework section title css classes #2773

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
24 changes: 21 additions & 3 deletions src/core/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
// - lang: can change the generated text (supported: en, fr)
// - maxTocLevel: only generate a TOC so many levels deep

import { addId, getIntlData, parents, renameElement } from "./utils.js";
import {
addId,
getIntlData,
parents,
renameElement,
wrapInner,
} from "./utils.js";
import { hyperHTML } from "./import-maps.js";

const lowerHeaderTags = ["h2", "h3", "h4", "h5", "h6"];
Expand All @@ -22,6 +28,9 @@ export const name = "core/structure";
const localizationStrings = {
en: {
toc: "Table of Contents",
section: "Section ",
chapter: "Chapter ",
appendix: "Appendix ",
},
zh: {
toc: "内容大纲",
Expand Down Expand Up @@ -84,10 +93,19 @@ function scanSections(sections, maxTocLevel, { prefix = "" } = {}) {
// paginate the output
section.header.before(document.createComment("OddPage"));
}

const secthdr =
level === 1
? appendixMode
? l10n.appendix
: l10n.chapter
: l10n.section;
wrapInner(section.header, hyperHTML`<span class='sect-title'>`);
if (!section.isIntro) {
index += 1;
section.header.prepend(hyperHTML`<bdi class='secno'>${secno} </bdi>`);
section.header.prepend(
hyperHTML`<span class='secthdr' hidden>${secthdr} </span>`,
hyperHTML`<bdi class='secno'>${secno} </bdi>`
);
}

if (level <= maxTocLevel) {
Expand Down