diff --git a/docs/extensions/meta_data.txt b/docs/extensions/meta_data.txt index 4a4fe62ac..b0cc85e73 100644 --- a/docs/extensions/meta_data.txt +++ b/docs/extensions/meta_data.txt @@ -23,7 +23,7 @@ This extension is included in the standard Markdown library. Syntax ------ -Meta-data consists of a series of keywords and values defined at the beginning +Meta-data consists of a series of keywords and values defined at the beginning of a markdown document like this: Title: My Document @@ -31,28 +31,22 @@ of a markdown document like this: Authors: Waylan Limberg John Doe Date: October 2, 2007 - blank-value: + blank-value: base_url: http://example.com This is the first paragraph of the document. -The keywords are case-insensitive and may consist of letters, numbers, -underscores and dashes and must end with a colon. The values consist of +The keywords are case-insensitive and may consist of letters, numbers, +underscores and dashes and must end with a colon. The values consist of anything following the colon on the line and may even be blank. If a line is indented by 4 or more spaces, that line is assumed to be an additional line of the value for the previous keyword. A keyword may have as -many lines as desired. +many lines as desired. The first blank line ends all meta-data for the document. Therefore, the first line of a document must not be blank. -Alternatively, You may use YAML style deliminators to mark the start and/or end -of your meta-data. When doing so, the first line of your document must be `---`. -The meta-data ends at the first blank line or the first line containing an end -deliminator (either `---` or `...`), whichever comes first. Even though YAML -deliminators are supported, meta-data is not parsed as YAML. - All meta-data is stripped from the document prior to any further processing by Markdown. @@ -65,7 +59,7 @@ as the name of the extension. Accessing the Meta-Data ----------------------- -The meta-data is made available as a python Dict in the `Meta` attribute of an +The meta-data is made available as a python Dict in the `Meta` attribute of an instance of the Markdown class. For example, using the above document: >>> md = markdown.Markdown(extensions = ['markdown.extensions.meta']) @@ -85,10 +79,10 @@ instance of the Markdown class. For example, using the above document: 'base_url' : ['http://example.com'] } -Note that the keys are all lowercase and the values consist of a list of -strings where each item is one line for that key. This way, one could preserve -line breaks if desired. Or the items could be joined where appropriate. No -assumptions are made regarding the data. It is simply passed as found to the +Note that the keys are all lowercase and the values consist of a list of +strings where each item is one line for that key. This way, one could preserve +line breaks if desired. Or the items could be joined where appropriate. No +assumptions are made regarding the data. It is simply passed as found to the `Meta` attribute. Perhaps the meta-data could be passed into a template system, or used by @@ -98,7 +92,7 @@ the developer. Compatible Extensions --------------------- -The following extensions are currently known to work with the Meta-Data +The following extensions are currently known to work with the Meta-Data extension. The keywords they are known to support are also listed. * [HeaderId](header_id.html) @@ -108,4 +102,3 @@ extension. The keywords they are known to support are also listed. * `wiki_base_url` * `wiki_end_url` * `wiki_html_class` - diff --git a/markdown/extensions/meta.py b/markdown/extensions/meta.py index 711235ef4..2268ba6dd 100644 --- a/markdown/extensions/meta.py +++ b/markdown/extensions/meta.py @@ -27,8 +27,6 @@ # Global Vars META_RE = re.compile(r'^[ ]{0,3}(?P[A-Za-z0-9_-]+):\s*(?P.*)') META_MORE_RE = re.compile(r'^[ ]{4,}(?P.*)') -BEGIN_RE = re.compile(r'^-{3}(\s.*)?') -END_RE = re.compile(r'^(-{3}|\.{3})(\s.*)?') class MetaExtension (Extension): @@ -48,13 +46,11 @@ def run(self, lines): """ Parse Meta-Data and store in Markdown.Meta. """ meta = {} key = None - if lines and BEGIN_RE.match(lines[0]): - lines.pop(0) while lines: line = lines.pop(0) m1 = META_RE.match(line) - if line.strip() == '' or END_RE.match(line): - break # blank line or end of YAML header - done + if line.strip() == '': + break # blank line - done if m1: key = m1.group('key').lower().strip() value = m1.group('value').strip() @@ -70,7 +66,10 @@ def run(self, lines): else: lines.insert(0, line) break # no meta data - done - self.markdown.Meta = meta + if hasattr(self.markdown, 'Meta'): + self.markdown.Meta.update(meta) + else: + self.markdown.Meta = meta return lines diff --git a/tests/__init__.py b/tests/__init__.py index f759ceb74..27ba3b063 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,6 +15,8 @@ import tidylib except ImportError: tidylib = None +except OSError: + tidylib = None try: import yaml except ImportError as e: diff --git a/tests/test_extensions.py b/tests/test_extensions.py index 38f0be3c9..b95ad77e3 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -470,26 +470,21 @@ def testBasicMetaData(self): } ) - def testYamlMetaData(self): - """ Test metadata specified as simple YAML. """ + def testDoNotAcceptYamlMetaData(self): + """ Do not parse metadata specified as YAML anymore. """ text = '''--- -Title: A Test Doc. -Author: [Waylan Limberg, John Doe] +Foo: Bar Blank_Data: --- The body. This is paragraph one.''' self.assertEqual( self.md.convert(text), - '

The body. This is paragraph one.

' + '
\n

Foo: Bar\nBlank_Data:

\n
\n

The body. This is paragraph one.

' ) self.assertEqual( - self.md.Meta, { - 'author': ['[Waylan Limberg, John Doe]'], - 'blank_data': [''], - 'title': ['A Test Doc.'] - } + self.md.Meta, {} ) def testMissingMetaData(self):