From 84062306675b0458d5e1b4a23ddf10bf17931f5d Mon Sep 17 00:00:00 2001 From: Brandon Morelli Date: Tue, 18 Jun 2024 13:51:52 -0600 Subject: [PATCH] Revert "Always use h1 for first heading on a page (#3009)" (#3018) This reverts commit d16085bebe5c46534a1242a0f1fd85c984643f4e. --- extra/docs_landing.html | 4 - integtest/spec/single_book_spec.rb | 128 +++++++++ .../asciidoctor/lib/chunker/breadcrumbs.rb | 2 +- .../asciidoctor/lib/chunker/extension.rb | 28 +- .../lib/docbook_compat/convert_document.rb | 36 +-- .../lib/docbook_compat/extension.rb | 27 +- resources/asciidoctor/spec/chunker_spec.rb | 244 +++++++----------- .../asciidoctor/spec/docbook_compat_spec.rb | 88 ++++++- .../spec/elastic_compat_preprocessor_spec.rb | 8 +- resources/web/docs_js/__tests__/docs.test.js | 18 +- resources/web/docs_js/index.js | 63 ++--- resources/web/style/admonishment.pcss | 7 +- resources/web/style/console_widget.pcss | 4 +- resources/web/style/heading.pcss | 22 +- 14 files changed, 366 insertions(+), 313 deletions(-) diff --git a/extra/docs_landing.html b/extra/docs_landing.html index 2a4655b81196a..af1d8079cb448 100644 --- a/extra/docs_landing.html +++ b/extra/docs_landing.html @@ -138,10 +138,6 @@ display: none; } - #left_col { - display: none; - } - #guide .subnavigation { top: 00px; border-bottom: 1px solid var(--color-gray); diff --git a/integtest/spec/single_book_spec.rb b/integtest/spec/single_book_spec.rb index a40f2f4dee365..f5f5cf49a47a4 100644 --- a/integtest/spec/single_book_spec.rb +++ b/integtest/spec/single_book_spec.rb @@ -314,6 +314,134 @@ end end + context 'regarding the xpack tag' do + let(:edit_me) do + <<~HTML.strip + edit + HTML + end + let(:xpack_tag) do + <<~HTML.strip + + HTML + end + let(:rx) { %r{<#{h} class="title">(.+?)} } + let(:title_tag) do + return unless body + + m = rx.match(body) + raise "Can't find title_tag with #{rx} in #{body}" unless m + + m[1] + end + shared_examples 'xpack tag title' do |has_tag| + it 'contains the edit_me link' do + expect(title_tag).to include(edit_me) + end + if has_tag + it 'contains the xpack tag' do + expect(title_tag).to include(xpack_tag) + end + else + it "doesn't contain the xpack tag" do + expect(title_tag).not_to include(xpack_tag) + end + end + end + shared_examples 'part page titles' do |onpart| + page_context 'part.html' do + let(:h) { 'h1' } + let(:id) { 'part' } + include_examples 'xpack tag title', onpart + end + end + shared_examples 'chapter page titles' do |onchapter, onfloater, onsection| + page_context 'chapter.html' do + let(:h) { 'h2' } + context 'the chapter title' do + let(:id) { 'chapter' } + include_examples 'xpack tag title', onchapter + end + context 'the section title' do + let(:id) { 'section' } + include_examples 'xpack tag title', onsection + end + context 'the float title' do + let(:rx) { %r{

(.+?)

} } + include_examples 'xpack tag title', onfloater + end + end + end + + def self.xpack_tag_context(onpart, onchapter, onfloater, onsection, + hide_xpack) + convert_single_before_context do |src| + index = xpack_tag_test_asciidoc onpart, onchapter, onfloater, onsection, + hide_xpack + src.write 'index.asciidoc', index + end + + include_examples 'part page titles', + onpart && !hide_xpack + include_examples 'chapter page titles', onchapter && !hide_xpack, + onfloater && !hide_xpack, onsection && !hide_xpack + end + + def self.xpack_tag_test_asciidoc(onpart, onchapter, onfloater, onsection, + hide_xpack) + <<~ASCIIDOC + = Title + + #{hide_xpack ? ':hide-xpack-tags: true' : ''} + + #{onpart ? '[role="xpack"]' : ''} + [[part]] + = Part + + #{onchapter ? '[role="xpack"]' : ''} + [[chapter]] + == Chapter + + Chapter words. + + [[floater]] + [float] + == #{onfloater ? '[xpack]#Floater#' : 'Floater'} + + Floater words. + + #{onsection ? '[role="xpack"]' : ''} + [[section]] + === Section + + Section words. + ASCIIDOC + end + + context 'when not hiding xpack tags' do + context 'when the xpack role is on a part' do + xpack_tag_context true, false, false, false, false + end + context 'when the xpack role is on a chapter' do + xpack_tag_context false, true, false, false, false + end + context 'when the xpack role is on a floating title' do + xpack_tag_context false, false, true, false, false + end + context 'when the xpack role is on a section' do + xpack_tag_context false, false, false, true, false + end + context 'when the xpack role is on everything' do + xpack_tag_context true, true, true, true, false + end + end + context 'when hiding xpack tags' do + context 'when the xpack role is on everything' do + xpack_tag_context true, true, true, true, true + end + end + end + context 'for README.asciidoc' do convert_single_before_context do |src| root = File.expand_path('../../', __dir__) diff --git a/resources/asciidoctor/lib/chunker/breadcrumbs.rb b/resources/asciidoctor/lib/chunker/breadcrumbs.rb index c2b6ef4a3da2c..edce3e8403cde 100644 --- a/resources/asciidoctor/lib/chunker/breadcrumbs.rb +++ b/resources/asciidoctor/lib/chunker/breadcrumbs.rb @@ -22,7 +22,7 @@ def generate_breadcrumbs(doc, section) update_breadcrumbs_cases(result, chev, doc) - result.join("\n") + Asciidoctor::Block.new doc, :pass, source: result.join("\n") end def update_breadcrumbs_cases(result, chev, doc) diff --git a/resources/asciidoctor/lib/chunker/extension.rb b/resources/asciidoctor/lib/chunker/extension.rb index 5274cbfbe138a..c5a54e8cbf4ea 100644 --- a/resources/asciidoctor/lib/chunker/extension.rb +++ b/resources/asciidoctor/lib/chunker/extension.rb @@ -57,15 +57,6 @@ def convert_section(section) return yield unless section.level <= @chunk_level html = form_section_into_page doc, section, yield - # Replace the breadcrumbs placeholder with - # the generated breadcrumbs - if html =~ %r{} - html.gsub!( - %r{}, - generate_breadcrumbs(doc, section).to_s - ) - # raise("Couldn't add breadcrumbs in #{html}") - end write doc, "#{section.id}.html", html '' end @@ -102,11 +93,12 @@ def form_section_into_page(doc, section, html) # We don't use asciidoctor's "parent" documents here because they don't # seem to buy us much and they are an "internal" detail. subdoc = Asciidoctor::Document.new [], subdoc_opts(doc, section) - add_subdoc_sections doc, subdoc, html + add_subdoc_sections doc, subdoc, section, html subdoc.convert end - def add_subdoc_sections(doc, subdoc, html) + def add_subdoc_sections(doc, subdoc, section, html) + subdoc << generate_breadcrumbs(doc, section) nav = Nav.new subdoc subdoc << nav.header subdoc << Asciidoctor::Block.new(subdoc, :pass, source: html) @@ -129,10 +121,7 @@ def subdoc_opts(doc, section) def subdoc_attrs(doc, section) attrs = doc.attributes.dup maintitle = doc.doctitle partition: true - # Rendered h1 heading - attrs['doctitle'] = subdoc_doctitle section - # Value of `title` in the `head` - attrs['title'] = subdoc_title section, maintitle + attrs['doctitle'] = subdoc_title section, maintitle # Asciidoctor defaults these attribute to empty string if they aren't # specified and setting them to `nil` clears them. Since we want to # preserve the configuration from the parent into the child, we clear @@ -141,20 +130,13 @@ def subdoc_attrs(doc, section) attrs['stylesheet'] = nil unless attrs['stylesheet'] attrs['icons'] = nil unless attrs['icons'] attrs['subdoc'] = true # Mark the subdoc so we don't try and chunk it + attrs['noheader'] = true attrs['title-separator'] = '' attrs['canonical-url'] = section.attributes['canonical-url'] attrs.merge! find_related(section) attrs end - # For the `h1` heading that appears on the rendered page, - # use just the page title - def subdoc_doctitle(section) - strip_tags section.captioned_title.to_s - end - - # For the `title` in the `head`, use the page title followed - # by the site title ("Elastic") def subdoc_title(section, maintitle) strip_tags "#{section.captioned_title} | #{maintitle.main}" end diff --git a/resources/asciidoctor/lib/docbook_compat/convert_document.rb b/resources/asciidoctor/lib/docbook_compat/convert_document.rb index cf39b1189c857..3bcb567fd4468 100644 --- a/resources/asciidoctor/lib/docbook_compat/convert_document.rb +++ b/resources/asciidoctor/lib/docbook_compat/convert_document.rb @@ -25,7 +25,7 @@ def convert_document(doc) def munge_html(doc, html, wants_toc) title = doc.doctitle partition: true munge_html_tag html - munge_head doc.attr('title-extra'), html + munge_head doc.attr('title-extra'), title, html munge_body doc, html munge_title doc, title, html add_toc doc, html if wants_toc @@ -36,28 +36,17 @@ def munge_html_tag(html) raise("Coudn't fix html in #{html}") end - def munge_head(title_extra, html) - if html !~ %r{^([\S\s]+)<\/title>$}m - raise("Couldn't munge <title> in #{html}") - end - - html.gsub!(%r{^<title>([\S\s]+)<\/title>$}m) do - add_content_meta Regexp.last_match[1], title_extra - end + def munge_head(title_extra, title, html) + html.gsub!( + %r{<title>.+?}m, <<~HTML + #{strip_tags title.main}#{title_extra} | Elastic + + HTML + ) || raise("Couldn't munge in #{html}") munge_meta html end - def add_content_meta(match, title_extra) - # If multiple lines, get just the first line - clean_title = match.gsub!(/\n[\S\s]+/, '') || match - clean_title = strip_tags clean_title - <<~HTML - <title>#{clean_title}#{title_extra} | Elastic - - HTML - end - META_VIEWPORT = <<~HTML HTML @@ -72,14 +61,12 @@ def munge_meta(html) end def munge_title(doc, title, html) + return if doc.attr 'noheader' + # Important: we're not replacing the whole header - it still will have a # closing . - # - # We also add a placeholder for the breadcrumbs that will be replaced - # in resources/asciidoctor/lib/chunker/extension.rb header_start = <<~HTML
- #{docbook_style_title doc, title} HTML html.gsub!(%r{ +
HTML end diff --git a/resources/asciidoctor/lib/docbook_compat/extension.rb b/resources/asciidoctor/lib/docbook_compat/extension.rb index 5d310742d84de..c50aecb5230de 100644 --- a/resources/asciidoctor/lib/docbook_compat/extension.rb +++ b/resources/asciidoctor/lib/docbook_compat/extension.rb @@ -77,20 +77,19 @@ def xpack_tag(node) end def hlevel(section) - # If the heading level is less than 2, use 2, - # otherwise use the given heading level. - # - # This ensures: - # - There are no `h0`s, which are not valid HTML elements. - # - There are no `h1`s in the page's main content since - # we only want one `h1` per page, and one is generated - # automatically and added to the page header (outside - # div#content). - if section.level < 2 - 2 - else - section.level - end + # Walk up the ancestry until the ancestor's parent is the document. The + # ancestor that we end up with is the "biggest" section containing this + # section. Except don't walk *all* the way. Because docbook doesn't. + # See that `unless` below? If we were walking it should be `until` but + # docbook *doesn't* walk. It just does this. Why? Ghosts maybe. I dunno. + # But we're trying to emulate docbook. So here we are. + ancestor = section + ancestor = ancestor.parent unless ancestor.parent.context == :document + # If *that* section is level 0 then we have to bump the hlevel of our + # section by one. The argument for this goes: we have to bump the level 0 + # section's hlevel by one anyway because there *isn't* an h0 tag. So we + # have to bump all of its children. + section.level + (ancestor.level.zero? ? 1 : 0) end SECTION_WRAPPER_CLASSES = %w[part chapter].freeze diff --git a/resources/asciidoctor/spec/chunker_spec.rb b/resources/asciidoctor/spec/chunker_spec.rb index b34acedae44d8..1f9bf79c5af1b 100644 --- a/resources/asciidoctor/spec/chunker_spec.rb +++ b/resources/asciidoctor/spec/chunker_spec.rb @@ -197,6 +197,14 @@ def dest_file(file)

