Skip to content

Commit 41f15c4

Browse files
Updated fix on metadata to work without fences
The previous commit towards resolving Issue trentm#234 didn't incorporate previous behavior that fences shouldn't be necessary. First introduced in Pull Request trentm#215, metadata should be accessible even without including `---` fences around opening metadata. This fix now preserves the ability to use either `---` fences (maybe without a subsequent blank line) or no fences (but with a blank line). Resolves: trentm#234
1 parent 85dc8d9 commit 41f15c4

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lib/markdown2.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,19 +406,23 @@ def preprocess(self, text):
406406
_key_val_block_pat = re.compile(
407407
"(.*:\s+>\n\s+[\S\s]+?)(?=\n\w+\s*:\s*\w+\n|\Z)", re.MULTILINE)
408408
_meta_data_fence_pattern = re.compile(r'^---[\ \t]*\n', re.MULTILINE)
409+
_meta_data_newline = re.compile("^\n", re.MULTILINE)
409410

410411
def _extract_metadata(self, text):
411-
if not text.startswith("---"):
412-
return text
413-
414-
fence_splits = re.split(self._meta_data_fence_pattern, text, maxsplit=2)
415-
metadata_content = fence_splits[1]
416-
match = re.findall(self._meta_data_pattern, metadata_content)
417-
418-
if not match:
419-
return text
420-
421-
tail = fence_splits[2]
412+
if text.startswith("---"):
413+
fence_splits = re.split(self._meta_data_fence_pattern, text, maxsplit=2)
414+
metadata_content = fence_splits[1]
415+
match = re.findall(self._meta_data_pattern, metadata_content)
416+
if not match:
417+
return text
418+
tail = fence_splits[2]
419+
else:
420+
metadata_split = re.split(self._meta_data_newline, text, maxsplit=1)
421+
metadata_content = metadata_split[0]
422+
match = re.findall(self._meta_data_pattern, metadata_content)
423+
if not match:
424+
return text
425+
tail = metadata_split[1]
422426

423427
kv = re.findall(self._key_val_pat, text)
424428
kvm = re.findall(self._key_val_block_pat, text)

0 commit comments

Comments
 (0)