Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,18 +371,29 @@ def preprocess(self, text):
"""
return text

# Is metadata if the content starts with '---'-fenced `key: value`
# Is metadata if the content starts with optional '---'-fenced `key: value`
# pairs. E.g. (indented for presentation):
# ---
# foo: bar
# another-var: blah blah
# ---
_metadata_pat = re.compile("""^---[ \t]*\n((?:[ \t]*[^ \t:]+[ \t]*:[^\n]*\n)+)---[ \t]*\n""")
# # header
# or:
# foo: bar
# another-var: blah blah
#
# # header

_metadata_pat = re.compile(r"""
^
(?:---[\ \t]*\n)? # optional "---"
((?:[ \t]*[^ \t:]+[\ \t]*:[^\n]*\n)+) # "key: value" pairs
(?:---[ \t]*)? # optional "---"
\n""",
re.VERBOSE
)

def _extract_metadata(self, text):
# fast test
if not text.startswith("---"):
return text
match = self._metadata_pat.match(text)
if not match:
return text
Expand Down
3 changes: 3 additions & 0 deletions test/tm-cases/metadata2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>The real text</h1>

<p>This should be parsed as before</p>
7 changes: 7 additions & 0 deletions test/tm-cases/metadata2.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"test": "abc",
"leading~space": "is okay",
"And": "some, cvs, data, which, you, must, parse, yourself",
"this-is": "a hyphen test",
"empty": ""
}
1 change: 1 addition & 0 deletions test/tm-cases/metadata2.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extras": ["metadata"]}
1 change: 1 addition & 0 deletions test/tm-cases/metadata2.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extra metadata issue78
9 changes: 9 additions & 0 deletions test/tm-cases/metadata2.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test: abc
this-is : a hyphen test
leading~space : is okay
And: some, cvs, data, which, you, must, parse, yourself
empty :

# The real text

This should be parsed as before