Words words.[1]

HTML end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML + end it 'contains a link to the second section' do expect(contents).to include( 'Section 2' @@ -228,6 +236,14 @@ def dest_file(file) it 'contains the contents' do expect(contents).to include '

Words again.

' end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML + end it 'contains a link to an element in the first section' do expect(contents).to include( 'override text' @@ -246,36 +262,6 @@ def dest_file(file) HTML end end - context 'breadcrumbs' do - before(:each) do - # We need docbook compat to verify breadcrumbs - # We unregister_all first because the order that we - # register the plugins matters. - Asciidoctor::Extensions.unregister_all - Asciidoctor::Extensions.register DocbookCompat - Asciidoctor::Extensions.register Chunker - end - file_context 'the first section', 's1.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - end - file_context 'the second section', 's2.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - end - end end context 'there is a level 2 section' do let(:input) do @@ -416,25 +402,13 @@ def dest_file(file) include_examples 'standard page', 'index', nil let(:prev_title) { 'Title [fooo]' } include_examples 'subpage' - end - context 'breadcrumbs' do - before(:each) do - # We need docbook compat to verify breadcrumbs - # We unregister_all first because the order that we - # register the plugins matters. - Asciidoctor::Extensions.unregister_all - Asciidoctor::Extensions.register DocbookCompat - Asciidoctor::Extensions.register Chunker - end - file_context 'the section', 's1.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML end end end @@ -534,7 +508,7 @@ def dest_file(file) end it 'contains the heading' do expect(contents).to include( - '

Section: With subtitle

' + '

Section: With subtitle

' ) end it 'contains the contents' do @@ -654,6 +628,14 @@ def dest_file(file) it 'contains the heading' do expect(contents).to include('

S1

') end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML + end it 'contains a link to the level 3 section' do expect(contents).to include('S2_1_1') end @@ -664,6 +646,15 @@ def dest_file(file) it 'contains the heading' do expect(contents).to include('

S1_1

') end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML + end end file_context 'the second level 1 section', 's2.html' do include_examples 'standard page', 's1_1', 's2_1' @@ -671,6 +662,14 @@ def dest_file(file) it 'contains the heading' do expect(contents).to include('

S2

') end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML + end end file_context 'the second level 2 section', 's2_1.html' do include_examples 'standard page', 's2', 's2_2' @@ -681,6 +680,15 @@ def dest_file(file) it 'contains the level 3 section' do expect(contents).to include('

S2_1_1

') end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML + end end file_context 'the last level 2 section', 's2_2.html' do include_examples 'standard page', 's2_1', nil @@ -688,68 +696,14 @@ def dest_file(file) it 'contains the heading' do expect(contents).to include('

S2_2

') end - end - context 'breadcrumbs' do - before(:each) do - # We need docbook compat to verify breadcrumbs - # We unregister_all first because the order that we - # register the plugins matters. - Asciidoctor::Extensions.unregister_all - Asciidoctor::Extensions.register DocbookCompat - Asciidoctor::Extensions.register Chunker - end - file_context 'the first level 1 section', 's1.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - file_context 'the first level 2 section', 's1_1.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - end - file_context 'the second level 1 section', 's2.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - end - file_context 'the second level 2 section', 's2_1.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - end - file_context 'the last level 2 section', 's2_2.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML end end end @@ -808,6 +762,14 @@ def dest_file(file) it 'contains the heading' do expect(contents).to include('

Appendix A: Foo

') end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML + end end file_context 'the first page in the appendix', 'app_1.html' do include_examples 'standard page', 'app', 'app_2' @@ -817,6 +779,15 @@ def dest_file(file) it 'contains the heading' do expect(contents).to include('

Foo 1

') end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML + end end file_context 'the first page in the appendix', 'app_2.html' do include_examples 'standard page', 'app_1', nil @@ -825,47 +796,14 @@ def dest_file(file) it 'contains the heading' do expect(contents).to include('

Foo 2

') end - end - context 'breadcrumbs' do - before(:each) do - # We need docbook compat to verify breadcrumbs - # We unregister_all first because the order that we - # register the plugins matters. - Asciidoctor::Extensions.unregister_all - Asciidoctor::Extensions.register DocbookCompat - Asciidoctor::Extensions.register Chunker - end - file_context 'the appendix', 'app.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - file_context 'the first page in the appendix', 'app_1.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - end - file_context 'the first page in the appendix', 'app_2.html' do - it 'contains the breadcrumbs' do - expect(contents).to include <<~HTML - - HTML - end - end + it 'contains the breadcrumbs' do + expect(contents).to include <<~HTML + + HTML end end end diff --git a/resources/asciidoctor/spec/docbook_compat_spec.rb b/resources/asciidoctor/spec/docbook_compat_spec.rb index 5f7ada5f31775..4d8650c6f276d 100644 --- a/resources/asciidoctor/spec/docbook_compat_spec.rb +++ b/resources/asciidoctor/spec/docbook_compat_spec.rb @@ -111,10 +111,12 @@ it "is wrapped in docbook's funny titlepage" do expect(converted).to include(<<~HTML)
-

Title

+
+ +
HTML end end @@ -131,10 +133,12 @@ it "is wrapped in docbook's funny titlepage" do expect(converted).to include(<<~HTML)
-

Title

+
+ +
HTML end end @@ -165,10 +169,10 @@ it "is wrapped in docbook's funny titlepage" do expect(converted).to include(<<~HTML)
-

Title

+
HTML end @@ -176,6 +180,7 @@ context 'the table of contents' do it 'is outside the titlepage' do expect(converted).to include(<<~HTML) +
@@ -288,7 +293,7 @@ expect(converted).not_to include '' end it 'includes the unabbreviated title' do - expect(converted).to include 'Section 1' + expect(converted).to include 'Section 1' end it 'includes a link to the abbreviated section' do expect(converted).to include <<~HTML.strip @@ -359,15 +364,23 @@ Words. ASCIIDOC end + context 'the title' do + it "doesn't include the subtitle" do + expect(converted).to include(<<~HTML) + Title | Elastic + + HTML + end + end context 'the header' do it 'includes the title and subtitle' do expect(converted).to include(<<~HTML)
-

Title

Subtitle

+
HTML @@ -394,10 +407,10 @@ it 'includes the title and subtitle' do expect(converted).to include(<<~HTML)
-

foo

+
HTML @@ -482,6 +495,64 @@ end end end + context 'when the head is disabled' do + let(:convert_attributes) do + { + # Shrink the output slightly so it is easier to read + 'stylesheet!' => false, + # Disable the head + 'noheader' => true, + } + end + let(:input) do + <<~ASCIIDOC + = Title + + Words. + ASCIIDOC + end + context 'the header' do + it "doesn't contain the title h1" do + expect(converted).not_to include('Title') + end + end + context 'the body' do + it "doesn't have attributes" do + expect(converted).to include('') + end + it "doesn't include the 'book' wrapper" do + expect(converted).not_to include(<<~HTML) +
+ HTML + end + end + + context 'when there is a page-header' do + let(:convert_attributes) do + { + # Shrink the output slightly so it is easier to read + 'stylesheet!' => false, + 'noheader' => true, + 'page-header' => '
', + } + end + let(:input) do + <<~ASCIIDOC + = Title + + Words. + ASCIIDOC + end + context 'the header' do + it 'contains the page-header right after the body tag' do + expect(converted).not_to include <<~HTML + +
+ HTML + end + end + end + end context 'when the head is disabled' do let(:convert_attributes) do { @@ -563,10 +634,9 @@ end end it "is wrapped in docbook's funny titlepage" do - level = hlevel < 2 ? 2 : hlevel expect(converted).to include(<<~HTML)
- #{title}#{xpack_tag} + #{title}#{xpack_tag}
HTML end @@ -731,7 +801,7 @@ include_examples 'section basics', 'appendix', 1, '_foo', 'Appendix A: Foo' it "doesn't bump the h tags of sections within it" do - expect(converted).to include 'Bar' + expect(converted).to include 'Bar' end end end diff --git a/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb b/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb index 7102aa0821309..884fac8a63a0d 100644 --- a/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb +++ b/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb @@ -195,7 +195,7 @@ end it 'uses the attributes for the header' do expect(converted).to include <<~HTML -

Header

+

Header

HTML end it 'uses the attributes outside of the header' do @@ -299,7 +299,7 @@ expect(converted).to eq <<~HTML
-

Example

+

Example

@@ -340,7 +340,7 @@ expect(converted).to eq <<~HTML
-

Example

+

Example

@@ -470,7 +470,7 @@ end it 'has the right offset' do expect(converted).to include <<~HTML -

Target

+

Target

HTML end end diff --git a/resources/web/docs_js/__tests__/docs.test.js b/resources/web/docs_js/__tests__/docs.test.js index 4b862bf1e30b0..87ad943e037b4 100644 --- a/resources/web/docs_js/__tests__/docs.test.js +++ b/resources/web/docs_js/__tests__/docs.test.js @@ -115,7 +115,7 @@ function describeInitHeaders(name, guideBody, onThisPageAssertions) { describe(name, () => { beforeEach(() => { document.body.innerHTML = dedent ` -
+
${guideBody}
@@ -142,28 +142,28 @@ describe('On This Page', () => { `; const oneSubsection = dedent ` ${onlyTitle} -

+

Near Realtime (NRT) -

+ `; const twoSubsections = dedent ` ${oneSubsection} -

+

Cluster -

+ `; const fourSubsections = dedent ` ${twoSubsections} -

+

Observability -

-

+

+

APM -

+ `; describeInitHeaders('for page with just a title', onlyTitle, () => { diff --git a/resources/web/docs_js/index.js b/resources/web/docs_js/index.js index ef684eaf67a8f..6b180c4b2a3bd 100644 --- a/resources/web/docs_js/index.js +++ b/resources/web/docs_js/index.js @@ -63,10 +63,10 @@ export function init_headers(sticky_content, lang_strings) { this_page.append('

' + lang_strings('On this page') + '

'); var ul = $('
    ').appendTo(this_page); var items = 0; + var baseHeadingLevel = 0; - // Get all headings inside the main body of the doc - $('div#content a[id]:not([href])').each( - function(i) { + $('#guide a[id]:not([href])').each( + function(i, el) { // Make headers into real links for permalinks this.href = '#' + this.id; @@ -76,11 +76,17 @@ export function init_headers(sticky_content, lang_strings) { // Assume initial heading is an H1, but adjust if it's not let hLevel = 0; if ($(this).parent().is("h2")){ - hLevel = 0; - } else if ($(this).parent().is("h3")){ hLevel = 1; - } else if ($(this).parent().is("h4")){ + } else if ($(this).parent().is("h3")){ hLevel = 2; + } else if ($(this).parent().is("h4")){ + hLevel = 3; + } + + // Set the base heading level for the page to the title page level + 1 + // This ensures top level headings aren't nested + if (i === 0){ + baseHeadingLevel = hLevel + 1; } // Build list items for all headings except the page title @@ -88,7 +94,8 @@ export function init_headers(sticky_content, lang_strings) { title_container.find('a,.added,.coming,.deprecated,.experimental') .remove(); var text = title_container.html(); - const li = '
  • ' + text + '
  • '; + const adjustedLevel = hLevel - baseHeadingLevel; + const li = '
  • ' + text + '
  • '; ul.append(li); } } @@ -245,9 +252,7 @@ function highlight_otp() { }) }) - document.querySelectorAll('div#content a[id]').forEach((heading, i) => { - // Skip the first heading since it's not visible - if (i === 0) return + document.querySelectorAll('#guide a[id]').forEach((heading) => { observer.observe(heading); }) } @@ -341,42 +346,6 @@ $(function() { AlternativeSwitcher(store()); - // Get all headings inside the main body of the doc - const allHeadings = $('div#content').find('h1,h2,h3,h4,h5,h6') - let allLevels = [] - // Create a list of all heading levels used on the page - allHeadings.each(function(index) { - // Don't include the first heading because that's the title - if (index === 0) return; - if (!allLevels.includes($(this).prop('nodeName'))) allLevels.push($(this).prop('nodeName')); - }) - // Update the heading level to be incremental - // (i.e. the first heading after the title should be an h2 and - // then deeper levels should be adjusted so they are incremental) - allHeadings.each(function(index) { - const currentHeading = $(this) - const contents = currentHeading.prop('innerHTML') - // Don't include the first heading because that's the - // title and we always want that to be an h1 - if (index > 0) { - if (allLevels[0] && ($(this).prop('nodeName') === allLevels[0])) { - $(this).replaceWith(`

    ${contents}

    `); - } - if (allLevels[1] && ($(this).prop('nodeName') === allLevels[1])) { - $(this).replaceWith(`

    ${contents}

    `); - } - if (allLevels[2] && ($(this).prop('nodeName') === allLevels[2])) { - $(this).replaceWith(`

    ${contents}

    `); - } - if (allLevels[3] && ($(this).prop('nodeName') === allLevels[3])) { - $(this).replaceWith(`
    ${contents}
    `); - } - if (allLevels[4] && ($(this).prop('nodeName') === allLevels[4])) { - $(this).replaceWith(`
    ${contents}
    `); - } - } - }) - // If breadcrumbs contain a dropdown (e.g. APM, ECS Logging) // handle interaction with the dropdown if ($('#related-products')) { @@ -485,7 +454,7 @@ $(function() { var div = $('div.toc'); // Fetch toc.html unless there is already a .toc on the page - if (div.length == 0) { + if (div.length == 0 && $('#guide').find('div.article,div.book').length == 0) { var url = location.href.replace(/[^\/]+$/, 'toc.html'); var toc = $.get(url, {}, function(data) { left_col.append(data); diff --git a/resources/web/style/admonishment.pcss b/resources/web/style/admonishment.pcss index 8fa20318458da..5413a1c7f59b0 100644 --- a/resources/web/style/admonishment.pcss +++ b/resources/web/style/admonishment.pcss @@ -85,13 +85,8 @@ .admon_content { margin-left: 80px; - /* On page load, the heading level may be changed, - but we always what to style it the same way */ - h2, h3, h4, h5, h6 { + h3 { margin: 3px 0; - font-size: 22px; - font-weight: 600; - a { font-weight: 600; } } p:last-of-type { margin-bottom: 0em; diff --git a/resources/web/style/console_widget.pcss b/resources/web/style/console_widget.pcss index 819c2e0dee455..0ea12fe5c2361 100644 --- a/resources/web/style/console_widget.pcss +++ b/resources/web/style/console_widget.pcss @@ -65,9 +65,7 @@ .try_console_selector { text-align: center; - /* On page load, the heading level may be changed, - but we always what to style it the same way */ - h2, h3, h4, h5, h6 { + h4 { font-size: 30px; } diff --git a/resources/web/style/heading.pcss b/resources/web/style/heading.pcss index 26b0a3e046191..4210868e4c5fe 100644 --- a/resources/web/style/heading.pcss +++ b/resources/web/style/heading.pcss @@ -19,6 +19,11 @@ background-image: inline("img/link.png"); } } + h1 { + font-size: 36px; + margin: 10px 0 10px; + a { font-weight: 300; } + } h2 { font-size: 29px; margin: 20px 0; @@ -77,20 +82,5 @@ .title { margin: 10px 0 16px; } - /* Styles the page header, which is always an h1 - wrapped in a div with the titlepage class, and always - has the title class. */ - h1.title { - margin: 24px 0; - font-size: 36px; - padding: 0; - a { font-weight: 300; } - } - } - - /* Hide the first heading within the main content - of the page since it is the same as the title */ - div#content > div > .titlepage { - display: none; } -} +} \ No newline at end of file