MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / MetaPreprocessor

Class MetaPreprocessor

markdown/extensions/meta.py:59–89  ·  view source on GitHub ↗

Get Meta-Data.

Source from the content-addressed store, hash-verified

57
58
59class MetaPreprocessor(Preprocessor):
60 """ Get Meta-Data. """
61
62 def run(self, lines: list[str]) -> list[str]:
63 """ Parse Meta-Data and store in Markdown.Meta. """
64 meta: dict[str, Any] = {}
65 key = None
66 if lines and BEGIN_RE.match(lines[0]):
67 lines.pop(0)
68 while lines:
69 line = lines.pop(0)
70 m1 = META_RE.match(line)
71 if line.strip() == '' or END_RE.match(line):
72 break # blank line or end of YAML header - done
73 if m1:
74 key = m1.group('key').lower().strip()
75 value = m1.group('value').strip()
76 try:
77 meta[key].append(value)
78 except KeyError:
79 meta[key] = [value]
80 else:
81 m2 = META_MORE_RE.match(line)
82 if m2 and key:
83 # Add another line to existing key
84 meta[key].append(m2.group('value').strip())
85 else:
86 lines.insert(0, line)
87 break # no meta data - done
88 self.md.Meta = meta
89 return lines
90
91
92def makeExtension(**kwargs): # pragma: no cover

Callers 1

extendMarkdownMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected