rpeg-multimarkdown 0.1.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.markdown +7 -4
- data/Rakefile +3 -3
- data/bin/rpeg-multimarkdown +7 -7
- data/ext/extconf.rb +2 -2
- data/ext/markdown.c +14 -0
- data/ext/markdown_lib.c +72 -18
- data/ext/markdown_lib.h +18 -8
- data/ext/markdown_output.c +187 -58
- data/ext/markdown_parser.c +8315 -6224
- data/ext/markdown_peg.h +5 -4
- data/ext/odf.c +7 -1
- data/ext/odf.h +8 -0
- data/ext/parsing_functions.c +42 -2
- data/ext/parsing_functions.h +17 -0
- data/ext/utility_functions.c +60 -56
- data/ext/utility_functions.h +93 -0
- data/lib/peg_multimarkdown.rb +16 -16
- data/test/MultiMarkdownTest/BeamerTests/Beamer-Tables.tex +2 -2
- data/test/MultiMarkdownTest/CompatibilityTests/Automatic Labels.html +35 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Automatic Labels.text +45 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Base Header Level.html +14 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Base Header Level.text +16 -0
- data/test/MultiMarkdownTest/CompatibilityTests/BibTeX.html +9 -0
- data/test/MultiMarkdownTest/CompatibilityTests/BibTeX.text +10 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Citations.html +40 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Citations.text +42 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Definition Lists.html +40 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Definition Lists.text +39 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Dutch.html +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Dutch.text +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Email.html +40 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Email.text +31 -0
- data/test/MultiMarkdownTest/CompatibilityTests/English.html +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/English.text +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Errors.html +9 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Errors.text +11 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Footnotes.html +23 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Footnotes.text +25 -0
- data/test/MultiMarkdownTest/CompatibilityTests/French.html +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/French.text +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/German.html +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/German.text +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/GermanGuillemets.html +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/GermanGuillemets.text +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Glossary.html +29 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Glossary.text +28 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Headers.html +42 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Headers.text +51 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Line Breaks.html +13 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Line Breaks.text +15 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Link Attributes.html +35 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Link Attributes.text +51 -0
- data/test/MultiMarkdownTest/CompatibilityTests/List Parsing.html +13 -0
- data/test/MultiMarkdownTest/CompatibilityTests/List Parsing.text +11 -0
- data/test/MultiMarkdownTest/CompatibilityTests/MarkdownInHTML.html +13 -0
- data/test/MultiMarkdownTest/CompatibilityTests/MarkdownInHTML.text +19 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Math.html +14 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Math.text +15 -0
- data/test/MultiMarkdownTest/CompatibilityTests/MetaData.html +14 -0
- data/test/MultiMarkdownTest/CompatibilityTests/MetaData.text +14 -0
- data/test/MultiMarkdownTest/CompatibilityTests/NotMetaData.html +3 -0
- data/test/MultiMarkdownTest/CompatibilityTests/NotMetaData.text +4 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Sanity.html +77 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Sanity.text +77 -0
- data/test/MultiMarkdownTest/CompatibilityTests/SmartQuotes.html +22 -0
- data/test/MultiMarkdownTest/CompatibilityTests/SmartQuotes.text +22 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Swedish.html +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Swedish.text +17 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Tables.html +65 -0
- data/test/MultiMarkdownTest/CompatibilityTests/Tables.text +71 -0
- data/test/MultiMarkdownTest/MemoirTests/Definition Lists.tex +5 -10
- data/test/MultiMarkdownTest/MemoirTests/Sanity.tex +2 -2
- data/test/MultiMarkdownTest/MemoirTests/Tables.tex +10 -10
- data/test/MultiMarkdownTest/MultiMarkdownTests/Automatic Labels.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Base Header Level.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/BibTeX.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Citations.html +6 -4
- data/test/MultiMarkdownTest/MultiMarkdownTests/Definition Lists.html +9 -12
- data/test/MultiMarkdownTest/MultiMarkdownTests/Definition Lists.tex +5 -10
- data/test/MultiMarkdownTest/MultiMarkdownTests/Dutch.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Email.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/English.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Errors.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Footnotes.html +7 -5
- data/test/MultiMarkdownTest/MultiMarkdownTests/French.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/German.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/GermanGuillemets.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Glossary.html +6 -4
- data/test/MultiMarkdownTest/MultiMarkdownTests/Headers.html +6 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Headers.tex +2 -0
- data/test/MultiMarkdownTest/MultiMarkdownTests/Headers.text +2 -0
- data/test/MultiMarkdownTest/MultiMarkdownTests/Line Breaks.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Link Attributes.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/List Parsing.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/MarkdownInHTML.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Math.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/MetaData.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/NotMetaData.html +3 -0
- data/test/MultiMarkdownTest/MultiMarkdownTests/NotMetaData.tex +3 -0
- data/test/MultiMarkdownTest/MultiMarkdownTests/NotMetaData.text +4 -0
- data/test/MultiMarkdownTest/MultiMarkdownTests/Sanity.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Sanity.tex +2 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/SmartQuotes.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Swedish.html +4 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Tables.html +45 -2
- data/test/MultiMarkdownTest/MultiMarkdownTests/Tables.tex +32 -10
- data/test/MultiMarkdownTest/MultiMarkdownTests/Tables.text +8 -0
- data/test/multimarkdown_test.rb +5 -5
- metadata +92 -50
data/ext/markdown_peg.h
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
/* markdown_peg.h */
|
2
|
-
#
|
3
|
-
#
|
2
|
+
#ifndef MARKDOWN_PEG_H
|
3
|
+
#define MARKDOWN_PEG_H
|
4
4
|
|
5
|
-
|
5
|
+
#include "markdown_lib.h"
|
6
|
+
#include "glib.h"
|
6
7
|
|
7
8
|
/* Information (label, URL and title) for a link. */
|
8
9
|
struct Link {
|
@@ -133,10 +134,10 @@ void free_element_list(element * elt);
|
|
133
134
|
void free_element(element *elt);
|
134
135
|
void print_element_list(GString *out, element *elt, int format, int exts);
|
135
136
|
|
136
|
-
|
137
137
|
element * parse_metadata_only(char *string, int extensions);
|
138
138
|
char * extract_metadata_value(char *text, int extensions, char *key);
|
139
139
|
|
140
140
|
char * metavalue_for_key(char *key, element *list);
|
141
141
|
|
142
142
|
element * parse_markdown_for_opml(char *string, int extensions);
|
143
|
+
#endif
|
data/ext/odf.c
CHANGED
@@ -14,6 +14,8 @@
|
|
14
14
|
|
15
15
|
***********************************************************************/
|
16
16
|
|
17
|
+
#include "odf.h"
|
18
|
+
|
17
19
|
|
18
20
|
void print_odf_header(GString *out){
|
19
21
|
|
@@ -99,7 +101,7 @@ void print_odf_header(GString *out){
|
|
99
101
|
" style:class=\"html\">\n" \
|
100
102
|
" <style:paragraph-properties fo:margin-left=\"0.3937in\" fo:margin-right=\"0.3937in\" fo:margin-top=\"0in\"\n" \
|
101
103
|
" fo:margin-bottom=\"0.1965in\"\n" \
|
102
|
-
" fo:text-align=\"justify\"" \
|
104
|
+
" fo:text-align=\"justify\"" \
|
103
105
|
" style:justify-single-word=\"false\"" \
|
104
106
|
" fo:text-indent=\"0in\"\n" \
|
105
107
|
" style:auto-text-indent=\"false\"/>\n" \
|
@@ -130,6 +132,10 @@ void print_odf_header(GString *out){
|
|
130
132
|
" style:join-border=\"false\"/>\n" \
|
131
133
|
" <style:text-properties fo:font-size=\"6pt\" style:font-size-asian=\"6pt\" style:font-size-complex=\"6pt\"/>\n" \
|
132
134
|
"</style:style>\n" \
|
135
|
+
"<style:style style:name=\"Footnote_20_anchor\" style:display-name=\"Footnote anchor\"" \
|
136
|
+
" style:family=\"text\">" \
|
137
|
+
" <style:text-properties style:text-position=\"super 58%\"/>" \
|
138
|
+
" </style:style>" \
|
133
139
|
"</office:styles>\n");
|
134
140
|
|
135
141
|
/* Automatic style information */
|
data/ext/odf.h
CHANGED
data/ext/parsing_functions.c
CHANGED
@@ -1,7 +1,25 @@
|
|
1
1
|
/* parsing_functions.c - Functions for parsing markdown and
|
2
2
|
* freeing element lists. */
|
3
3
|
|
4
|
-
|
4
|
+
/* These yy_* functions come from markdown_parser.c which is
|
5
|
+
* generated from markdown_parser.leg
|
6
|
+
* */
|
7
|
+
typedef int (*yyrule)();
|
8
|
+
|
9
|
+
extern int yyparse();
|
10
|
+
extern int yyparsefrom(yyrule);
|
11
|
+
extern int yy_References();
|
12
|
+
extern int yy_Notes();
|
13
|
+
extern int yy_Doc();
|
14
|
+
|
15
|
+
extern int yy_AutoLabels();
|
16
|
+
extern int yy_DocWithMetaData();
|
17
|
+
extern int yy_MetaDataOnly();
|
18
|
+
extern int yy_DocForOPML();
|
19
|
+
|
20
|
+
#include "utility_functions.h"
|
21
|
+
#include "parsing_functions.h"
|
22
|
+
#include "markdown_peg.h"
|
5
23
|
|
6
24
|
static void free_element_contents(element elt);
|
7
25
|
|
@@ -41,6 +59,11 @@ static void free_element_contents(element elt) {
|
|
41
59
|
case GLOSSARY:
|
42
60
|
case GLOSSARYTERM:
|
43
61
|
case NOTELABEL:
|
62
|
+
case CELLSPAN:
|
63
|
+
case EMDASH:
|
64
|
+
case ENDASH:
|
65
|
+
case GLOSSARYSORTKEY:
|
66
|
+
case MATHSPAN:
|
44
67
|
free(elt.contents.str);
|
45
68
|
elt.contents.str = NULL;
|
46
69
|
break;
|
@@ -129,6 +152,12 @@ element * parse_markdown(char *string, int extensions, element *reference_list,
|
|
129
152
|
yyparsefrom(yy_Doc);
|
130
153
|
|
131
154
|
charbuf = oldcharbuf; /* restore charbuf to original value */
|
155
|
+
|
156
|
+
/* if (parse_aborted) {
|
157
|
+
free_element_list(parse_result);
|
158
|
+
return NULL;
|
159
|
+
}*/
|
160
|
+
|
132
161
|
return parse_result;
|
133
162
|
|
134
163
|
}
|
@@ -144,9 +173,20 @@ element * parse_markdown_with_metadata(char *string, int extensions, element *re
|
|
144
173
|
oldcharbuf = charbuf;
|
145
174
|
charbuf = string;
|
146
175
|
|
147
|
-
|
176
|
+
start_time = clock();
|
148
177
|
|
178
|
+
yyparsefrom(yy_DocWithMetaData);
|
149
179
|
charbuf = oldcharbuf; /* restore charbuf to original value */
|
180
|
+
|
181
|
+
/* reset start_time for subsequent passes */
|
182
|
+
start_time = 0;
|
183
|
+
|
184
|
+
if (parse_aborted) {
|
185
|
+
parse_aborted = 0;
|
186
|
+
free_element_list(parse_result);
|
187
|
+
return NULL;
|
188
|
+
}
|
189
|
+
|
150
190
|
return parse_result;
|
151
191
|
|
152
192
|
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#ifndef PARSING_FUNCTIONS_H
|
2
|
+
#define PARSING_FUNCTIONS_H
|
3
|
+
/* parsing_functions.c - Functions for parsing markdown and
|
4
|
+
* freeing element lists. */
|
5
|
+
|
6
|
+
#include "markdown_peg.h"
|
7
|
+
|
8
|
+
/* free_element_list - free list of elements recursively */
|
9
|
+
void free_element_list(element * elt);
|
10
|
+
/* free_element - free element and contents */
|
11
|
+
void free_element(element *elt);
|
12
|
+
|
13
|
+
element * parse_references(char *string, int extensions);
|
14
|
+
element * parse_notes(char *string, int extensions, element *reference_list);
|
15
|
+
element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list, element *label_list);
|
16
|
+
|
17
|
+
#endif
|
data/ext/utility_functions.c
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
/* utility_functions.c - List manipulation functions, element
|
2
2
|
* constructors, and macro definitions for leg markdown parser. */
|
3
3
|
|
4
|
-
|
4
|
+
#include "utility_functions.h"
|
5
|
+
#include "markdown_peg.h"
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
#include <string.h>
|
8
|
+
#include <assert.h>
|
8
9
|
|
9
|
-
static void print_raw_element_list(GString *out, element *list);
|
10
10
|
|
11
11
|
/**********************************************************************
|
12
12
|
|
@@ -15,14 +15,14 @@ static void print_raw_element_list(GString *out, element *list);
|
|
15
15
|
***********************************************************************/
|
16
16
|
|
17
17
|
/* cons - cons an element onto a list, returning pointer to new head */
|
18
|
-
|
18
|
+
element * cons(element *new, element *list) {
|
19
19
|
assert(new != NULL);
|
20
20
|
new->next = list;
|
21
21
|
return new;
|
22
22
|
}
|
23
23
|
|
24
24
|
/* reverse - reverse a list, returning pointer to new list */
|
25
|
-
|
25
|
+
element *reverse(element *list) {
|
26
26
|
element *new = NULL;
|
27
27
|
element *next = NULL;
|
28
28
|
while (list != NULL) {
|
@@ -34,7 +34,7 @@ static element *reverse(element *list) {
|
|
34
34
|
}
|
35
35
|
|
36
36
|
/* append_list - add element to end of list */
|
37
|
-
|
37
|
+
void append_list(element *new, element *list) {
|
38
38
|
assert(new != NULL);
|
39
39
|
element *step = list;
|
40
40
|
|
@@ -48,7 +48,7 @@ static void append_list(element *new, element *list) {
|
|
48
48
|
|
49
49
|
/* concat_string_list - concatenates string contents of list of STR elements.
|
50
50
|
* Frees STR elements as they are added to the concatenation. */
|
51
|
-
|
51
|
+
GString *concat_string_list(element *list) {
|
52
52
|
GString *result;
|
53
53
|
element *next;
|
54
54
|
result = g_string_new("");
|
@@ -69,13 +69,16 @@ static GString *concat_string_list(element *list) {
|
|
69
69
|
|
70
70
|
***********************************************************************/
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
|
73
|
+
char *charbuf = ""; /* Buffer of characters to be parsed. */
|
74
|
+
element *references = NULL; /* List of link references found. */
|
75
|
+
element *notes = NULL; /* List of footnotes found. */
|
76
|
+
element *parse_result; /* Results of parse. */
|
76
77
|
int syntax_extensions; /* Syntax extensions selected. */
|
77
78
|
|
78
|
-
|
79
|
+
element *labels = NULL; /* List of labels found in document. */
|
80
|
+
clock_t start_time = 0; /* Used for ensuring we're not stuck in a loop */
|
81
|
+
bool parse_aborted = 0; /* flag indicating we ran out of time */
|
79
82
|
|
80
83
|
/**********************************************************************
|
81
84
|
|
@@ -86,7 +89,7 @@ static element *labels = NULL; /* List of labels found in document. */
|
|
86
89
|
***********************************************************************/
|
87
90
|
|
88
91
|
/* mk_element - generic constructor for element */
|
89
|
-
|
92
|
+
element * mk_element(int key) {
|
90
93
|
element *result = malloc(sizeof(element));
|
91
94
|
result->key = key;
|
92
95
|
result->children = NULL;
|
@@ -96,7 +99,7 @@ static element * mk_element(int key) {
|
|
96
99
|
}
|
97
100
|
|
98
101
|
/* mk_str - constructor for STR element */
|
99
|
-
|
102
|
+
element * mk_str(char *string) {
|
100
103
|
element *result;
|
101
104
|
assert(string != NULL);
|
102
105
|
result = mk_element(STR);
|
@@ -106,7 +109,7 @@ static element * mk_str(char *string) {
|
|
106
109
|
|
107
110
|
/* mk_str_from_list - makes STR element by concatenating a
|
108
111
|
* reversed list of strings, adding optional extra newline */
|
109
|
-
|
112
|
+
element * mk_str_from_list(element *list, bool extra_newline) {
|
110
113
|
element *result;
|
111
114
|
GString *c = concat_string_list(reverse(list));
|
112
115
|
if (extra_newline)
|
@@ -120,7 +123,7 @@ static element * mk_str_from_list(element *list, bool extra_newline) {
|
|
120
123
|
/* mk_list - makes new list with key 'key' and children the reverse of 'lst'.
|
121
124
|
* This is designed to be used with cons to build lists in a parser action.
|
122
125
|
* The reversing is necessary because cons adds to the head of a list. */
|
123
|
-
|
126
|
+
element * mk_list(int key, element *lst) {
|
124
127
|
element *result;
|
125
128
|
result = mk_element(key);
|
126
129
|
result->children = reverse(lst);
|
@@ -128,7 +131,7 @@ static element * mk_list(int key, element *lst) {
|
|
128
131
|
}
|
129
132
|
|
130
133
|
/* mk_link - constructor for LINK element */
|
131
|
-
|
134
|
+
element * mk_link(element *label, char *url, char *title, element *attr, char *id) {
|
132
135
|
element *result;
|
133
136
|
result = mk_element(LINK);
|
134
137
|
result->contents.link = malloc(sizeof(link));
|
@@ -141,12 +144,12 @@ static element * mk_link(element *label, char *url, char *title, element *attr,
|
|
141
144
|
}
|
142
145
|
|
143
146
|
/* extension = returns true if extension is selected */
|
144
|
-
|
147
|
+
bool extension(int ext) {
|
145
148
|
return (syntax_extensions & ext);
|
146
149
|
}
|
147
150
|
|
148
151
|
/* match_inlines - returns true if inline lists match (case-insensitive...) */
|
149
|
-
|
152
|
+
bool match_inlines(element *l1, element *l2) {
|
150
153
|
while (l1 != NULL && l2 != NULL) {
|
151
154
|
if (l1->key != l2->key)
|
152
155
|
return false;
|
@@ -190,7 +193,7 @@ static bool match_inlines(element *l1, element *l2) {
|
|
190
193
|
|
191
194
|
/* find_reference - return true if link found in references matching label.
|
192
195
|
* 'link' is modified with the matching url and title. */
|
193
|
-
|
196
|
+
bool find_reference(link *result, element *label) {
|
194
197
|
element *cur = references; /* pointer to walk up list of references */
|
195
198
|
link *curitem;
|
196
199
|
while (cur != NULL) {
|
@@ -208,7 +211,7 @@ static bool find_reference(link *result, element *label) {
|
|
208
211
|
/* find_note - return true if note found in notes matching label.
|
209
212
|
if found, 'result' is set to point to matched note. */
|
210
213
|
|
211
|
-
|
214
|
+
bool find_note(element **result, char *label) {
|
212
215
|
element *cur = notes; /* pointer to walk up list of notes */
|
213
216
|
while (cur != NULL) {
|
214
217
|
if (strcmp(label, cur->contents.str) == 0) {
|
@@ -222,36 +225,10 @@ static bool find_note(element **result, char *label) {
|
|
222
225
|
}
|
223
226
|
|
224
227
|
|
225
|
-
|
226
|
-
/**********************************************************************
|
227
|
-
|
228
|
-
Definitions for leg parser generator.
|
229
|
-
YY_INPUT is the function the parser calls to get new input.
|
230
|
-
We take all new input from (static) charbuf.
|
231
|
-
|
232
|
-
***********************************************************************/
|
233
|
-
|
234
|
-
# define YYSTYPE element *
|
235
|
-
#ifdef __DEBUG__
|
236
|
-
# define YY_DEBUG 1
|
237
|
-
#endif
|
238
|
-
|
239
|
-
#define YY_INPUT(buf, result, max_size) \
|
240
|
-
{ \
|
241
|
-
int yyc; \
|
242
|
-
if (charbuf && *charbuf != '\0') { \
|
243
|
-
yyc= *charbuf++; \
|
244
|
-
} else { \
|
245
|
-
yyc= EOF; \
|
246
|
-
} \
|
247
|
-
result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
|
248
|
-
}
|
249
|
-
|
250
|
-
|
251
228
|
/* peg-multimarkdown additions */
|
252
229
|
|
253
230
|
/* print_raw_element - print an element as original text */
|
254
|
-
|
231
|
+
void print_raw_element(GString *out, element *elt) {
|
255
232
|
if (elt->key == LINK) {
|
256
233
|
print_raw_element_list(out,elt->contents.link->label);
|
257
234
|
} else {
|
@@ -264,7 +241,7 @@ static void print_raw_element(GString *out, element *elt) {
|
|
264
241
|
}
|
265
242
|
|
266
243
|
/* print_raw_element_list - print a list of elements as original text */
|
267
|
-
|
244
|
+
void print_raw_element_list(GString *out, element *list) {
|
268
245
|
while (list != NULL) {
|
269
246
|
print_raw_element(out, list);
|
270
247
|
list = list->next;
|
@@ -274,7 +251,7 @@ static void print_raw_element_list(GString *out, element *list) {
|
|
274
251
|
/* label_from_element_list */
|
275
252
|
/* Returns a null-terminated string, which must be freed after use. */
|
276
253
|
|
277
|
-
|
254
|
+
char *label_from_element_list(element *list, bool obfuscate) {
|
278
255
|
char *label;
|
279
256
|
char *label2;
|
280
257
|
GString *raw = g_string_new("");
|
@@ -290,7 +267,7 @@ static char *label_from_element_list(element *list, bool obfuscate) {
|
|
290
267
|
HTML id */
|
291
268
|
/* Returns a null-terminated string, which must be freed after use. */
|
292
269
|
|
293
|
-
|
270
|
+
char *label_from_string(char *str, bool obfuscate) {
|
294
271
|
bool valid = FALSE;
|
295
272
|
GString *out = g_string_new("");
|
296
273
|
char *label;
|
@@ -321,7 +298,7 @@ static char *label_from_string(char *str, bool obfuscate) {
|
|
321
298
|
|
322
299
|
/* find_label - return true if header, table, etc is found matching label.
|
323
300
|
* 'link' is modified with the matching url and title. */
|
324
|
-
|
301
|
+
bool find_label(link *result, element *label) {
|
325
302
|
char *lab;
|
326
303
|
element *cur = labels; /* pointer to walk up list of references */
|
327
304
|
GString *text = g_string_new("");
|
@@ -347,7 +324,7 @@ static bool find_label(link *result, element *label) {
|
|
347
324
|
/* localize_typography - return the proper string, based on language chosen */
|
348
325
|
/* Default action is English */
|
349
326
|
|
350
|
-
|
327
|
+
void localize_typography(GString *out, int character, int lang, int output) {
|
351
328
|
|
352
329
|
switch (output) {
|
353
330
|
case HTMLOUT:
|
@@ -525,11 +502,38 @@ static void localize_typography(GString *out, int character, int lang, int outpu
|
|
525
502
|
}
|
526
503
|
|
527
504
|
/* Trim spaces at end of string */
|
528
|
-
|
505
|
+
void trim_trailing_whitespace(char *str) {
|
529
506
|
while ( ( str[strlen(str)-1] == ' ' ) ||
|
530
507
|
( str[strlen(str)-1] == '\n' ) ||
|
531
508
|
( str[strlen(str)-1] == '\r' ) ||
|
532
509
|
( str[strlen(str)-1] == '\t' ) ) {
|
533
510
|
str[strlen(str)-1] = '\0';
|
534
511
|
}
|
535
|
-
}
|
512
|
+
}
|
513
|
+
|
514
|
+
/* Don't let us get caught in "infinite" loop */
|
515
|
+
bool check_timeout() {
|
516
|
+
/* Once we abort, keep aborting */
|
517
|
+
if (parse_aborted)
|
518
|
+
return 0;
|
519
|
+
|
520
|
+
/* We're not timing this run */
|
521
|
+
if (start_time == 0)
|
522
|
+
return 1;
|
523
|
+
|
524
|
+
clock_t end = clock();
|
525
|
+
double elapsed = ((double) (end - start_time)) / CLOCKS_PER_SEC;
|
526
|
+
|
527
|
+
/* fprintf(stderr,"%2.2f elapsed; (%4.2f CLOCKS_PER_SEC)\n",elapsed,CLOCKS_PER_SEC); */
|
528
|
+
/* fprintf(stderr,"%2.2f elapsed\n",elapsed); */
|
529
|
+
|
530
|
+
|
531
|
+
/* If > 3 clock seconds, then abort */
|
532
|
+
float max = 3;
|
533
|
+
if (elapsed > max) {
|
534
|
+
parse_aborted = 1;
|
535
|
+
return 0;
|
536
|
+
}
|
537
|
+
return 1;
|
538
|
+
}
|
539
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#ifndef UTILITY_FUNCTIONS_H
|
2
|
+
#define UTILITY_FUNCTIONS_H
|
3
|
+
|
4
|
+
#include <stdbool.h>
|
5
|
+
#include <glib.h>
|
6
|
+
|
7
|
+
#include "markdown_peg.h"
|
8
|
+
|
9
|
+
#include <time.h>
|
10
|
+
|
11
|
+
/* utility_functions.h - List manipulation functions, element
|
12
|
+
* constructors, and macro definitions for leg markdown parser. */
|
13
|
+
|
14
|
+
|
15
|
+
/* cons - cons an element onto a list, returning pointer to new head */
|
16
|
+
element * cons(element *new, element *list);
|
17
|
+
|
18
|
+
/* reverse - reverse a list, returning pointer to new list */
|
19
|
+
element *reverse(element *list);
|
20
|
+
/* concat_string_list - concatenates string contents of list of STR elements.
|
21
|
+
* Frees STR elements as they are added to the concatenation. */
|
22
|
+
GString *concat_string_list(element *list);
|
23
|
+
/**********************************************************************
|
24
|
+
|
25
|
+
Global variables used in parsing
|
26
|
+
|
27
|
+
***********************************************************************/
|
28
|
+
|
29
|
+
extern char *charbuf; /* Buffer of characters to be parsed. */
|
30
|
+
extern element *references; /* List of link references found. */
|
31
|
+
extern element *notes; /* List of footnotes found. */
|
32
|
+
extern element *parse_result; /* Results of parse. */
|
33
|
+
extern int syntax_extensions; /* Syntax extensions selected. */
|
34
|
+
|
35
|
+
|
36
|
+
extern element *labels; /* List of labels found in document. */
|
37
|
+
extern clock_t start_time; /* Used for ensuring we're not stuck in a loop */
|
38
|
+
extern bool parse_aborted; /* flag indicating we ran out of time */
|
39
|
+
|
40
|
+
/**********************************************************************
|
41
|
+
|
42
|
+
Auxiliary functions for parsing actions.
|
43
|
+
These make it easier to build up data structures (including lists)
|
44
|
+
in the parsing actions.
|
45
|
+
|
46
|
+
***********************************************************************/
|
47
|
+
|
48
|
+
/* mk_element - generic constructor for element */
|
49
|
+
element * mk_element(int key);
|
50
|
+
|
51
|
+
/* mk_str - constructor for STR element */
|
52
|
+
element * mk_str(char *string);
|
53
|
+
|
54
|
+
/* mk_str_from_list - makes STR element by concatenating a
|
55
|
+
* reversed list of strings, adding optional extra newline */
|
56
|
+
element * mk_str_from_list(element *list, bool extra_newline);
|
57
|
+
|
58
|
+
/* mk_list - makes new list with key 'key' and children the reverse of 'lst'.
|
59
|
+
* This is designed to be used with cons to build lists in a parser action.
|
60
|
+
* The reversing is necessary because cons adds to the head of a list. */
|
61
|
+
element * mk_list(int key, element *lst);
|
62
|
+
|
63
|
+
/* mk_link - constructor for LINK element */
|
64
|
+
element * mk_link(element *label, char *url, char *title, element *attr, char *id);
|
65
|
+
/* extension = returns true if extension is selected */
|
66
|
+
bool extension(int ext);
|
67
|
+
|
68
|
+
/* match_inlines - returns true if inline lists match (case-insensitive...) */
|
69
|
+
bool match_inlines(element *l1, element *l2);
|
70
|
+
|
71
|
+
/* find_reference - return true if link found in references matching label.
|
72
|
+
* 'link' is modified with the matching url and title. */
|
73
|
+
bool find_reference(link *result, element *label);
|
74
|
+
|
75
|
+
/* find_note - return true if note found in notes matching label.
|
76
|
+
if found, 'result' is set to point to matched note. */
|
77
|
+
|
78
|
+
bool find_note(element **result, char *label);
|
79
|
+
|
80
|
+
|
81
|
+
char *label_from_string(char *str, bool obfuscate);
|
82
|
+
void localize_typography(GString *out, int character, int language, int output);
|
83
|
+
void print_raw_element_list(GString *out, element *list);
|
84
|
+
void append_list(element *new, element *list);
|
85
|
+
bool find_label(link *result, element *label);
|
86
|
+
bool check_timeout();
|
87
|
+
void trim_trailing_whitespace(char *str);
|
88
|
+
char *label_from_element_list(element *list, bool obfuscate);
|
89
|
+
void print_raw_element_list(GString *out, element *list);
|
90
|
+
void print_raw_element(GString *out, element *elt);
|
91
|
+
|
92
|
+
#endif
|
93
|
+
|