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

Handle more heading levels #3060

Merged
merged 1 commit into from
Sep 12, 2024
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
14 changes: 9 additions & 5 deletions resources/web/docs_js/index-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,29 @@ export function init_headers(sticky_content, lang_strings) {
this.href = '#' + this.id;

// Extract on-this-page headers, without embedded links
var title_container = $(this).parent('h1,h2,h3,h4').clone();
var title_container = $(this).parent('h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12').clone();
if (title_container.length > 0) {
// Assume initial heading is an H1, but adjust if it's not
let hLevel = 0;
let hLevel;
if ($(this).parent().is("h2")){
hLevel = 0;
} else if ($(this).parent().is("h3")){
hLevel = 1;
} else if ($(this).parent().is("h4")){
hLevel = 2;
} else if ($(this).parent().is("h5,h6,h7,h8,h9,h10,h11,h12")) {
hLevel = null
}

// Build list items for all headings except the page title
if (0 < items++) {
title_container.find('a,.added,.coming,.deprecated,.experimental')
.remove();
var text = title_container.html();
const li = '<li id="otp-text-' + i + '" class="heading-level-' + hLevel + '"><a href="#' + this.id + '">' + text + '</a></li>';
ul.append(li);
if (hLevel !== null) {
const li = '<li id="otp-text-' + i + '" class="heading-level-' + hLevel + '"><a href="#' + this.id + '">' + text + '</a></li>';
ul.append(li);
}
}
}
});
Expand Down Expand Up @@ -342,7 +346,7 @@ $(function() {
AlternativeSwitcher(store());

// Get all headings inside the main body of the doc
const allHeadings = $('div#content').find('h1,h2,h3,h4,h5,h6,h7')
const allHeadings = $('div#content').find('h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12')
let allLevels = []
// Create a list of all heading levels used on the page
allHeadings.each(function(index) {
Expand Down
7 changes: 5 additions & 2 deletions resources/web/style/heading.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@
margin: 16px 0 5px;
}

/** I _think_ h7 is not technically valid HTML tag, but in the event that the nesting is deep enough we can at least bold the text */
h7 {
/**
Headings beyond h6 are not technically valid HTML tags,
but in the event that the nesting is deep enough we can at least bold the text.
**/
h7, h8, h9, h10, h11, h12 {
font-weight: 600;
}

Expand Down