From b0700f7d49f837dc9ceed3c9ebd428be9f6af6c2 Mon Sep 17 00:00:00 2001 From: facelessuser Date: Sun, 22 Dec 2024 09:33:29 -0700 Subject: [PATCH] Simplify some areas of code --- pymdownx/snippets.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/pymdownx/snippets.py b/pymdownx/snippets.py index fc634b600..acc3e882c 100644 --- a/pymdownx/snippets.py +++ b/pymdownx/snippets.py @@ -314,11 +314,10 @@ def parse_snippets(self, lines, file_name=None, is_url=False, is_section=False): if m.group(2): for nums in m.group(2)[1:].split(','): span = nums.split(':') + start.append(max(0, int(span[0]) - 1) if span[0] else None) if len(span) > 1: - start.append(max(0, int(span[0]) - 1) if span[0] else None) end.append(int(span[1]) if span[1] else None) else: - start.append(max(0, int(span[0]) - 1) if span[0] else None) end.append(None) elif m.group(3): section = m.group(3)[1:] @@ -343,29 +342,24 @@ def parse_snippets(self, lines, file_name=None, is_url=False, is_section=False): # Read file content with codecs.open(snippet, 'r', encoding=self.encoding) as f: s_lines = [l.rstrip('\r\n') for l in f] - if start and end: - final_lines = [] - for entry in zip(start, end): - final_lines.extend(s_lines[slice(entry[0], entry[1], None)]) - s_lines = self.dedent(final_lines) if self.dedent_subsections else final_lines - elif section: - s_lines = self.extract_section(section, s_lines) else: # Read URL content try: s_lines = self.download(snippet) - if start and end: - final_lines = [] - for entry in zip(start, end): - final_lines.extend(s_lines[slice(entry[0], entry[1], None)]) - s_lines = self.dedent(final_lines) if self.dedent_subsections else final_lines - elif section: - s_lines = self.extract_section(section, s_lines) except SnippetMissingError: if self.check_paths: raise s_lines = [] + if s_lines: + if start and end: + final_lines = [] + for entry in zip(start, end): + final_lines.extend(s_lines[slice(entry[0], entry[1], None)]) + s_lines = self.dedent(final_lines) if self.dedent_subsections else final_lines + elif section: + s_lines = self.extract_section(section, s_lines) + # Process lines looking for more snippets new_lines.extend( [