From 766c0f0d8bf09968bb92089c82e4ca319d6af996 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Mon, 10 Nov 2025 12:34:23 -0500 Subject: [PATCH] Trim page title if needed --- fix_html.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fix_html.py b/fix_html.py index df46f1c..be96273 100644 --- a/fix_html.py +++ b/fix_html.py @@ -5,6 +5,7 @@ """ import sys from pathlib import Path +from re import sub from bs4 import BeautifulSoup @@ -40,6 +41,17 @@ def remove_link_icon(soup): a.decompose() +def trim_title(soup): + """Remove suffix from element""" + for title in soup.find_all('title'): + print(f'Checking {title}') + regex = r'\s*[\W\S]\s*Sublime\s+(Merge|Text)(\s+Documentation)?$' + trimmed = sub(regex, '', title.string) + if trimmed != title.string: + print(f' Changing to {trimmed}') + title.string.replace_with(trimmed) + + def main(): for root in DOC_ROOTS: @@ -53,6 +65,7 @@ def main(): delete_skins(soup) remove_link_icon(soup) + trim_title(soup) with path.open('w', encoding='utf-8') as file: # Can't prettify as that would introduce whitespace around inline tags