public
Description: An implementation of markdown in C, using a PEG grammar
Clone URL: git://github.com/jgm/peg-markdown.git
Moved process_raw_blocks to before markdown_to_g_string.
jgm (author)
Tue Jun 17 09:34:10 -0700 2008
commit  fca315bee8d776685ea7e809137aee301e2a7821
tree    4892acd40f0972a39a82e84730a1ffb870bd4bb1
parent  0f752d078700c674fcc2ab5a2182084d01805dbf
...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
153
154
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
157
158
...
91
92
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
95
96
...
124
125
126
127
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
153
154
155
156
0
@@ -91,35 +91,6 @@ static void print_tree(element * elt, int indent) {
0
     }
0
 }
0
 
0
-static element * process_raw_blocks(element *input, int extensions, element *references, element *notes);
0
-
0
-/* markdown_to_gstring - convert markdown text to the output format specified.
0
- * Returns a GString, which must be freed after use using g_string_free(). */
0
-GString * markdown_to_g_string(char *text, int extensions, int output_format) {
0
- element *result;
0
- element *references;
0
- element *notes;
0
- GString *formatted_text;
0
- GString *out;
0
- out = g_string_new("");
0
-
0
- formatted_text = preformat_text(text);
0
-
0
- references = parse_references(formatted_text->str, extensions);
0
- notes = parse_notes(formatted_text->str, extensions, references);
0
- result = parse_markdown(formatted_text->str, extensions, references, notes);
0
-
0
- result = process_raw_blocks(result, extensions, references, notes);
0
-
0
- g_string_free(formatted_text, TRUE);
0
-
0
- print_element_list(out, result, output_format, extensions);
0
-
0
- free_element_list(result);
0
- free_element_list(references);
0
- return out;
0
-}
0
-
0
 /* process_raw_blocks - traverses an element list, replacing any RAW elements with
0
  * the result of parsing them as markdown text, and recursing into the children
0
  * of parent elements. The result should be a tree of elements without any RAWs. */
0
@@ -153,6 +124,33 @@ static element * process_raw_blocks(element *input, int extensions, element *ref
0
     return input;
0
 }
0
 
0
+/* markdown_to_gstring - convert markdown text to the output format specified.
0
+ * Returns a GString, which must be freed after use using g_string_free(). */
0
+GString * markdown_to_g_string(char *text, int extensions, int output_format) {
0
+ element *result;
0
+ element *references;
0
+ element *notes;
0
+ GString *formatted_text;
0
+ GString *out;
0
+ out = g_string_new("");
0
+
0
+ formatted_text = preformat_text(text);
0
+
0
+ references = parse_references(formatted_text->str, extensions);
0
+ notes = parse_notes(formatted_text->str, extensions, references);
0
+ result = parse_markdown(formatted_text->str, extensions, references, notes);
0
+
0
+ result = process_raw_blocks(result, extensions, references, notes);
0
+
0
+ g_string_free(formatted_text, TRUE);
0
+
0
+ print_element_list(out, result, output_format, extensions);
0
+
0
+ free_element_list(result);
0
+ free_element_list(references);
0
+ return out;
0
+}
0
+
0
 /* markdown_to_string - convert markdown text to the output format specified.
0
  * Returns a null-terminated string, which must be freed after use. */
0
 char * markdown_to_string(char *text, int extensions, int output_format) {

Comments

    No one has commented yet.