Improved the mdown2::paragraph_p parser.
[mppdown.git] / MDOWN
blobfaf8950b3e07ebbc03f6e9d861e49e49a3e103b3
1 %mdown 2.0
2 %? mdown core features
3 %? Nhat Minh LĂȘ <nhat.minh.le@huoc.org>
5 # Meta-info markup
7 ## Comments
9 Comments are lines beginning (at column 0) with any number of percent
10 signs, followed by space.
12 :Rationale:
13   This reserves constructs for directives without hurting readability.
15 ## Directives
17 Directives are lines beginning (at column 0) with a percent sign, not
18 followed by space. Most directives are ignored by mdown.
20 :Rationale:
21   Most static preprocessors operate on lines. Such directives leave
22   the opportunity for such preprocessors to be added. For more complex
23   handling of contents, you should use macros and environments with
24   appropriate dynamic element translation.
26 ### Version directive
28 Each mdown document must start with the version directive `%mdown`,
29 followed by the version of the mdown language in use in the
30 document. The only valid value defined by this specification is `2.0`.
32 Only comments and blank lines are allowed before the version
33 directive.
35 :Rationale:
36   The intent is quite obviously that new versions of mdown will
37   increment the version number.
39 ### Line directives
41 The `%#` directive followed by a numeric (all-digit) word `N`
42 indicates that the following line should be referred to as the `N`^th
43 line of the current file.
45 The `%#` directive followed by a numeric word `N` and an arbitrary
46 string (with leading spaces stripped) specifies a new file name in
47 addition to the new line number.
49 ### Bibliographic directives
51 The first three occurrences of the `%?` directive are special to mdown
52 and recognized as bibliograhic information. In order, they specify, in
53 plain text, the name of the document, the name of the author or
54 authors, and the date of publication.
56 :Rationale:
57   Plain text was chosen so that this information can be handled
58   separately without having to invoke the mdown system. Since many
59   output formats do not support formatting in titles anyway, the need
60   for such support in mdown was deemed negligible.
62 ### Annotation alias directives
64 A simple annotation (which takes no argument) can be defined by making
65 an alias of another annotation. It is the only way to specify
66 arguments for inline annotations.
68 An inline annotation alias is a `%@` directive followed by the name of
69 the annotation being defined, an equal sign, and the annotation name
70 and arguments of the aliased annotation.
72 A block annotation alias is a `%@@` directive that follows the same
73 syntax.
75 Definitions take effect immediately. Redefinitions are allowed and
76 take effect till the next redefinition or the end of the document.
79 # Inline markup
81 ## Styling
83 | Symbol   | Syntax      | Effects                | Constraints            |
84 +----------+-------------+------------------------+------------------------+
85 | `\`      | `\a`        | escaped character      |                        |
86 | `\`      | `a\ b`      | unbreakable space      | before whitespace      |
87 | `\`      | `line \`    | forced line break      | at end of line         |
88 | `*`      | `*a*`       | emphasis               |                        |
89 | `**`     | `**a**`     | strong emphasis        |                        |
90 | `***`    | `***a***`   | very strong emphasis   |                        |
91 | `'`      | `'a'`       | alternate style        | lead-in/out            |
92 | `''`     | `''a''`     | strong alternate style | lead-in/out            |
93 | `` ` ``  | `` `a` ``   | code                   | matching, verbatim     |
94 | `$`      | `$a$`       | math                   | verbatim               |
95 | `^`      | `^a`        | superscript            | free group             |
96 | `@`      | `@c`        | special character      | symbol, matching       |
97 | `@`      | `@a`        | annotation             | free group             |
98 | `@`      | `@`         | repeat annotations     | free group             |
99 | `@"`     | `@"a"`      | inline quote           |                        |
100 | `@_`     | `@_a_`      | subscript              |                        |
101 | `@`      | `@a b`      | annotation             | named, free group      |
102 | `{}`     | `{a}`       | group                  | where free group       |
104 Some notes:
106 - Lead-in/out means the opening/closing symbol has to appear at word
107   boundary on the external side of the element: that is, the opening
108   symbol has to be preceded by white space or a punctuator that is
109   actually interpreted by mdown, and the closing symbol must be
110   followed by such a character.
112 - Matching means there can be more than one delimiter, but their
113   number has to agree in a single element.
115 - Free group means the construct applies to the next syntactical
116   group, which defaults to the next word.
118 - Named means the construct takes a name, which is an alphanumeric
119   sequence.
121 :Rationale:
122   The line-breaking character was changed from mdown-1 following many
123   complaints that it was hard to spot and triggered hard-to-understand
124   errors.
126   Emphasis was changed from two different characters to a single
127   stackable one for homogeneity, resemblance to [?Markdown], and
128   because the slash is much used in addresses and paths.
130   The alternate style construct was introduced after much
131   consideration concluding that people don't usually care what
132   language a word is actually written in, just that it is not native
133   from the current language of the document. Besides, I believe it is
134   natural for most people to pronounce unknown foreign words according
135   to the rules of their native language, not some foreign rules they
136   may or may not know. Thus, the alternate style replaces mdown-1
137   foreign phrase constructs as well as language tags.
139   The math symbol is taken from TeX.
141 ## Links
143 | Symbol   | Syntax                 | Effects                   |
144 +----------+------------------------+---------------------------+
145 | `[]`     | `[text]`               | implicit hypertext link   |
146 |          | `[text](address)`      | explicit hypertext link   |
147 |          | `[text|label]`         | indirect hypertext link   |
148 | `[!]`    | `[!text]`              | implicit substitution     |
149 |          | `[!text](address)`     | explicit substitution     |
150 |          | `[!text|label]`        | indirect substitution     |
151 | `[^]`    | `[^label]`             | footnote                  |
152 | `[?]`    | `[?label]`             | bibliographic note        |
154 :Rationale:
155   Implicit links replace the mdown-1 syntax for anchors: this is more
156   consistent. Anchors have been changed to a declaration syntax.
158   The indirect syntax was changed because of the introduction of
159   implicit links. It resembles the Wiki syntax, but reversed, which
160   may be awkward for some users, but I for one think that the Wiki
161   order is not natural for semantic links.
163 ## Constraints
165 Inline elements, even code spans, cannot cross block boundaries.
167 ## Nesting
169 Markup may nest but the output format is free to ignore any nesting
170 and only consider the outermost level of inline markup for
171 translation.
173 Therefore, it is advised that links always be put at the outermost
174 level, and styling be inlined within the link text.
176 Though the syntax allows same constructs to nest, it does not usually
177 make sense to do so, and implementations are encouraged to disregard
178 such markup.
180 :Rationale:
181   These rules allow parts of links to be emphasized or turned into
182   images, while still providing a fallback for output environments
183   where this kind of thing is not supported, in which case, the link
184   behavior will prevail over the rest.
187 # Block markup
189 Indentation is made through steps of two spaces or right angle
190 brackets. An indented block is a block where each line (except the
191 first, and except blank lines) is indented by two spaces (added to the
192 current indentation level). In the following descriptions, the
193 beginning of a line (as in "line begins with") means at the current
194 level of indentation.
196 ## Paragraphs
198 Paragraphs are unindented blocks (indented at the current indentation
199 level) delimited by blank lines or other constructs (in other words,
200 it is the default construct).
202 If a paragraph is preceded by blank lines, then it is a full
203 paragraph; if it is preceded by another block with no intervening
204 blank line, then it is continuation paragraph. Output formats are not
205 required to make a distinction. Comments do *not* count as blank
206 lines, meaning you can force a continuation by putting a comment in
207 place of a blank line.
209 Paragraphs cannot contain other blocks.
211 :Rationale:
212   The rules for continuation paragraphs have been simplified so that
213   each paragraph can now be treated separately. Continuation
214   paragraphs are useful either in order to remove extra spacing in
215   formats that use spacing to indicate paragraphs (e.g. most web
216   designs) or ugly indentation in formats that use indentation to mark
217   new paragraphs (e.g. LaTeX).
219   This now lets you make compact lists simply by not leaving a blank
220   line between the preceding paragraph and the list.
222 ## Headings
224 Headings are lines beginning at column 0 with one to five hash signs,
225 the number of which determine the level (one being the most important)
226 of the heading.
228 Headings cannot contain other blocks.
230 :Rationale:
231   After much thinking, the old wiki-like syntax was replaced with
232   a [?Markdown]-compatible syntax, partly because in the end, I find
233   it better-looking, partly since environments have had their syntax
234   changed.
236 ## Quotations
238 Quotations are indented blocks where the first line begins with
239 a right angle bracket and one space (each subsequent line may be
240 indented using such brackets as well, by definition of indentation).
242 ## Verbatim blocks
244 Verbatim blocks are indented blocks where the first line begins with
245 two spaces (each subsequent line may be indented using such brackets
246 as well, by definition of indentation).
248 The content of verbatim blocks are not parsed by mdown.
250 ## Math blocks
252 Math blocks are indented blocks where the first begins with two
253 dollars and one space.
255 The content of math blocks are not parsed by mdown.
257 ## Lists
259 Lists are made of consecutive items. The syntax of the items determine
260 the type of the list.
262 ### Unordered lists
264 Unordered list items are indented blocks where the first line begins
265 with a hyphen followed by one space.
267 ### Ordered lists
269 Ordered list items are indented blocks where the first line begins
270 with an all-digit word (the number thus formed shall not be
271 meaningful, except maybe for the first element) followed by one dot
272 then one space.
274 ### Associative lists
276 Associative list items are made of two blocks: one line (the head)
277 followed by an indented block (the body) where the first line
278 begins with a colon and one space.
280 ## Tables
282 Tables are made of consecutive rows.
284 ### Table rows
286 Table rows are indented blocks where the first line begins with
287 a vertical bar followed by a space. A table row contains table cells.
289 ### Simple table cells
291 Simple table cells are inline elements ending with a space and
292 a vertical bar. As inline elements, simple cells cannot contain
293 blocks.
295 ### Block table cells
297 Block table cells are indented blocks where the first line begins with
298 a plus sign followed by a space.
300 ## Environments
302 Environments are indented blocks where the first line begins with
303 a colons followed by the class (environment name; a word), some
304 optional argument text, another colon, and an optional caption
305 text. Subsequent lines make up the contents of the environment.
307 ## Block annotations
309 Blocks can be annotated. An annotation is a unindented line beginning
310 with two at signs, followed by the annotation name (a word), and some
311 optional argument text.
313 ## Declarations
315 Some mdown constructs reference a label. Such a label is defined using
316 a declaration construct, which consists of an indented line where the
317 beginning with one space followed by the entity being declared. The
318 entity name is marked up the same way it is written when referenced,
319 with the text part and the eventual vertical bar separator
320 removed. The rest of the declaration block is treated verbatim as
321 a reference to some resource.
323 Declarations are allowed for links, anchors, substitutions, and
324 bibliographic references.
326 Anchors share the syntax of the corresponding links (i.e. a fragment
327 name beginning with a hash sign) and have no declaration body. The
328 declaration point is taken as the resource for the anchor.
330 ## Indirect blocks
332 Indirect blocks are like declarations, except they allow inline
333 content and are used for footnotes and bibliographic references.
335 The first line of an indirect block follows the same syntax as
336 a declaration; subsequent lines are non-indented (i.e. as they would
337 in a paragraph). Hence, an indirect block cannot contain other blocks.
340 # Translation semantics
342 Are listed only things that are not obvious, for everything else, you
343 can ask me if you can't figure out, I may have forgotten some things.
345 ## Implicit links handling
347 When using implicit links, the actual text and address are both
348 inferred from the given link.
350 1. If there is a label defined with the same name, then its address is
351   used and the label itself is taken as the text.
353 2. Else, the link is taken to be an address.
355 3. For internal links: if there is a title associated with the
356   referenced entity, then it is used as the text (for an anchor, it is
357   the associated heading; for a document, it is its title; for a file
358   it is its file name); else, the link is used.
360 4. For external links: the link is used as the text.
362 :Rationale:
363   With the introduction of the internal address space, implicit links
364   are intended to become the main type of links internal to
365   a collection of mdown documents (e.g. a website). These were
366   obviously inspired by Wiki links in which the explicit text is not
367   often spelled out.
369 ## Translation of dynamic elements
371 mdown delegates the exact handling of some elements (called dynamic
372 elements) to the outer environment in which the resulting document
373 will be used. These elements are annotations, environments, and
374 links. A default translation is used if the output format does not
375 support such processing.
377 This is intended to be used in conjunction with some kind of
378 scripting, to produce documents with partly-generated contents or
379 customizable styles.
381 For example, an implementation could generate a LaTeX document with
382 native macro and environment calls. Or it could produce a HTML
383 document with macros and environments translated to CSS classes. But
384 the same document could be translated to a mixed PHP/HTML document,
385 replacing macros and environments with calls to server-side functions
386 for contents generation.
388 :Rationale:
389   This extends the simple environment translation mechanism of mdown-1
390   into a more flexible interface, which will hopefully allow better
391   integration with other tools and frameworks (mainly, website
392   frameworks).
395 # References
397  [?Crossmark] http://dev.laptop.org/git?p=users/krstic/docformat;a=blob_plain;f=crossmark-spec.txt;hb=HEAD
398  [?Markdown] http://daringfireball.net/projects/markdown/
399  [?Pandoc] http://johnmacfarlane.net/pandoc/
400  [?ReST] http://docutils.sourceforge.net/rst.html