public
Description: An implementation of markdown in C, using a PEG grammar
Clone URL: git://github.com/jgm/peg-markdown.git
Search Repo:
Simplified types:
Added 'next' field to Element struct, removed separate 'ElementList' 
struct.
jgm (author)
Wed May 07 08:19:59 -0700 2008
commit  090bb095e356c47a15dde48cdd529d940a5aec73
tree    8e2e8cffb5435afccc4209c8f644513d72d4a77a
parent  655841c9d2981927d59ea00db8f714c11c5f621a
...
81
82
83
84
 
85
86
 
87
88
89
...
281
282
283
284
 
285
286
 
287
288
289
...
427
428
429
430
 
431
432
433
 
434
435
436
...
81
82
83
 
84
85
 
86
87
88
89
...
281
282
283
 
284
285
 
286
287
288
289
...
427
428
429
 
430
431
432
 
433
434
435
436
0
@@ -81,9 +81,9 @@ void print_html_string(char *str, bool obfuscate) {
0
 }
0
 
0
 /* print_html_element_list - print a list of elements as HTML */
0
-void print_html_element_list(item *list, bool obfuscate) {
0
+void print_html_element_list(element *list, bool obfuscate) {
0
     while (list != NULL) {
0
- print_html_element((*list).val, obfuscate);
0
+ print_html_element(*list, obfuscate);
0
         list = (*list).next;
0
     }
0
 }
0
@@ -281,9 +281,9 @@ void print_latex_string(char *str) {
0
 }
0
 
0
 /* print_latex_element_list - print a list of elements as LaTeX */
0
-void print_latex_element_list(item *list) {
0
+void print_latex_element_list(element *list) {
0
     while (list != NULL) {
0
- print_latex_element((*list).val);
0
+ print_latex_element(*list);
0
         list = (*list).next;
0
     }
0
 }
0
@@ -427,10 +427,10 @@ void print_groff_string(char *str) {
0
 }
0
 
0
 /* print_groff_mm_element_list - print a list of elements as groff ms */
0
-void print_groff_mm_element_list(item *list) {
0
+void print_groff_mm_element_list(element *list) {
0
     int count = 1;
0
     while (list != NULL) {
0
- print_groff_mm_element((*list).val, count);
0
+ print_groff_mm_element(*list, count);
0
         list = (*list).next;
0
         count++;
0
     }
...
29
30
31
32
33
 
 
34
35
 
36
37
38
...
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
 
 
 
76
77
78
...
85
86
87
88
 
89
90
91
...
118
119
120
121
 
122
123
124
...
128
129
130
131
 
132
133
 
134
135
 
136
137
138
139
140
141
142
 
143
144
145
146
147
148
149
 
150
151
152
...
154
155
156
157
 
158
159
160
...
166
167
168
169
170
 
 
171
172
173
 
174
175
176
...
293
294
295
296
 
297
298
299
...
29
30
31
 
 
32
33
34
 
35
36
37
38
...
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
76
77
78
...
85
86
87
 
88
89
90
91
...
118
119
120
 
121
122
123
124
...
128
129
130
 
131
132
 
133
134
 
135
136
137
138
139
140
141
 
142
143
144
145
146
147
148
 
149
150
151
152
...
154
155
156
 
157
158
159
160
...
166
167
168
 
 
169
170
171
172
 
173
174
175
176
...
293
294
295
 
296
297
298
299
0
@@ -29,10 +29,10 @@ int yyparse(void);
0
  ***********************************************************************/
0
 
0
 /* cons - cons an element onto a list, returning pointer to new head */
0
-static item *cons(element new, item *list) {
0
- item *head = malloc(sizeof(item));
0
+static element *cons(element new, element *list) {
0
+ element *head = malloc(sizeof(element));
0
     assert(head != NULL);
0
- (*head).val = new;
0
+ *head = new;
0
     (*head).next = list;
0
     return head;
0
 }
0
@@ -44,35 +44,35 @@ static void pushelt(element new, element *lst) {
0
 }
0
 
0
 /* reverse - reverse a list, returning pointer to new list */
0
-static item *reverse(item *list) {
0
- item *new = NULL;
0
+static element *reverse(element *list) {
0
+ element *new = NULL;
0
     while (list != NULL) {
0
- new = cons((*list).val, new);
0
+ new = cons(*list, new);
0
         list = (*list).next;
0
     }
0
     return new;
0
 }
0
 
0
-/* length_of_strings - returns sum of length of strings in an item list of STR elements */
0
-static int length_of_strings(item *list) {
0
+/* length_of_strings - returns sum of length of strings in a list of STR elements */
0
+static int length_of_strings(element *list) {
0
     int len = 0;
0
     while (list != NULL) {
0
- assert((*list).val.key == STR);
0
- assert((*list).val.contents.str != NULL);
0
- len += strlen((*list).val.contents.str);
0
+ assert((*list).key == STR);
0
+ assert((*list).contents.str != NULL);
0
+ len += strlen((*list).contents.str);
0
         list = (*list).next;
0
     }
0
     return len;
0
 }
0
 
0
 /* concat_string_list - concatenates string contents of list of STR elements */
0
-static char *concat_string_list(item *list) {
0
+static char *concat_string_list(element *list) {
0
     char *result = malloc(length_of_strings(list) + 2); /* leave room for optional \n and \0 */
0
     *result = '\0';
0
     while (list != NULL) {
0
- assert((*list).val.key == STR);
0
- assert((*list).val.contents.str != NULL);
0
- result = strcat(result, (*list).val.contents.str);
0
+ assert((*list).key == STR);
0
+ assert((*list).contents.str != NULL);
0
+ result = strcat(result, (*list).contents.str);
0
         list = (*list).next;
0
     }
0
     return result;
0
@@ -85,7 +85,7 @@ static char *concat_string_list(item *list) {
0
  ***********************************************************************/
0
 
0
 static char *charbuf = ""; /* Buffer of characters to be parsed. */
0
-static item *references; /* List of link references found. */
0
+static element *references; /* List of link references found. */
0
 static int output_format;
0
 static element parse_result; /* Results of parse. */
0
 static int syntax_extensions; /* Syntax extensions selected. */
0
@@ -118,7 +118,7 @@ static element mk_list(int key, element lst) {
0
 }
0
 
0
 /* mk_link - constructor for LINK element */
0
-static element mk_link(item *label, char *url, char *title) {
0
+static element mk_link(element *label, char *url, char *title) {
0
     element result;
0
     result.key = LINK;
0
     result.contents.link.label = label;
0
@@ -128,25 +128,25 @@ static element mk_link(item *label, char *url, char *title) {
0
 }
0
 
0
 /* match_inlines - returns true if inline lists match (case-insensitive...) */
0
-static bool match_inlines(item *l1, item *l2) {
0
+static bool match_inlines(element *l1, element *l2) {
0
     while (l1 != NULL && l2 != NULL) {
0
- if ((*l1).val.key != (*l2).val.key)
0
+ if ((*l1).key != (*l2).key)
0
             return false;
0
- switch ((*l1).val.key) {
0
+ switch ((*l1).key) {
0
         case SPACE:
0
         case LINEBREAK:
0
             break;
0
         case CODE:
0
         case STR:
0
         case HTML:
0
- if (strcasecmp((*l1).val.contents.str, (*l2).val.contents.str) == 0)
0
+ if (strcasecmp((*l1).contents.str, (*l2).contents.str) == 0)
0
                 break;
0
             else
0
                 return false;
0
         case EMPH:
0
         case STRONG:
0
         case LIST:
0
- if (match_inlines((*l1).val.contents.list, (*l2).val.contents.list))
0
+ if (match_inlines((*l1).contents.list, (*l2).contents.list))
0
                 break;
0
             else
0
                 return false;
0
@@ -154,7 +154,7 @@ static bool match_inlines(item *l1, item *l2) {
0
         case IMAGE:
0
             return false; /* No links or images within links */
0
         default:
0
- fprintf(stderr, "match_inlines encountered unknown key = %d\n", (*l1).val.key);
0
+ fprintf(stderr, "match_inlines encountered unknown key = %d\n", (*l1).key);
0
             exit(EXIT_FAILURE);
0
             break;
0
         }
0
@@ -166,11 +166,11 @@ static bool match_inlines(item *l1, item *l2) {
0
 
0
 /* find_reference - return true if link found in references matching label.
0
  * 'link' is modified with the matching url and title. */
0
-static bool find_reference(link *result, item *label) {
0
- item *cur = references; /* pointer to walk up list of references */
0
+static bool find_reference(link *result, element *label) {
0
+ element *cur = references; /* pointer to walk up list of references */
0
     link curitem;
0
     while (cur != NULL) {
0
- curitem = (*cur).val.contents.link;
0
+ curitem = (*cur).contents.link;
0
         if (match_inlines(label, curitem.label)) {
0
             (*result) = curitem;
0
             return true;
0
@@ -293,7 +293,7 @@ BulletListLoose = a:StartList
0
                   ( b:BulletListItem BlankLine*
0
                     { char *bplus = malloc(strlen(b.contents.str) + 3);
0
                         strcpy(bplus, b.contents.str);
0
- strcat(bplus, "\n\n"); /* In loose list, \n\n added to end of each item */
0
+ strcat(bplus, "\n\n"); /* In loose list, \n\n added to end of each element */
0
                         b = mk_str(bplus);
0
                         b.key = LISTITEM;
0
                         pushelt(b, &a);
...
10
11
12
13
14
15
 
 
 
16
17
18
19
20
21
22
23
24
 
 
 
25
26
27
...
53
54
55
 
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
...
79
80
81
82
 
83
84
85
 
86
87
88
89
 
90
91
92
...
10
11
12
 
 
 
13
14
15
16
17
18
19
20
21
 
 
 
22
23
24
25
26
27
...
53
54
55
56
57
58
59
60
 
 
 
 
 
 
 
 
61
62
63
...
72
73
74
 
75
76
77
 
78
79
80
81
 
82
83
84
85
0
@@ -10,18 +10,18 @@ extern char *strdup(const char *string);
0
 
0
 /* Information (label, URL and title) for a link. */
0
 struct Link {
0
- struct ElementListItem *label;
0
- char *url;
0
- char *title;
0
+ struct Element *label;
0
+ char *url;
0
+ char *title;
0
 };
0
 
0
 typedef struct Link link;
0
 
0
 /* Union for contents of an Element (string, list, or link). */
0
 union Contents {
0
- char *str;
0
- struct ElementListItem *list;
0
- struct Link link;
0
+ char *str;
0
+ struct Element *list;
0
+ struct Link link;
0
 };
0
 
0
 /* Types of semantic values returned by parsers. */
0
@@ -53,18 +53,11 @@ enum keys { LIST, /* A generic list of values. For ordered and bullet lists,
0
 struct Element {
0
     int key;
0
     union Contents contents;
0
+ struct Element *next;
0
 };
0
 
0
 typedef struct Element element;
0
 
0
-/* Node in linked list of Elements. */
0
-struct ElementListItem {
0
- element val;
0
- struct ElementListItem *next;
0
-};
0
-
0
-typedef struct ElementListItem item;
0
-
0
 enum markdown_extensions {
0
     EXT_SMART = 1
0
 };
0
@@ -79,14 +72,14 @@ enum formats { HTML_FORMAT,
0
 
0
 void print_html_string(char *str, bool obfuscate);
0
 void print_html_element(element elt, bool obfuscate);
0
-void print_html_element_list(item *list, bool obfuscate);
0
+void print_html_element_list(element *list, bool obfuscate);
0
 void print_latex_string(char *str);
0
 void print_latex_element(element elt);
0
-void print_latex_element_list(item *list);
0
+void print_latex_element_list(element *list);
0
 void print_latex_element(element elt);
0
 void print_groff_string(char *str);
0
 void print_groff_mm_element(element elt, int count);
0
-void print_groff_mm_element_list(item *list);
0
+void print_groff_mm_element_list(element *list);
0
 void print_groff_mm_element(element elt, int count);
0
 void print_element(element elt, int format);
0
 

Comments

    No one has commented yet.