Debian Codegraph @

docs/extensions/meta_data.md

raw
1 title: Meta-Data Extension
2
3 Meta-Data
4 =========
5
6 Summary
7 -------
8
9 The Meta-Data extension adds a syntax for defining meta-data about a document.
10 It is inspired by and follows the syntax of [MultiMarkdown][]. Currently,
11 this extension does not use the meta-data in any way, but simply provides it as
12 a `Meta` attribute of a Markdown instance for use by other extensions or
13 directly by your python code.
14
15 This extension is included in the standard Markdown library.
16
17 [MultiMarkdown]: https://fletcherpenney.net/multimarkdown/#metadata
18
19 !!! Note
20
21 This extension is in __maintenance mode__. We will continue to fix bugs
22 and keep it up-to-date with the core parser, but no new features or
23 changes in behavior will be made. If you need a feature that this
24 extension does not offer, then you have three options (1) find an
25 existing [third-party extension] which meets your needs, (2) [build your
26 own extension], or (3) fork this extension (pursuant to its licensing
27 requirements) and maintain it as a third-party extension.
28
29 [third-party extension]: index.md#third-party-extensions
30 [build your own extension]: api.md
31
32 Syntax
33 ------
34
35 Meta-data consists of a series of keywords and values defined at the beginning
36 of a markdown document like this:
37
38 ```md
39 Title: My Document
40 Summary: A brief description of my document.
41 Authors: Waylan Limberg
42 John Doe
43 Date: October 2, 2007
44 blank-value:
45 base_url: http://example.com
46
47 This is the first paragraph of the document.
48 ```
49
50 The keywords are case-insensitive and may consist of letters, numbers,
51 underscores and dashes and must end with a colon. The values consist of
52 anything following the colon on the line and may even be blank.
53
54 If a line is indented by 4 or more spaces, that line is assumed to be an
55 additional line of the value for the previous keyword. A keyword may have as
56 many lines as desired.
57
58 The first blank line ends all meta-data for the document. Therefore, the first
59 line of a document must not be blank.
60
61 Alternatively, You may use YAML style delimiters to mark the start and/or end
62 of your meta-data. When doing so, the first line of your document must be `---`.
63 The meta-data ends at the first blank line or the first line containing an end
64 deliminator (either `---` or `...`), whichever comes first. Even though YAML
65 delimiters are supported, meta-data is not parsed as YAML.
66
67 All meta-data is stripped from the document prior to any further processing
68 by Markdown.
69
70 Usage
71 -----
72
73 See [Extensions](index.md) for general extension usage. Use `meta` as the name
74 of the extension.
75
76 A trivial example:
77
78 ```python
79 markdown.markdown(some_text, extensions=['meta'])
80 ```
81
82 Accessing the Meta-Data
83 -----------------------
84
85 The meta-data is made available as a python Dict in the `Meta` attribute of an
86 instance of the Markdown class. For example, using the above document:
87
88 ```pycon
89 >>> md = markdown.Markdown(extensions = ['meta'])
90 >>> html = md.convert(text)
91 >>> # Meta-data has been stripped from output
92 >>> print html
93 <p>This is the first paragraph of the document.</p>
94
95 >>> # View meta-data
96 >>> print md.Meta
97 {
98 'title' : ['My Document'],
99 'summary' : ['A brief description of my document.'],
100 'authors' : ['Waylan Limberg', 'John Doe'],
101 'date' : ['October 2, 2007'],
102 'blank-value' : [''],
103 'base_url' : ['http://example.com']
104 }
105 ```
106
107 Note that the keys are all lowercase and the values consist of a list of
108 strings where each item is one line for that key. This way, one could preserve
109 line breaks if desired. Or the items could be joined where appropriate. No
110 assumptions are made regarding the data. It is simply passed as found to the
111 `Meta` attribute.
112
113 Perhaps the meta-data could be passed into a template system, or used by
114 various Markdown extensions. The possibilities are left to the imagination of
115 the developer.
116
117 Compatible Extensions
118 ---------------------
119
120 The following extensions are currently known to work with the Meta-Data
121 extension. The keywords they are known to support are also listed.
122
123 * [WikiLinks](wikilinks.md)
124 * `wiki_base_url`
125 * `wiki_end_url`
126 * `wiki_html_class`