From c00cd848a1f555950cf4bcd8b863ed2c494ae236 Mon Sep 17 00:00:00 2001 From: Thom Smith Date: Tue, 8 Feb 2022 16:02:47 -0500 Subject: [PATCH] Link headings to enclosing sections --- spec/1.3.0/bin/lib/transformations.py | 12 ++++++++++++ www/main/spec.scss | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/1.3.0/bin/lib/transformations.py b/spec/1.3.0/bin/lib/transformations.py index e8ae08db..1b00b2eb 100644 --- a/spec/1.3.0/bin/lib/transformations.py +++ b/spec/1.3.0/bin/lib/transformations.py @@ -99,6 +99,8 @@ def transform(soup, links): toc_header.parent.insert_after(toc) + link_headings(soup) + create_internal_links(soup, link_index) check_for_duplicate_ids(soup) @@ -207,6 +209,16 @@ def number_figures(soup): replace(figure_heading, HEADING_NUMBER_EXPR, '.'.join([chapter, str(i)])) +def link_headings(soup): + for heading in soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']): + section = heading.find_parent('section') + if section is not None: + anchor = section.attrs.get('id', None) + if anchor is not None: + a = tag('a', [ch.extract() for ch in list(heading.children)], href='#'+anchor) + heading.append(a) + + PRODUCTION_EXPR = re.compile(r''' (?P\#.*) | \b(?P diff --git a/www/main/spec.scss b/www/main/spec.scss index 5ef60b1f..3ab27f11 100644 --- a/www/main/spec.scss +++ b/www/main/spec.scss @@ -12,11 +12,17 @@ body.status-draft { a { color: inherit; - text-decoration: underline solid $theme-color; + text-decoration: underline solid currentcolor; &:hover { color: blue; - text-decoration: underline solid blue; + } +} + +h1, h2, h3, h4, h5, h6 { + position: relative; + a { + text-decoration: none; } }