public
Description: An implementation of markdown in C, using a PEG grammar
Clone URL: git://github.com/jgm/peg-markdown.git
Search Repo:
Made 'link' field in Contents union a pointer to link, for memory 
efficiency.
jgm (author)
Wed Jun 11 16:51:44 -0700 2008
commit  2bfdf6285ccebcaecc1fb464dfafd8b8a12a4ae0
tree    4651caed2898ac78188a1dd0bdcf5023c6a83a79
parent  f27569f10855a35e68d93709232d851319ad4fc8
...
144
145
146
147
 
148
149
150
 
151
152
 
153
154
 
155
156
157
158
 
159
160
161
162
163
 
164
165
 
166
167
 
168
169
 
170
171
172
...
393
394
395
396
397
 
 
398
399
400
401
 
402
403
404
...
595
596
597
598
599
 
 
600
601
602
603
604
 
605
606
607
...
144
145
146
 
147
148
149
 
150
151
 
152
153
 
154
155
156
157
 
158
159
160
161
162
 
163
164
 
165
166
 
167
168
 
169
170
171
172
...
393
394
395
 
 
396
397
398
399
400
 
401
402
403
404
...
595
596
597
 
 
598
599
600
601
602
603
 
604
605
606
607
0
@@ -144,29 +144,29 @@ static void print_html_element(GString *out, element elt, bool obfuscate) {
0
         g_string_append_printf(out, "%s", elt.contents.str);
0
         break;
0
     case LINK:
0
- if (strstr(elt.contents.link.url, "mailto:") == elt.contents.link.url)
0
+ if (strstr(elt.contents.link->url, "mailto:") == elt.contents.link->url)
0
             obfuscate = true; /* obfuscate mailto: links */
0
         g_string_append_printf(out, "<a href=\"");
0
- print_html_string(out, elt.contents.link.url, obfuscate);
0
+ print_html_string(out, elt.contents.link->url, obfuscate);
0
         g_string_append_printf(out, "\"");
0
- if (strlen(elt.contents.link.title) > 0) {
0
+ if (strlen(elt.contents.link->title) > 0) {
0
             g_string_append_printf(out, " title=\"");
0
- print_html_string(out, elt.contents.link.title, obfuscate);
0
+ print_html_string(out, elt.contents.link->title, obfuscate);
0
             g_string_append_printf(out, "\"");
0
         }
0
         g_string_append_printf(out, ">");
0
- print_html_element_list(out, elt.contents.link.label, obfuscate);
0
+ print_html_element_list(out, elt.contents.link->label, obfuscate);
0
         g_string_append_printf(out, "</a>");
0
         break;
0
     case IMAGE:
0
         g_string_append_printf(out, "<img src=\"");
0
- print_html_string(out, elt.contents.link.url, obfuscate);
0
+ print_html_string(out, elt.contents.link->url, obfuscate);
0
         g_string_append_printf(out, "\" alt=\"");
0
- print_html_element_list(out, elt.contents.link.label, obfuscate);
0
+ print_html_element_list(out, elt.contents.link->label, obfuscate);
0
         g_string_append_printf(out, "\"");
0
- if (strlen(elt.contents.link.title) > 0) {
0
+ if (strlen(elt.contents.link->title) > 0) {
0
             g_string_append_printf(out, " title=\"");
0
- print_html_string(out, elt.contents.link.title, obfuscate);
0
+ print_html_string(out, elt.contents.link->title, obfuscate);
0
             g_string_append_printf(out, "\"");
0
         }
0
         g_string_append_printf(out, " />");
0
@@ -393,12 +393,12 @@ static void print_latex_element(GString *out, element elt) {
0
         /* don't print HTML */
0
         break;
0
     case LINK:
0
- g_string_append_printf(out, "\\href{%s}{", elt.contents.link.url);
0
- print_latex_element_list(out, elt.contents.link.label);
0
+ g_string_append_printf(out, "\\href{%s}{", elt.contents.link->url);
0
+ print_latex_element_list(out, elt.contents.link->label);
0
         g_string_append_printf(out, "}");
0
         break;
0
     case IMAGE:
0
- g_string_append_printf(out, "\\includegraphics{%s}", elt.contents.link.url);
0
+ g_string_append_printf(out, "\\includegraphics{%s}", elt.contents.link->url);
0
         break;
0
     case EMPH:
0
         g_string_append_printf(out, "\\emph{");
0
@@ -595,13 +595,13 @@ static void print_groff_mm_element(GString *out, element elt, int count) {
0
         /* don't print HTML */
0
         break;
0
     case LINK:
0
- print_groff_mm_element_list(out, elt.contents.link.label);
0
- g_string_append_printf(out, " (%s)", elt.contents.link.url);
0
+ print_groff_mm_element_list(out, elt.contents.link->label);
0
+ g_string_append_printf(out, " (%s)", elt.contents.link->url);
0
         padded = 0;
0
         break;
0
     case IMAGE:
0
         g_string_append_printf(out, "[IMAGE: ");
0
- print_groff_mm_element_list(out, elt.contents.link.label);
0
+ print_groff_mm_element_list(out, elt.contents.link->label);
0
         g_string_append_printf(out, "]");
0
         padded = 0;
0
         /* not supported */
...
136
137
138
139
140
141
 
 
 
 
142
143
144
...
188
189
190
191
 
192
193
194
195
 
 
196
197
198
...
919
920
921
922
923
924
925
926
 
 
 
 
 
 
927
928
929
...
136
137
138
 
 
 
139
140
141
142
143
144
145
...
189
190
191
 
192
193
194
 
 
195
196
197
198
199
...
920
921
922
 
 
 
 
 
923
924
925
926
927
928
929
930
931
0
@@ -136,9 +136,10 @@ static element * mk_list(int key, element *lst) {
0
 static element * mk_link(element *label, char *url, char *title) {
0
     element *result;
0
     result = mk_element(LINK);
0
- result->contents.link.label = label;
0
- result->contents.link.url = strdup(url);
0
- result->contents.link.title = strdup(title);
0
+ result->contents.link = malloc(sizeof(link));
0
+ result->contents.link->label = label;
0
+ result->contents.link->url = strdup(url);
0
+ result->contents.link->title = strdup(title);
0
     return result;
0
 }
0
 
0
@@ -188,11 +189,11 @@ static bool match_inlines(element *l1, element *l2) {
0
  * 'link' is modified with the matching url and title. */
0
 static bool find_reference(link *result, element *label) {
0
     element *cur = references; /* pointer to walk up list of references */
0
- link curitem;
0
+ link *curitem;
0
     while (cur != NULL) {
0
         curitem = cur->contents.link;
0
- if (match_inlines(label, curitem.label)) {
0
- *result = curitem;
0
+ if (match_inlines(label, curitem->label)) {
0
+ *result = *curitem;
0
             return true;
0
         }
0
         else
0
@@ -919,11 +920,12 @@ void free_element_contents(element elt) {
0
         break;
0
       case LINK:
0
       case IMAGE:
0
- free(elt.contents.link.url);
0
- elt.contents.link.url = NULL;
0
- free(elt.contents.link.title);
0
- elt.contents.link.title = NULL;
0
- free_element_list(elt.contents.link.label);
0
+ free(elt.contents.link->url);
0
+ elt.contents.link->url = NULL;
0
+ free(elt.contents.link->title);
0
+ elt.contents.link->title = NULL;
0
+ free_element_list(elt.contents.link->label);
0
+ free(elt.contents.link);
0
         break;
0
       default:
0
         ;
...
22
23
24
25
 
26
27
28
...
22
23
24
 
25
26
27
28
0
@@ -22,7 +22,7 @@ typedef struct Link link;
0
 /* Union for contents of an Element (string, list, or link). */
0
 union Contents {
0
     char *str;
0
- struct Link link;
0
+ struct Link *link;
0
 };
0
 
0
 /* Types of semantic values returned by parsers. */

Comments

    No one has commented yet.