public
Description: An implementation of markdown in C, using a PEG grammar
Clone URL: git://github.com/jgm/peg-markdown.git
commit  dcbe375b31b8fe785d6171dda1dce302d3f89d9e
tree    582c1006ae57b37554286a3cc047acef6ef0fa67
parent  090bb095e356c47a15dde48cdd529d940a5aec73
peg-markdown / README
100644 75 lines (50 sloc) 2.335 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
What is this?
=============
 
This is an implementation of John Gruber's "markdown"
(http://daringfireball.net/projects/markdown/) in C.
It uses a PEG grammar to define the syntax. This should allow easy
modification and extension.
 
It is pretty fast. A 179K text file that takes 5.7 seconds for
Markdown.pl (v. 1.0.1) to parse takes only 0.13 seconds for this
markdown. It does, however, use a fair amount of memory.
 
Installing
==========
 
This program is written in portable ANSI C. For convenience, two
required dependencies are included in the source directory:
 
  * bsittler's my_getopt option parsing library
    (http://www.geocities.com/bsittler/)
 
  * Ian Piumarta's peg/leg PEG parser generator
    (http://piumarta.com/software/peg/)
 
These will be built automatically.
 
To make the 'markdown' executable:
 
    make
 
Then, for usage instructions:
 
    ./markdown -h
 
To run John Gruber's Markdown 1.0.3 test suite:
 
    make test
 
The test suite will fail on one of the list tests. Here's why.
Markdown.pl encloses "item one" in the following list in `<p>` tags:
 
    1. item one
        * subitem
        * subitem
    
    2. item two
 
    3. item three
 
peg-markdown does not enclose "item one" in <p> tags unless it has a
following blank line. This is consistent with the official markdown
syntax description, and lets the author of the document choose whether
`<p>` tags are desired.
 
Hacking
=======
 
It should be pretty easy to modify markdown.leg to produce other formats
than HTML or LaTeX, and to parse syntax extensions. A quick guide:
 
  * To add an output format, add the format to 'formats', modify 'print_element',
    and add functions corresponding to 'print_html_string', 'print_html_element',
    and 'print_html_element_list'. Also add an option in the main loop that selects
    the new format.
 
  * To add syntax extensions, define them in the PEG grammar (bottom part
    of markdown.leg), using existing definitions as a guide. If you need
    to add new types of elements (e.g. FOOTNOTE), modify the 'keys'
    enum. By using `&{ }` rules it should be possible to selectively
    disable extensions depending on command-line options.
 
  * Note: Avoid using [^abc] character classes in the grammar, because they
    cause problems with non-ascii input. Instead, use: ( !'a' !'b' !'c' . )