parkdown 1.4.28
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/LICENSE +68 -0
- data/README.markdown +86 -0
- data/Rakefile +170 -0
- data/bin/parkdown +13 -0
- data/ext/extconf.h +3 -0
- data/ext/extconf.rb +15 -0
- data/ext/markdown.c +104 -0
- data/ext/markdown_lib.c +186 -0
- data/ext/markdown_lib.h +44 -0
- data/ext/markdown_output.c +1275 -0
- data/ext/markdown_parser.c +7275 -0
- data/ext/markdown_peg.h +90 -0
- data/ext/parsing_functions.c +128 -0
- data/ext/utility_functions.c +217 -0
- data/lib/markdown.rb +1 -0
- data/lib/peg_markdown.rb +104 -0
- data/test/MarkdownTest_1.0/MarkdownTest.pl +157 -0
- data/test/MarkdownTest_1.0/Tests/Amps and angle encoding.html +17 -0
- data/test/MarkdownTest_1.0/Tests/Amps and angle encoding.text +21 -0
- data/test/MarkdownTest_1.0/Tests/Auto links.html +18 -0
- data/test/MarkdownTest_1.0/Tests/Auto links.text +13 -0
- data/test/MarkdownTest_1.0/Tests/Backslash escapes.html +102 -0
- data/test/MarkdownTest_1.0/Tests/Backslash escapes.text +104 -0
- data/test/MarkdownTest_1.0/Tests/Blockquotes with code blocks.html +15 -0
- data/test/MarkdownTest_1.0/Tests/Blockquotes with code blocks.text +11 -0
- data/test/MarkdownTest_1.0/Tests/Hard-wrapped paragraphs with list-like lines.html +8 -0
- data/test/MarkdownTest_1.0/Tests/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/test/MarkdownTest_1.0/Tests/Horizontal rules.html +71 -0
- data/test/MarkdownTest_1.0/Tests/Horizontal rules.text +67 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML (Advanced).html +14 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML (Advanced).text +14 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML (Simple).html +72 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML (Simple).text +69 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML comments.html +13 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML comments.text +13 -0
- data/test/MarkdownTest_1.0/Tests/Links, inline style.html +9 -0
- data/test/MarkdownTest_1.0/Tests/Links, inline style.text +9 -0
- data/test/MarkdownTest_1.0/Tests/Links, reference style.html +18 -0
- data/test/MarkdownTest_1.0/Tests/Links, reference style.text +31 -0
- data/test/MarkdownTest_1.0/Tests/Literal quotes in titles.html +3 -0
- data/test/MarkdownTest_1.0/Tests/Literal quotes in titles.text +7 -0
- data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Basics.html +314 -0
- data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Basics.text +306 -0
- data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Syntax.html +942 -0
- data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Syntax.text +888 -0
- data/test/MarkdownTest_1.0/Tests/Nested blockquotes.html +9 -0
- data/test/MarkdownTest_1.0/Tests/Nested blockquotes.text +5 -0
- data/test/MarkdownTest_1.0/Tests/Ordered and unordered lists.html +137 -0
- data/test/MarkdownTest_1.0/Tests/Ordered and unordered lists.text +122 -0
- data/test/MarkdownTest_1.0/Tests/Strong and em together.html +7 -0
- data/test/MarkdownTest_1.0/Tests/Strong and em together.text +7 -0
- data/test/MarkdownTest_1.0/Tests/Tabs.html +25 -0
- data/test/MarkdownTest_1.0/Tests/Tabs.text +21 -0
- data/test/MarkdownTest_1.0/Tests/Tidyness.html +8 -0
- data/test/MarkdownTest_1.0/Tests/Tidyness.text +5 -0
- data/test/MarkdownTest_1.0.3/MarkdownTest.pl +176 -0
- data/test/MarkdownTest_1.0.3/Tests/Amps and angle encoding.html +17 -0
- data/test/MarkdownTest_1.0.3/Tests/Amps and angle encoding.text +21 -0
- data/test/MarkdownTest_1.0.3/Tests/Auto links.html +18 -0
- data/test/MarkdownTest_1.0.3/Tests/Auto links.text +13 -0
- data/test/MarkdownTest_1.0.3/Tests/Backslash escapes.html +118 -0
- data/test/MarkdownTest_1.0.3/Tests/Backslash escapes.text +120 -0
- data/test/MarkdownTest_1.0.3/Tests/Blockquotes with code blocks.html +15 -0
- data/test/MarkdownTest_1.0.3/Tests/Blockquotes with code blocks.text +11 -0
- data/test/MarkdownTest_1.0.3/Tests/Code Blocks.html +18 -0
- data/test/MarkdownTest_1.0.3/Tests/Code Blocks.text +14 -0
- data/test/MarkdownTest_1.0.3/Tests/Code Spans.html +6 -0
- data/test/MarkdownTest_1.0.3/Tests/Code Spans.text +6 -0
- data/test/MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.html +8 -0
- data/test/MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/test/MarkdownTest_1.0.3/Tests/Horizontal rules.html +71 -0
- data/test/MarkdownTest_1.0.3/Tests/Horizontal rules.text +67 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Advanced).html +15 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Advanced).text +15 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Simple).html +72 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Simple).text +69 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML comments.html +13 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML comments.text +13 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, inline style.html +11 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, inline style.text +12 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, reference style.html +52 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, reference style.text +71 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, shortcut references.html +9 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, shortcut references.text +20 -0
- data/test/MarkdownTest_1.0.3/Tests/Literal quotes in titles.html +3 -0
- data/test/MarkdownTest_1.0.3/Tests/Literal quotes in titles.text +7 -0
- data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Basics.html +314 -0
- data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Basics.text +306 -0
- data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Syntax.html +942 -0
- data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Syntax.text +888 -0
- data/test/MarkdownTest_1.0.3/Tests/Nested blockquotes.html +9 -0
- data/test/MarkdownTest_1.0.3/Tests/Nested blockquotes.text +5 -0
- data/test/MarkdownTest_1.0.3/Tests/Ordered and unordered lists.html +148 -0
- data/test/MarkdownTest_1.0.3/Tests/Ordered and unordered lists.text +131 -0
- data/test/MarkdownTest_1.0.3/Tests/Strong and em together.html +7 -0
- data/test/MarkdownTest_1.0.3/Tests/Strong and em together.text +7 -0
- data/test/MarkdownTest_1.0.3/Tests/Tabs.html +25 -0
- data/test/MarkdownTest_1.0.3/Tests/Tabs.text +21 -0
- data/test/MarkdownTest_1.0.3/Tests/Tidyness.html +8 -0
- data/test/MarkdownTest_1.0.3/Tests/Tidyness.text +5 -0
- data/test/benchmark.rb +49 -0
- data/test/markdown_test.rb +84 -0
- metadata +150 -0
data/ext/markdown_peg.h
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
/* markdown_peg.h */
|
2
|
+
#ifndef MARKDOWN_PEG_H
|
3
|
+
#define MARKDOWN_PEG_H
|
4
|
+
|
5
|
+
#include "markdown_lib.h"
|
6
|
+
#include <glib.h>
|
7
|
+
|
8
|
+
/* Information (label, URL and title) for a link. */
|
9
|
+
struct Link {
|
10
|
+
struct Element *label;
|
11
|
+
char *url;
|
12
|
+
char *title;
|
13
|
+
};
|
14
|
+
|
15
|
+
typedef struct Link link;
|
16
|
+
|
17
|
+
/* Information (label and two sources) for a media link. */
|
18
|
+
struct Media {
|
19
|
+
struct Element *label;
|
20
|
+
char *source1;
|
21
|
+
char *source2;
|
22
|
+
};
|
23
|
+
|
24
|
+
typedef struct Media media;
|
25
|
+
|
26
|
+
/* Union for contents of an Element (string, list, link, or media). */
|
27
|
+
union Contents {
|
28
|
+
char *str;
|
29
|
+
struct Link *link;
|
30
|
+
struct Media *media;
|
31
|
+
};
|
32
|
+
|
33
|
+
/* Types of semantic values returned by parsers. */
|
34
|
+
enum keys { LIST, /* A generic list of values. For ordered and bullet lists, see below. */
|
35
|
+
RAW, /* Raw markdown to be processed further */
|
36
|
+
SPACE,
|
37
|
+
LINEBREAK,
|
38
|
+
ELLIPSIS,
|
39
|
+
EMDASH,
|
40
|
+
ENDASH,
|
41
|
+
ENSPACE,
|
42
|
+
APOSTROPHE,
|
43
|
+
SINGLEQUOTED,
|
44
|
+
DOUBLEQUOTED,
|
45
|
+
STR,
|
46
|
+
LINK,
|
47
|
+
IMAGE,
|
48
|
+
MEDIA,
|
49
|
+
AUDIO,
|
50
|
+
VIDEO,
|
51
|
+
CODE,
|
52
|
+
HTML,
|
53
|
+
EMPH,
|
54
|
+
STRONG,
|
55
|
+
STRIKE,
|
56
|
+
PLAIN,
|
57
|
+
PARA,
|
58
|
+
LISTITEM,
|
59
|
+
BULLETLIST,
|
60
|
+
ORDEREDLIST,
|
61
|
+
H1, H2, H3, H4, H5, H6, /* Code assumes that these are in order. */
|
62
|
+
BLOCKQUOTE,
|
63
|
+
SPOILERBLOCK,
|
64
|
+
VERBATIM,
|
65
|
+
HASHTAG,
|
66
|
+
USERNAME,
|
67
|
+
HTMLBLOCK,
|
68
|
+
HRULE,
|
69
|
+
REFERENCE,
|
70
|
+
NOTE
|
71
|
+
};
|
72
|
+
|
73
|
+
/* Semantic value of a parsing action. */
|
74
|
+
struct Element {
|
75
|
+
int key;
|
76
|
+
union Contents contents;
|
77
|
+
struct Element *children;
|
78
|
+
struct Element *next;
|
79
|
+
};
|
80
|
+
|
81
|
+
typedef struct Element element;
|
82
|
+
|
83
|
+
element * parse_references(char *string, int extensions);
|
84
|
+
element * parse_notes(char *string, int extensions, element *reference_list);
|
85
|
+
element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list);
|
86
|
+
void free_element_list(element * elt);
|
87
|
+
void free_element(element *elt);
|
88
|
+
void print_element_list(GString *out, element *elt, int format, int exts);
|
89
|
+
|
90
|
+
#endif
|
@@ -0,0 +1,128 @@
|
|
1
|
+
/* parsing_functions.c - Functions for parsing markdown and
|
2
|
+
* freeing element lists. */
|
3
|
+
|
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
|
+
#include "utility_functions.h"
|
16
|
+
#include "parsing_functions.h"
|
17
|
+
#include "markdown_peg.h"
|
18
|
+
|
19
|
+
static void free_element_contents(element elt);
|
20
|
+
|
21
|
+
/* free_element_list - free list of elements recursively */
|
22
|
+
void free_element_list(element * elt) {
|
23
|
+
element * next = NULL;
|
24
|
+
while (elt != NULL) {
|
25
|
+
next = elt->next;
|
26
|
+
free_element_contents(*elt);
|
27
|
+
if (elt->children != NULL) {
|
28
|
+
free_element_list(elt->children);
|
29
|
+
elt->children = NULL;
|
30
|
+
}
|
31
|
+
free(elt);
|
32
|
+
elt = next;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
/* free_element_contents - free element contents depending on type */
|
37
|
+
static void free_element_contents(element elt) {
|
38
|
+
switch (elt.key) {
|
39
|
+
case STR:
|
40
|
+
case SPACE:
|
41
|
+
case RAW:
|
42
|
+
case HTMLBLOCK:
|
43
|
+
case HTML:
|
44
|
+
case VERBATIM:
|
45
|
+
case CODE:
|
46
|
+
case NOTE:
|
47
|
+
free(elt.contents.str);
|
48
|
+
elt.contents.str = NULL;
|
49
|
+
break;
|
50
|
+
case LINK:
|
51
|
+
case IMAGE:
|
52
|
+
case REFERENCE:
|
53
|
+
free(elt.contents.link->url);
|
54
|
+
elt.contents.link->url = NULL;
|
55
|
+
free(elt.contents.link->title);
|
56
|
+
elt.contents.link->title = NULL;
|
57
|
+
free_element_list(elt.contents.link->label);
|
58
|
+
free(elt.contents.link);
|
59
|
+
elt.contents.link = NULL;
|
60
|
+
break;
|
61
|
+
case MEDIA:
|
62
|
+
case AUDIO:
|
63
|
+
case VIDEO:
|
64
|
+
free(elt.contents.media->source1);
|
65
|
+
elt.contents.media->source1 = NULL;
|
66
|
+
free(elt.contents.media->source2);
|
67
|
+
elt.contents.media->source2 = NULL;
|
68
|
+
free_element_list(elt.contents.media->label);
|
69
|
+
free(elt.contents.media);
|
70
|
+
elt.contents.media = NULL;
|
71
|
+
break;
|
72
|
+
default:
|
73
|
+
;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
/* free_element - free element and contents */
|
78
|
+
void free_element(element *elt) {
|
79
|
+
free_element_contents(*elt);
|
80
|
+
free(elt);
|
81
|
+
}
|
82
|
+
|
83
|
+
element * parse_references(char *string, int extensions) {
|
84
|
+
|
85
|
+
char *oldcharbuf;
|
86
|
+
syntax_extensions = extensions;
|
87
|
+
|
88
|
+
oldcharbuf = charbuf;
|
89
|
+
charbuf = string;
|
90
|
+
yyparsefrom(yy_References); /* first pass, just to collect references */
|
91
|
+
charbuf = oldcharbuf;
|
92
|
+
|
93
|
+
return references;
|
94
|
+
}
|
95
|
+
|
96
|
+
element * parse_notes(char *string, int extensions, element *reference_list) {
|
97
|
+
|
98
|
+
char *oldcharbuf;
|
99
|
+
notes = NULL;
|
100
|
+
syntax_extensions = extensions;
|
101
|
+
|
102
|
+
if (extension(EXT_NOTES)) {
|
103
|
+
references = reference_list;
|
104
|
+
oldcharbuf = charbuf;
|
105
|
+
charbuf = string;
|
106
|
+
yyparsefrom(yy_Notes); /* second pass for notes */
|
107
|
+
charbuf = oldcharbuf;
|
108
|
+
}
|
109
|
+
|
110
|
+
return notes;
|
111
|
+
}
|
112
|
+
|
113
|
+
element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list) {
|
114
|
+
|
115
|
+
char *oldcharbuf;
|
116
|
+
syntax_extensions = extensions;
|
117
|
+
references = reference_list;
|
118
|
+
notes = note_list;
|
119
|
+
|
120
|
+
oldcharbuf = charbuf;
|
121
|
+
charbuf = string;
|
122
|
+
|
123
|
+
yyparsefrom(yy_Doc);
|
124
|
+
|
125
|
+
charbuf = oldcharbuf; /* restore charbuf to original value */
|
126
|
+
return parse_result;
|
127
|
+
|
128
|
+
}
|
@@ -0,0 +1,217 @@
|
|
1
|
+
/* utility_functions.c - List manipulation functions, element
|
2
|
+
* constructors, and macro definitions for leg markdown parser. */
|
3
|
+
|
4
|
+
#include "utility_functions.h"
|
5
|
+
#include "markdown_peg.h"
|
6
|
+
|
7
|
+
#include <string.h>
|
8
|
+
#include <assert.h>
|
9
|
+
|
10
|
+
|
11
|
+
/**********************************************************************
|
12
|
+
|
13
|
+
List manipulation functions
|
14
|
+
|
15
|
+
***********************************************************************/
|
16
|
+
|
17
|
+
/* cons - cons an element onto a list, returning pointer to new head */
|
18
|
+
element * cons(element *new, element *list) {
|
19
|
+
assert(new != NULL);
|
20
|
+
new->next = list;
|
21
|
+
return new;
|
22
|
+
}
|
23
|
+
|
24
|
+
/* reverse - reverse a list, returning pointer to new list */
|
25
|
+
element *reverse(element *list) {
|
26
|
+
element *new = NULL;
|
27
|
+
element *next = NULL;
|
28
|
+
while (list != NULL) {
|
29
|
+
next = list->next;
|
30
|
+
new = cons(list, new);
|
31
|
+
list = next;
|
32
|
+
}
|
33
|
+
return new;
|
34
|
+
}
|
35
|
+
|
36
|
+
/* concat_string_list - concatenates string contents of list of STR elements.
|
37
|
+
* Frees STR elements as they are added to the concatenation. */
|
38
|
+
GString *concat_string_list(element *list) {
|
39
|
+
GString *result;
|
40
|
+
element *next;
|
41
|
+
result = g_string_new("");
|
42
|
+
while (list != NULL) {
|
43
|
+
assert(list->key == STR);
|
44
|
+
assert(list->contents.str != NULL);
|
45
|
+
g_string_append(result, list->contents.str);
|
46
|
+
next = list->next;
|
47
|
+
free_element(list);
|
48
|
+
list = next;
|
49
|
+
}
|
50
|
+
return result;
|
51
|
+
}
|
52
|
+
|
53
|
+
/**********************************************************************
|
54
|
+
|
55
|
+
Global variables used in parsing
|
56
|
+
|
57
|
+
***********************************************************************/
|
58
|
+
|
59
|
+
char *charbuf = ""; /* Buffer of characters to be parsed. */
|
60
|
+
element *references = NULL; /* List of link references found. */
|
61
|
+
element *notes = NULL; /* List of footnotes found. */
|
62
|
+
element *parse_result; /* Results of parse. */
|
63
|
+
int syntax_extensions; /* Syntax extensions selected. */
|
64
|
+
|
65
|
+
/**********************************************************************
|
66
|
+
|
67
|
+
Auxiliary functions for parsing actions.
|
68
|
+
These make it easier to build up data structures (including lists)
|
69
|
+
in the parsing actions.
|
70
|
+
|
71
|
+
***********************************************************************/
|
72
|
+
|
73
|
+
/* mk_element - generic constructor for element */
|
74
|
+
element * mk_element(int key) {
|
75
|
+
element *result = malloc(sizeof(element));
|
76
|
+
result->key = key;
|
77
|
+
result->children = NULL;
|
78
|
+
result->next = NULL;
|
79
|
+
result->contents.str = NULL;
|
80
|
+
return result;
|
81
|
+
}
|
82
|
+
|
83
|
+
/* mk_str - constructor for STR element */
|
84
|
+
element * mk_str(char *string) {
|
85
|
+
element *result;
|
86
|
+
assert(string != NULL);
|
87
|
+
result = mk_element(STR);
|
88
|
+
result->contents.str = strdup(string);
|
89
|
+
return result;
|
90
|
+
}
|
91
|
+
|
92
|
+
/* mk_str_from_list - makes STR element by concatenating a
|
93
|
+
* reversed list of strings, adding optional extra newline */
|
94
|
+
element * mk_str_from_list(element *list, bool extra_newline) {
|
95
|
+
element *result;
|
96
|
+
GString *c = concat_string_list(reverse(list));
|
97
|
+
if (extra_newline)
|
98
|
+
g_string_append(c, "\n");
|
99
|
+
result = mk_element(STR);
|
100
|
+
result->contents.str = c->str;
|
101
|
+
g_string_free(c, false);
|
102
|
+
return result;
|
103
|
+
}
|
104
|
+
|
105
|
+
/* mk_list - makes new list with key 'key' and children the reverse of 'lst'.
|
106
|
+
* This is designed to be used with cons to build lists in a parser action.
|
107
|
+
* The reversing is necessary because cons adds to the head of a list. */
|
108
|
+
element * mk_list(int key, element *lst) {
|
109
|
+
element *result;
|
110
|
+
result = mk_element(key);
|
111
|
+
result->children = reverse(lst);
|
112
|
+
return result;
|
113
|
+
}
|
114
|
+
|
115
|
+
/* mk_link - constructor for LINK element */
|
116
|
+
element * mk_link(element *label, char *url, char *title) {
|
117
|
+
element *result;
|
118
|
+
result = mk_element(LINK);
|
119
|
+
result->contents.link = malloc(sizeof(link));
|
120
|
+
result->contents.link->label = label;
|
121
|
+
result->contents.link->url = strdup(url);
|
122
|
+
result->contents.link->title = strdup(title);
|
123
|
+
return result;
|
124
|
+
}
|
125
|
+
|
126
|
+
/* mk_media - constructor for AUDIO and VIDEO element */
|
127
|
+
element * mk_media(element *label, char *source1, char *source2) {
|
128
|
+
element *result;
|
129
|
+
result = mk_element(MEDIA);
|
130
|
+
result->contents.media = malloc(sizeof(media));
|
131
|
+
result->contents.media->label = label;
|
132
|
+
result->contents.media->source1 = strdup(source1);
|
133
|
+
result->contents.media->source2 = strdup(source2);
|
134
|
+
return result;
|
135
|
+
}
|
136
|
+
|
137
|
+
/* extension = returns true if extension is selected */
|
138
|
+
bool extension(int ext) {
|
139
|
+
return (syntax_extensions & ext);
|
140
|
+
}
|
141
|
+
|
142
|
+
/* match_inlines - returns true if inline lists match (case-insensitive...) */
|
143
|
+
bool match_inlines(element *l1, element *l2) {
|
144
|
+
while (l1 != NULL && l2 != NULL) {
|
145
|
+
if (l1->key != l2->key)
|
146
|
+
return false;
|
147
|
+
switch (l1->key) {
|
148
|
+
case SPACE:
|
149
|
+
case LINEBREAK:
|
150
|
+
case ELLIPSIS:
|
151
|
+
case EMDASH:
|
152
|
+
case ENDASH:
|
153
|
+
case APOSTROPHE:
|
154
|
+
break;
|
155
|
+
case CODE:
|
156
|
+
case STR:
|
157
|
+
case HTML:
|
158
|
+
if (strcasecmp(l1->contents.str, l2->contents.str) == 0)
|
159
|
+
break;
|
160
|
+
else
|
161
|
+
return false;
|
162
|
+
case EMPH:
|
163
|
+
case STRONG:
|
164
|
+
case LIST:
|
165
|
+
case SINGLEQUOTED:
|
166
|
+
case DOUBLEQUOTED:
|
167
|
+
if (match_inlines(l1->children, l2->children))
|
168
|
+
break;
|
169
|
+
else
|
170
|
+
return false;
|
171
|
+
case LINK:
|
172
|
+
case IMAGE:
|
173
|
+
return false; /* No links or images within links */
|
174
|
+
default:
|
175
|
+
fprintf(stderr, "match_inlines encountered unknown key = %d\n", l1->key);
|
176
|
+
exit(EXIT_FAILURE);
|
177
|
+
break;
|
178
|
+
}
|
179
|
+
l1 = l1->next;
|
180
|
+
l2 = l2->next;
|
181
|
+
}
|
182
|
+
return (l1 == NULL && l2 == NULL); /* return true if both lists exhausted */
|
183
|
+
}
|
184
|
+
|
185
|
+
/* find_reference - return true if link found in references matching label.
|
186
|
+
* 'link' is modified with the matching url and title. */
|
187
|
+
bool find_reference(link *result, element *label) {
|
188
|
+
element *cur = references; /* pointer to walk up list of references */
|
189
|
+
link *curitem;
|
190
|
+
while (cur != NULL) {
|
191
|
+
curitem = cur->contents.link;
|
192
|
+
if (match_inlines(label, curitem->label)) {
|
193
|
+
*result = *curitem;
|
194
|
+
return true;
|
195
|
+
}
|
196
|
+
else
|
197
|
+
cur = cur->next;
|
198
|
+
}
|
199
|
+
return false;
|
200
|
+
}
|
201
|
+
|
202
|
+
/* find_note - return true if note found in notes matching label.
|
203
|
+
if found, 'result' is set to point to matched note. */
|
204
|
+
|
205
|
+
bool find_note(element **result, char *label) {
|
206
|
+
element *cur = notes; /* pointer to walk up list of notes */
|
207
|
+
while (cur != NULL) {
|
208
|
+
if (strcmp(label, cur->contents.str) == 0) {
|
209
|
+
*result = cur;
|
210
|
+
return true;
|
211
|
+
}
|
212
|
+
else
|
213
|
+
cur = cur->next;
|
214
|
+
}
|
215
|
+
return false;
|
216
|
+
}
|
217
|
+
|
data/lib/markdown.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'peg_markdown'
|
data/lib/peg_markdown.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'peg_markdown.so'
|
2
|
+
|
3
|
+
# Front-end to jgm's peg-markdown implementation of Markdown, the humane
|
4
|
+
# text markup language.
|
5
|
+
#
|
6
|
+
# A simple processor:
|
7
|
+
# >>> puts Markdown.new("Hello, World.").to_html
|
8
|
+
# <p>Hello, World.</p>
|
9
|
+
#
|
10
|
+
# With other stuff:
|
11
|
+
# >>> puts Markdown.new("_Hello -- World!_", :smart, :filter_html).to_html
|
12
|
+
# <p><em>Hello World!</em></p>
|
13
|
+
#
|
14
|
+
class PEGMarkdown
|
15
|
+
|
16
|
+
# Original Markdown formatted text.
|
17
|
+
attr_reader :text
|
18
|
+
|
19
|
+
# Set true to have smarty-like quote translation performed.
|
20
|
+
attr_accessor :smart
|
21
|
+
|
22
|
+
# Set true to have footnotes processed.
|
23
|
+
attr_accessor :notes
|
24
|
+
|
25
|
+
# Do not output <style> tags included in the source text.
|
26
|
+
attr_accessor :filter_styles
|
27
|
+
|
28
|
+
# Do not output any raw HTML included in the source text.
|
29
|
+
attr_accessor :filter_html
|
30
|
+
|
31
|
+
# Included for compatibility with RedCloth's interface.
|
32
|
+
attr_accessor :fold_lines
|
33
|
+
|
34
|
+
# Set true to enable strike-through extension.
|
35
|
+
attr_accessor :strike
|
36
|
+
|
37
|
+
# Set true to enable autolink extension.
|
38
|
+
attr_accessor :autolink
|
39
|
+
|
40
|
+
# Set true to enable hard wrap extension.
|
41
|
+
attr_accessor :hard_wrap
|
42
|
+
|
43
|
+
# Set true to disable rendering of images.
|
44
|
+
attr_accessor :no_images
|
45
|
+
|
46
|
+
# Set true to enable audio/video extension.
|
47
|
+
attr_accessor :media
|
48
|
+
|
49
|
+
# Set true to enable codeblock extension.
|
50
|
+
attr_accessor :codeblock
|
51
|
+
|
52
|
+
# Set true to enable hashtags extension.
|
53
|
+
attr_accessor :hashtags
|
54
|
+
|
55
|
+
# Set true to enable usernames extension.
|
56
|
+
attr_accessor :usernames
|
57
|
+
|
58
|
+
# Set true to enable spoilerblock extension.
|
59
|
+
attr_accessor :spoilerblock
|
60
|
+
|
61
|
+
# Create a new Markdown processor. The +text+ argument is a string
|
62
|
+
# containing Markdown text. Variable other arguments may be supplied to
|
63
|
+
# set various processing options:
|
64
|
+
#
|
65
|
+
# * <tt>:smart</tt> - Enable SmartyPants processing.
|
66
|
+
# * <tt>:notes</tt> - Enable footnotes.
|
67
|
+
# * <tt>:filter_styles</tt> - Do not output <style> tags included in the
|
68
|
+
# source text.
|
69
|
+
# * <tt>:filter_html</tt> - Do not output raw HTML included in the
|
70
|
+
# source text.
|
71
|
+
# * <tt>:fold_lines</tt> - RedCloth compatible line folding (not used).
|
72
|
+
# * <tt>:strike</tt> - Enable strike-through extension.
|
73
|
+
# * <tt>:autolink</tt> - Enable autolinking of bare URLs.
|
74
|
+
# * <tt>:hard_wrap</tt> - Insert line breaks inside paragraphs.
|
75
|
+
# * <tt>:no_images</tt> - Treat image links as if they were plain links.
|
76
|
+
# * <tt>:media</tt> - Replace audio/video links with HTML5 audio/video objects.
|
77
|
+
# * <tt>:codeblock</tt> - Render block enclosed in ~~~ as verbatim section.
|
78
|
+
# * <tt>:hashtags</tt> - Mark hashtags.
|
79
|
+
# * <tt>:usernames</tt> - Mark usernames.
|
80
|
+
# * <tt>:spoilerblock</tt> - Render block prefixed with ?> as spoiler section.
|
81
|
+
#
|
82
|
+
def initialize(text, *extensions)
|
83
|
+
@text = text
|
84
|
+
@smart = false
|
85
|
+
@notes = false
|
86
|
+
@filter_styles = false
|
87
|
+
@filter_html = false
|
88
|
+
@strike = false
|
89
|
+
@autolink = false
|
90
|
+
@hard_wrap = false
|
91
|
+
@no_images = false
|
92
|
+
@media = false
|
93
|
+
@codeblock = false
|
94
|
+
@hashtags = false
|
95
|
+
@usernames = false
|
96
|
+
@spoilerblock = false
|
97
|
+
extensions.each { |e| send("#{e}=", true) }
|
98
|
+
end
|
99
|
+
|
100
|
+
alias to_s text
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
Markdown = PEGMarkdown unless defined? Markdown
|
@@ -0,0 +1,157 @@
|
|
1
|
+
#!/usr/bin/perl
|
2
|
+
|
3
|
+
#
|
4
|
+
# MarkdownTester -- Run tests for Markdown implementations
|
5
|
+
#
|
6
|
+
# Copyright (c) 2004 John Gruber
|
7
|
+
# <http://daringfireball.net/projects/markdown/>
|
8
|
+
#
|
9
|
+
|
10
|
+
use strict;
|
11
|
+
use warnings;
|
12
|
+
use Getopt::Long;
|
13
|
+
use Benchmark;
|
14
|
+
|
15
|
+
our $VERSION = '1.0';
|
16
|
+
# Mon 13 Dec 2004
|
17
|
+
|
18
|
+
my $time_start = new Benchmark;
|
19
|
+
my $test_dir = "Tests";
|
20
|
+
my $script = "./Markdown.pl";
|
21
|
+
my $use_tidy = 0;
|
22
|
+
my ($flag_version);
|
23
|
+
|
24
|
+
GetOptions (
|
25
|
+
"script=s" => \$script,
|
26
|
+
"testdir=s" => \$test_dir,
|
27
|
+
"tidy" => \$use_tidy,
|
28
|
+
"version" => \$flag_version,
|
29
|
+
);
|
30
|
+
|
31
|
+
if($flag_version) {
|
32
|
+
my $progname = $0;
|
33
|
+
$progname =~ s{.*/}{};
|
34
|
+
die "$progname version $VERSION\n";
|
35
|
+
}
|
36
|
+
|
37
|
+
unless (-d $test_dir) { die "'$test_dir' is not a directory.\n"; }
|
38
|
+
unless (-f $script) { die "$script does not exist.\n"; }
|
39
|
+
unless (-x $script) { die "$script is not executable.\n"; }
|
40
|
+
|
41
|
+
my $tests_passed = 0;
|
42
|
+
my $tests_failed = 0;
|
43
|
+
|
44
|
+
foreach my $testfile (glob "$test_dir/*.text") {
|
45
|
+
my $testname = $testfile;
|
46
|
+
$testname =~ s{.*/(.+)\.text$}{$1}i;
|
47
|
+
print "$testname ... ";
|
48
|
+
|
49
|
+
# Look for a corresponding .html file for each .text file:
|
50
|
+
my $resultfile = $testfile;
|
51
|
+
$resultfile =~ s{\.text$}{\.html}i;
|
52
|
+
unless (-f $resultfile) {die "'$resultfile' does not exist.\n";}
|
53
|
+
|
54
|
+
# open(TEST, $testfile) || die("Can't open testfile: $!");
|
55
|
+
open(RESULT, $resultfile) || die("Can't open resultfile: $!");
|
56
|
+
undef $/;
|
57
|
+
# my $t_input = <TEST>;
|
58
|
+
my $t_result = <RESULT>;
|
59
|
+
|
60
|
+
my $t_output = `$script '$testfile'`;
|
61
|
+
|
62
|
+
# Normalize the output and expected result strings:
|
63
|
+
$t_result =~ s/\s+\z//; # trim trailing whitespace
|
64
|
+
$t_output =~ s/\s+\z//; # trim trailing whitespace
|
65
|
+
if ($use_tidy) {
|
66
|
+
# Escape the strings, pass them through to CLI tidy tool for tag-level equivalency
|
67
|
+
$t_result =~ s{'}{'\\''}g; # escape ' chars for shell
|
68
|
+
$t_output =~ s{'}{'\\''}g;
|
69
|
+
$t_result = `echo '$t_result' | tidy --show-body-only 1 --quiet 1 --show-warnings 0`;
|
70
|
+
$t_output = `echo '$t_output' | tidy --show-body-only 1 --quiet 1 --show-warnings 0`;
|
71
|
+
}
|
72
|
+
|
73
|
+
if ($t_output eq $t_result) {
|
74
|
+
print "OK\n";
|
75
|
+
$tests_passed++;
|
76
|
+
}
|
77
|
+
else {
|
78
|
+
print "FAILED\n\n";
|
79
|
+
$tests_failed++;
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
print "\n\n";
|
84
|
+
print "$tests_passed passed; $tests_failed failed.\n";
|
85
|
+
|
86
|
+
my $time_end = new Benchmark;
|
87
|
+
my $time_diff = timediff($time_end, $time_start);
|
88
|
+
print "Benchmark: ", timestr($time_diff), "\n";
|
89
|
+
|
90
|
+
|
91
|
+
__END__
|
92
|
+
|
93
|
+
=pod
|
94
|
+
|
95
|
+
=head1 NAME
|
96
|
+
|
97
|
+
B<MarkdownTest>
|
98
|
+
|
99
|
+
|
100
|
+
=head1 SYNOPSIS
|
101
|
+
|
102
|
+
B<MarkdownTest.pl> [ B<--options> ] [ I<file> ... ]
|
103
|
+
|
104
|
+
|
105
|
+
=head1 DESCRIPTION
|
106
|
+
|
107
|
+
|
108
|
+
=head1 OPTIONS
|
109
|
+
|
110
|
+
Use "--" to end switch parsing. For example, to open a file named "-z", use:
|
111
|
+
|
112
|
+
MarkdownTest.pl -- -z
|
113
|
+
|
114
|
+
=over 4
|
115
|
+
|
116
|
+
=item B<--script>
|
117
|
+
|
118
|
+
Specify the path to the Markdown script to test. Defaults to
|
119
|
+
"./Markdown.pl". Example:
|
120
|
+
|
121
|
+
./MarkdownTest.pl --script ./PHP-Markdown/php-markdown
|
122
|
+
|
123
|
+
=item B<--testdir>
|
124
|
+
|
125
|
+
Specify the path to a directory containing test data. Defaults to "Tests".
|
126
|
+
|
127
|
+
=item B<--tidy>
|
128
|
+
|
129
|
+
Flag to turn on using the command line 'tidy' tool to normalize HTML
|
130
|
+
output before comparing script output to the expected test result.
|
131
|
+
Assumes that the 'tidy' command is available in your PATH. Defaults to
|
132
|
+
off.
|
133
|
+
|
134
|
+
=back
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
=head1 BUGS
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
=head1 VERSION HISTORY
|
143
|
+
|
144
|
+
1.0 Mon 13 Dec 2004
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
=head1 COPYRIGHT AND LICENSE
|
149
|
+
|
150
|
+
Copyright (c) 2004 John Gruber
|
151
|
+
<http://daringfireball.net/>
|
152
|
+
All rights reserved.
|
153
|
+
|
154
|
+
This is free software; you may redistribute it and/or modify it under
|
155
|
+
the same terms as Perl itself.
|
156
|
+
|
157
|
+
=cut
|