From fbdd3f897144a216530626705c6a0d0508db8db5 Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Sun, 18 Apr 2021 12:36:27 -0700 Subject: [PATCH] code block support, kind-of --- yaclog/changelog.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/yaclog/changelog.py b/yaclog/changelog.py index 3dbb23d..916a8bc 100644 --- a/yaclog/changelog.py +++ b/yaclog/changelog.py @@ -71,12 +71,30 @@ class Changelog: self.lines = fp.readlines() section = '' - last_line = '' in_block = False + in_code = False # loop over lines in the file for line_no, line in enumerate(self.lines): - if match := re.fullmatch( + if in_code: + if re.match(r'^```', line): + line = '```' + in_code = False + in_block = False + + if len(self.versions) == 0: + self.header += line + else: + self.versions[-1].sections[section][-1] += line + + elif re.match(r'^```', line): + in_code = True + if len(self.versions) == 0: + self.header += line + else: + self.versions[-1].sections[section].append(line) + + elif match := re.fullmatch( r'^##\s+(?P\S*)(?:\s+-\s+(?P\S+))?\s*?(?P.*?)\s*#*$', line): # this is a version header in the form '## Name (- date) (tags*) (#*)' section = '' @@ -119,8 +137,6 @@ class Changelog: self.versions[-1].sections[section].append(line.strip()) in_block = True - last_line = line - # handle links for version in self.versions: if match := re.fullmatch(r'\[(.*)]', version.name):