From 827009985d5af38f8abeb56fad92f247899e1750 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 25 Jan 2025 20:50:42 +0100 Subject: [PATCH] Minify fallback on docs build (#18887) Signed-off-by: Glenn Jocher Co-authored-by: UltralyticsAssistant --- docs/build_docs.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/build_docs.py b/docs/build_docs.py index 23e668dc..e75219aa 100644 --- a/docs/build_docs.py +++ b/docs/build_docs.py @@ -242,6 +242,29 @@ def remove_macros(): print(f"Removed {len(macros_indices)} URLs containing '/macros/' from {sitemap}") +def remove_comments_and_empty_lines(content, file_type): + """Removes comments and empty lines from a string of code, preserving newlines and URLs.""" + if file_type == "html": + # Remove HTML comments, preserving newline after comment + # content = re.sub(r"\n?", r"\n", content, flags=re.DOTALL) + pass + elif file_type == "css": + # Remove CSS comments, preserving newline after comment + # content = re.sub(r"/\*.*?\*/\n?", r"\n", content, flags=re.DOTALL) + pass + elif file_type == "js": + # Remove JS single-line comments, preserving newline and URLs + # content = re.sub(r"(?