From f56b26f70cea347dad501bca597d188dec849f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20L=C3=BCpges?= Date: Thu, 31 Jul 2025 11:35:03 +0200 Subject: [PATCH] Add a post-process hook to the snippets preprocessor (#2726) --- pymdownx/snippets.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pymdownx/snippets.py b/pymdownx/snippets.py index 305c7c0aa..7c2c19ceb 100644 --- a/pymdownx/snippets.py +++ b/pymdownx/snippets.py @@ -245,6 +245,9 @@ def download(self, url): continue raise SnippetMissingError(f"Cannot download snippet '{url}' (HTTP Error {e.code})") from e + def post_process_snippet(self, s_lines, snippet): + """Override to post-process the snippet's content.""" + return s_lines def parse_snippets(self, lines, file_name=None, is_url=False, is_section=False): """Parse snippets snippet.""" @@ -390,6 +393,10 @@ def parse_snippets(self, lines, file_name=None, is_url=False, is_section=False): elif section: s_lines = self.extract_section(section, s_lines) + # call the post-process hook + if s_lines: + s_lines = self.post_process_snippet(s_lines, snippet) + # Process lines looking for more snippets new_lines.extend( [