rpeg-markdown 0.1.0 → 0.2.0

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.
Files changed (103) hide show
  1. data/README +25 -1
  2. data/Rakefile +85 -16
  3. data/ext/extconf.h +3 -0
  4. data/ext/extconf.rb +13 -2
  5. data/ext/markdown.c +27 -71
  6. data/ext/markdown_lib.c +181 -0
  7. data/ext/markdown_lib.h +19 -0
  8. data/ext/markdown_output.c +313 -327
  9. data/ext/markdown_parser.c +2817 -2920
  10. data/ext/markdown_peg.h +10 -24
  11. data/ext/parsing_functions.c +104 -0
  12. data/ext/utility_functions.c +220 -0
  13. data/lib/markdown.rb +22 -2
  14. data/test/MarkdownTest_1.0/MarkdownTest.pl +157 -0
  15. data/test/MarkdownTest_1.0/Tests/Amps and angle encoding.html +17 -0
  16. data/test/MarkdownTest_1.0/Tests/Amps and angle encoding.text +21 -0
  17. data/test/MarkdownTest_1.0/Tests/Auto links.html +18 -0
  18. data/test/MarkdownTest_1.0/Tests/Auto links.text +13 -0
  19. data/test/MarkdownTest_1.0/Tests/Backslash escapes.html +102 -0
  20. data/test/MarkdownTest_1.0/Tests/Backslash escapes.text +104 -0
  21. data/test/MarkdownTest_1.0/Tests/Blockquotes with code blocks.html +15 -0
  22. data/test/MarkdownTest_1.0/Tests/Blockquotes with code blocks.text +11 -0
  23. data/test/MarkdownTest_1.0/Tests/Hard-wrapped paragraphs with list-like lines.html +8 -0
  24. data/test/MarkdownTest_1.0/Tests/Hard-wrapped paragraphs with list-like lines.text +8 -0
  25. data/test/MarkdownTest_1.0/Tests/Horizontal rules.html +71 -0
  26. data/test/MarkdownTest_1.0/Tests/Horizontal rules.text +67 -0
  27. data/test/MarkdownTest_1.0/Tests/Inline HTML (Advanced).html +14 -0
  28. data/test/MarkdownTest_1.0/Tests/Inline HTML (Advanced).text +14 -0
  29. data/test/MarkdownTest_1.0/Tests/Inline HTML (Simple).html +72 -0
  30. data/test/MarkdownTest_1.0/Tests/Inline HTML (Simple).text +69 -0
  31. data/test/MarkdownTest_1.0/Tests/Inline HTML comments.html +13 -0
  32. data/test/MarkdownTest_1.0/Tests/Inline HTML comments.text +13 -0
  33. data/test/MarkdownTest_1.0/Tests/Links, inline style.html +9 -0
  34. data/test/MarkdownTest_1.0/Tests/Links, inline style.text +9 -0
  35. data/test/MarkdownTest_1.0/Tests/Links, reference style.html +18 -0
  36. data/test/MarkdownTest_1.0/Tests/Links, reference style.text +31 -0
  37. data/test/MarkdownTest_1.0/Tests/Literal quotes in titles.html +3 -0
  38. data/test/MarkdownTest_1.0/Tests/Literal quotes in titles.text +7 -0
  39. data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Basics.html +314 -0
  40. data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Basics.text +306 -0
  41. data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Syntax.html +942 -0
  42. data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Syntax.text +888 -0
  43. data/test/MarkdownTest_1.0/Tests/Nested blockquotes.html +9 -0
  44. data/test/MarkdownTest_1.0/Tests/Nested blockquotes.text +5 -0
  45. data/test/MarkdownTest_1.0/Tests/Ordered and unordered lists.html +137 -0
  46. data/test/MarkdownTest_1.0/Tests/Ordered and unordered lists.text +122 -0
  47. data/test/MarkdownTest_1.0/Tests/Strong and em together.html +7 -0
  48. data/test/MarkdownTest_1.0/Tests/Strong and em together.text +7 -0
  49. data/test/MarkdownTest_1.0/Tests/Tabs.html +25 -0
  50. data/test/MarkdownTest_1.0/Tests/Tabs.text +21 -0
  51. data/test/MarkdownTest_1.0/Tests/Tidyness.html +8 -0
  52. data/test/MarkdownTest_1.0/Tests/Tidyness.text +5 -0
  53. data/test/MarkdownTest_1.0.3/MarkdownTest.pl +176 -0
  54. data/test/MarkdownTest_1.0.3/Tests/Amps and angle encoding.html +17 -0
  55. data/test/MarkdownTest_1.0.3/Tests/Amps and angle encoding.text +21 -0
  56. data/test/MarkdownTest_1.0.3/Tests/Auto links.html +18 -0
  57. data/test/MarkdownTest_1.0.3/Tests/Auto links.text +13 -0
  58. data/test/MarkdownTest_1.0.3/Tests/Backslash escapes.html +118 -0
  59. data/test/MarkdownTest_1.0.3/Tests/Backslash escapes.text +120 -0
  60. data/test/MarkdownTest_1.0.3/Tests/Blockquotes with code blocks.html +15 -0
  61. data/test/MarkdownTest_1.0.3/Tests/Blockquotes with code blocks.text +11 -0
  62. data/test/MarkdownTest_1.0.3/Tests/Code Blocks.html +18 -0
  63. data/test/MarkdownTest_1.0.3/Tests/Code Blocks.text +14 -0
  64. data/test/MarkdownTest_1.0.3/Tests/Code Spans.html +6 -0
  65. data/test/MarkdownTest_1.0.3/Tests/Code Spans.text +6 -0
  66. data/test/MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.html +8 -0
  67. data/test/MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.text +8 -0
  68. data/test/MarkdownTest_1.0.3/Tests/Horizontal rules.html +71 -0
  69. data/test/MarkdownTest_1.0.3/Tests/Horizontal rules.text +67 -0
  70. data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Advanced).html +15 -0
  71. data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Advanced).text +15 -0
  72. data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Simple).html +72 -0
  73. data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Simple).text +69 -0
  74. data/test/MarkdownTest_1.0.3/Tests/Inline HTML comments.html +13 -0
  75. data/test/MarkdownTest_1.0.3/Tests/Inline HTML comments.text +13 -0
  76. data/test/MarkdownTest_1.0.3/Tests/Links, inline style.html +11 -0
  77. data/test/MarkdownTest_1.0.3/Tests/Links, inline style.text +12 -0
  78. data/test/MarkdownTest_1.0.3/Tests/Links, reference style.html +52 -0
  79. data/test/MarkdownTest_1.0.3/Tests/Links, reference style.text +71 -0
  80. data/test/MarkdownTest_1.0.3/Tests/Links, shortcut references.html +9 -0
  81. data/test/MarkdownTest_1.0.3/Tests/Links, shortcut references.text +20 -0
  82. data/test/MarkdownTest_1.0.3/Tests/Literal quotes in titles.html +3 -0
  83. data/test/MarkdownTest_1.0.3/Tests/Literal quotes in titles.text +7 -0
  84. data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Basics.html +314 -0
  85. data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Basics.text +306 -0
  86. data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Syntax.html +942 -0
  87. data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Syntax.text +888 -0
  88. data/test/MarkdownTest_1.0.3/Tests/Nested blockquotes.html +9 -0
  89. data/test/MarkdownTest_1.0.3/Tests/Nested blockquotes.text +5 -0
  90. data/test/MarkdownTest_1.0.3/Tests/Ordered and unordered lists.html +148 -0
  91. data/test/MarkdownTest_1.0.3/Tests/Ordered and unordered lists.text +131 -0
  92. data/test/MarkdownTest_1.0.3/Tests/Strong and em together.html +7 -0
  93. data/test/MarkdownTest_1.0.3/Tests/Strong and em together.text +7 -0
  94. data/test/MarkdownTest_1.0.3/Tests/Tabs.html +25 -0
  95. data/test/MarkdownTest_1.0.3/Tests/Tabs.text +21 -0
  96. data/test/MarkdownTest_1.0.3/Tests/Tidyness.html +8 -0
  97. data/test/MarkdownTest_1.0.3/Tests/Tidyness.text +5 -0
  98. data/test/benchmark.rb +49 -0
  99. data/test/markdown_test.rb +78 -0
  100. metadata +96 -6
  101. data/ext/markdown_buffer.c +0 -46
  102. data/ext/markdown_buffer.h +0 -6
  103. data/test.rb +0 -25
data/ext/markdown_peg.h CHANGED
@@ -1,13 +1,9 @@
1
1
  /* markdown_peg.h */
2
+ #include "markdown_lib.h"
3
+ #include <glib.h>
2
4
 
3
5
  extern char *strdup(const char *string);
4
6
 
5
- /**********************************************************************
6
-
7
- Data Structures
8
-
9
- ***********************************************************************/
10
-
11
7
  /* Information (label, URL and title) for a link. */
12
8
  struct Link {
13
9
  struct Element *label;
@@ -20,7 +16,7 @@ typedef struct Link link;
20
16
  /* Union for contents of an Element (string, list, or link). */
21
17
  union Contents {
22
18
  char *str;
23
- struct Link link;
19
+ struct Link *link;
24
20
  };
25
21
 
26
22
  /* Types of semantic values returned by parsers. */
@@ -52,7 +48,7 @@ enum keys { LIST, /* A generic list of values. For ordered and bullet lists,
52
48
  HTMLBLOCK,
53
49
  HRULE,
54
50
  REFERENCE,
55
- NOTE,
51
+ NOTE
56
52
  };
57
53
 
58
54
  /* Semantic value of a parsing action. */
@@ -65,20 +61,10 @@ struct Element {
65
61
 
66
62
  typedef struct Element element;
67
63
 
68
- enum markdown_extensions {
69
- EXT_SMART = 1,
70
- EXT_NOTES = 2
71
- };
72
-
73
- element *cons(element new, element *list);
74
- element *reverse(element *list);
75
- element markdown(char *string, int extensions);
76
-
77
- /* Output formats. */
78
- enum formats { HTML_FORMAT,
79
- LATEX_FORMAT,
80
- GROFF_MM_FORMAT
81
- };
82
-
83
- void print_element(element elt, int format);
64
+ element * parse_references(char *string, int extensions);
65
+ element * parse_notes(char *string, int extensions, element *reference_list);
66
+ element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list);
67
+ void free_element_list(element * elt);
68
+ void free_element(element *elt);
69
+ void print_element_list(GString *out, element *elt, int format, int exts);
84
70
 
@@ -0,0 +1,104 @@
1
+ /* parsing_functions.c - Functions for parsing markdown and
2
+ * freeing element lists. */
3
+
4
+ int yyparse(void);
5
+
6
+ static void free_element_contents(element elt);
7
+
8
+ /* free_element_list - free list of elements recursively */
9
+ void free_element_list(element * elt) {
10
+ element * next = NULL;
11
+ while (elt != NULL) {
12
+ next = elt->next;
13
+ free_element_contents(*elt);
14
+ if (elt->children != NULL) {
15
+ free_element_list(elt->children);
16
+ elt->children = NULL;
17
+ }
18
+ free(elt);
19
+ elt = next;
20
+ }
21
+ }
22
+
23
+ /* free_element_contents - free element contents depending on type */
24
+ static void free_element_contents(element elt) {
25
+ switch (elt.key) {
26
+ case STR:
27
+ case SPACE:
28
+ case RAW:
29
+ case HTMLBLOCK:
30
+ case HTML:
31
+ case VERBATIM:
32
+ case CODE:
33
+ case NOTE:
34
+ free(elt.contents.str);
35
+ elt.contents.str = NULL;
36
+ break;
37
+ case LINK:
38
+ case IMAGE:
39
+ case REFERENCE:
40
+ free(elt.contents.link->url);
41
+ elt.contents.link->url = NULL;
42
+ free(elt.contents.link->title);
43
+ elt.contents.link->title = NULL;
44
+ free_element_list(elt.contents.link->label);
45
+ free(elt.contents.link);
46
+ elt.contents.link = NULL;
47
+ break;
48
+ default:
49
+ ;
50
+ }
51
+ }
52
+
53
+ /* free_element - free element and contents */
54
+ void free_element(element *elt) {
55
+ free_element_contents(*elt);
56
+ free(elt);
57
+ }
58
+
59
+ element * parse_references(char *string, int extensions) {
60
+
61
+ char *oldcharbuf;
62
+ syntax_extensions = extensions;
63
+
64
+ oldcharbuf = charbuf;
65
+ charbuf = string;
66
+ yyparsefrom(yy_References); /* first pass, just to collect references */
67
+ charbuf = oldcharbuf;
68
+
69
+ return references;
70
+ }
71
+
72
+ element * parse_notes(char *string, int extensions, element *reference_list) {
73
+
74
+ char *oldcharbuf;
75
+ notes = NULL;
76
+ syntax_extensions = extensions;
77
+
78
+ if (extension(EXT_NOTES)) {
79
+ references = reference_list;
80
+ oldcharbuf = charbuf;
81
+ charbuf = string;
82
+ yyparsefrom(yy_Notes); /* second pass for notes */
83
+ charbuf = oldcharbuf;
84
+ }
85
+
86
+ return notes;
87
+ }
88
+
89
+ element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list) {
90
+
91
+ char *oldcharbuf;
92
+ syntax_extensions = extensions;
93
+ references = reference_list;
94
+ notes = note_list;
95
+
96
+ oldcharbuf = charbuf;
97
+ charbuf = string;
98
+
99
+ yyparsefrom(yy_Doc);
100
+
101
+ charbuf = oldcharbuf; /* restore charbuf to original value */
102
+ return parse_result;
103
+
104
+ }
@@ -0,0 +1,220 @@
1
+ /* utility_functions.c - List manipulation functions, element
2
+ * constructors, and macro definitions for leg markdown parser. */
3
+
4
+ extern int strcasecmp(const char *string1, const char *string2);
5
+
6
+ /**********************************************************************
7
+
8
+ List manipulation functions
9
+
10
+ ***********************************************************************/
11
+
12
+ /* cons - cons an element onto a list, returning pointer to new head */
13
+ static element * cons(element *new, element *list) {
14
+ assert(new != NULL);
15
+ new->next = list;
16
+ return new;
17
+ }
18
+
19
+ /* reverse - reverse a list, returning pointer to new list */
20
+ static element *reverse(element *list) {
21
+ element *new = NULL;
22
+ element *next = NULL;
23
+ while (list != NULL) {
24
+ next = list->next;
25
+ new = cons(list, new);
26
+ list = next;
27
+ }
28
+ return new;
29
+ }
30
+
31
+ /* concat_string_list - concatenates string contents of list of STR elements.
32
+ * Frees STR elements as they are added to the concatenation. */
33
+ static GString *concat_string_list(element *list) {
34
+ GString *result;
35
+ element *next;
36
+ result = g_string_new("");
37
+ while (list != NULL) {
38
+ assert(list->key == STR);
39
+ assert(list->contents.str != NULL);
40
+ g_string_append(result, list->contents.str);
41
+ next = list->next;
42
+ free_element(list);
43
+ list = next;
44
+ }
45
+ return result;
46
+ }
47
+
48
+ /**********************************************************************
49
+
50
+ Global variables used in parsing
51
+
52
+ ***********************************************************************/
53
+
54
+ static char *charbuf = ""; /* Buffer of characters to be parsed. */
55
+ static element *references = NULL; /* List of link references found. */
56
+ static element *notes = NULL; /* List of footnotes found. */
57
+ static element *parse_result; /* Results of parse. */
58
+ static int syntax_extensions; /* Syntax extensions selected. */
59
+
60
+ /**********************************************************************
61
+
62
+ Auxiliary functions for parsing actions.
63
+ These make it easier to build up data structures (including lists)
64
+ in the parsing actions.
65
+
66
+ ***********************************************************************/
67
+
68
+ /* mk_element - generic constructor for element */
69
+ static element * mk_element(int key) {
70
+ element *result = malloc(sizeof(element));
71
+ result->key = key;
72
+ result->children = NULL;
73
+ result->next = NULL;
74
+ result->contents.str = NULL;
75
+ return result;
76
+ }
77
+
78
+ /* mk_str - constructor for STR element */
79
+ static element * mk_str(char *string) {
80
+ element *result;
81
+ assert(string != NULL);
82
+ result = mk_element(STR);
83
+ result->contents.str = strdup(string);
84
+ return result;
85
+ }
86
+
87
+ /* mk_str_from_list - makes STR element by concatenating a
88
+ * reversed list of strings, adding optional extra newline */
89
+ static element * mk_str_from_list(element *list, bool extra_newline) {
90
+ element *result;
91
+ GString *c = concat_string_list(reverse(list));
92
+ if (extra_newline)
93
+ g_string_append(c, "\n");
94
+ result = mk_element(STR);
95
+ result->contents.str = c->str;
96
+ g_string_free(c, false);
97
+ return result;
98
+ }
99
+
100
+ /* mk_list - makes new list with key 'key' and children the reverse of 'lst'.
101
+ * This is designed to be used with cons to build lists in a parser action.
102
+ * The reversing is necessary because cons adds to the head of a list. */
103
+ static element * mk_list(int key, element *lst) {
104
+ element *result;
105
+ result = mk_element(key);
106
+ result->children = reverse(lst);
107
+ return result;
108
+ }
109
+
110
+ /* mk_link - constructor for LINK element */
111
+ static element * mk_link(element *label, char *url, char *title) {
112
+ element *result;
113
+ result = mk_element(LINK);
114
+ result->contents.link = malloc(sizeof(link));
115
+ result->contents.link->label = label;
116
+ result->contents.link->url = strdup(url);
117
+ result->contents.link->title = strdup(title);
118
+ return result;
119
+ }
120
+
121
+ /* extension = returns true if extension is selected */
122
+ static bool extension(int ext) {
123
+ return (syntax_extensions & ext);
124
+ }
125
+
126
+ /* match_inlines - returns true if inline lists match (case-insensitive...) */
127
+ static bool match_inlines(element *l1, element *l2) {
128
+ while (l1 != NULL && l2 != NULL) {
129
+ if (l1->key != l2->key)
130
+ return false;
131
+ switch (l1->key) {
132
+ case SPACE:
133
+ case LINEBREAK:
134
+ break;
135
+ case CODE:
136
+ case STR:
137
+ case HTML:
138
+ if (strcasecmp(l1->contents.str, l2->contents.str) == 0)
139
+ break;
140
+ else
141
+ return false;
142
+ case EMPH:
143
+ case STRONG:
144
+ case LIST:
145
+ if (match_inlines(l1->children, l2->children))
146
+ break;
147
+ else
148
+ return false;
149
+ case LINK:
150
+ case IMAGE:
151
+ return false; /* No links or images within links */
152
+ default:
153
+ fprintf(stderr, "match_inlines encountered unknown key = %d\n", l1->key);
154
+ exit(EXIT_FAILURE);
155
+ break;
156
+ }
157
+ l1 = l1->next;
158
+ l2 = l2->next;
159
+ }
160
+ return (l1 == NULL && l2 == NULL); /* return true if both lists exhausted */
161
+ }
162
+
163
+ /* find_reference - return true if link found in references matching label.
164
+ * 'link' is modified with the matching url and title. */
165
+ static bool find_reference(link *result, element *label) {
166
+ element *cur = references; /* pointer to walk up list of references */
167
+ link *curitem;
168
+ while (cur != NULL) {
169
+ curitem = cur->contents.link;
170
+ if (match_inlines(label, curitem->label)) {
171
+ *result = *curitem;
172
+ return true;
173
+ }
174
+ else
175
+ cur = cur->next;
176
+ }
177
+ return false;
178
+ }
179
+
180
+ /* find_note - return true if note found in notes matching label.
181
+ if found, 'result' is set to point to matched note. */
182
+
183
+ static bool find_note(element **result, char *label) {
184
+ element *cur = notes; /* pointer to walk up list of notes */
185
+ while (cur != NULL) {
186
+ if (strcmp(label, cur->contents.str) == 0) {
187
+ *result = cur;
188
+ return true;
189
+ }
190
+ else
191
+ cur = cur->next;
192
+ }
193
+ return false;
194
+ }
195
+
196
+ /**********************************************************************
197
+
198
+ Definitions for leg parser generator.
199
+ YY_INPUT is the function the parser calls to get new input.
200
+ We take all new input from (static) charbuf.
201
+
202
+ ***********************************************************************/
203
+
204
+ # define YYSTYPE element *
205
+ #ifdef __DEBUG__
206
+ # define YY_DEBUG 1
207
+ #endif
208
+
209
+ #define YY_INPUT(buf, result, max_size) \
210
+ { \
211
+ int yyc; \
212
+ if (charbuf && *charbuf != '\0') { \
213
+ yyc= *charbuf++; \
214
+ } else { \
215
+ yyc= EOF; \
216
+ } \
217
+ result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
218
+ }
219
+
220
+
data/lib/markdown.rb CHANGED
@@ -5,12 +5,32 @@ class Markdown
5
5
  # Original Markdown formatted text.
6
6
  attr_reader :text
7
7
 
8
- # Whether smarty-like quote translation should be performed.
8
+ # Set true to have smarty-like quote translation performed.
9
9
  attr_accessor :smart
10
10
 
11
- # Whether footnotes should be
11
+ # Set true to have footnotes processed.
12
12
  attr_accessor :notes
13
13
 
14
+ # BlueCloth compatible output filtering.
15
+ attr_accessor :filter_styles, :filter_html
16
+
17
+ # RedCloth compatible line folding -- not used for Markdown but
18
+ # included for compatibility.
19
+ attr_accessor :fold_lines
20
+
21
+ # Create a new Markdown processor. The +text+ argument
22
+ # should be a string containing Markdown text. Additional arguments may be
23
+ # supplied to set various processing options:
24
+ #
25
+ # * <tt>:smart</tt> - Enable SmartyPants processing.
26
+ # * <tt>:notes</tt> - Enable footnotes.
27
+ # * <tt>:filter_styles</tt> - Do not output <tt><style></tt> tags.
28
+ # * <tt>:filter_html</tt> - Do not output any raw HTML tags included in
29
+ # the source text.
30
+ # * <tt>:fold_lines</tt> - RedCloth compatible line folding (not used).
31
+ #
32
+ # NOTE: The <tt>:filter_styles</tt> and <tt>:filter_html</tt> extensions
33
+ # are not yet implemented.
14
34
  def initialize(text, *extensions)
15
35
  @smart = false
16
36
  @notes = false
@@ -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
@@ -0,0 +1,17 @@
1
+ <p>AT&amp;T has an ampersand in their name.</p>
2
+
3
+ <p>AT&amp;T is another way to write it.</p>
4
+
5
+ <p>This &amp; that.</p>
6
+
7
+ <p>4 &lt; 5.</p>
8
+
9
+ <p>6 > 5.</p>
10
+
11
+ <p>Here's a <a href="http://example.com/?foo=1&amp;bar=2">link</a> with an ampersand in the URL.</p>
12
+
13
+ <p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&amp;T">AT&amp;T</a>.</p>
14
+
15
+ <p>Here's an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
16
+
17
+ <p>Here's an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
@@ -0,0 +1,21 @@
1
+ AT&T has an ampersand in their name.
2
+
3
+ AT&amp;T is another way to write it.
4
+
5
+ This & that.
6
+
7
+ 4 < 5.
8
+
9
+ 6 > 5.
10
+
11
+ Here's a [link] [1] with an ampersand in the URL.
12
+
13
+ Here's a link with an amersand in the link text: [AT&T] [2].
14
+
15
+ Here's an inline [link](/script?foo=1&bar=2).
16
+
17
+ Here's an inline [link](</script?foo=1&bar=2>).
18
+
19
+
20
+ [1]: http://example.com/?foo=1&bar=2
21
+ [2]: http://att.com/ "AT&T"
@@ -0,0 +1,18 @@
1
+ <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
2
+
3
+ <p>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</a></p>
4
+
5
+ <ul>
6
+ <li>In a list?</li>
7
+ <li><a href="http://example.com/">http://example.com/</a></li>
8
+ <li>It should.</li>
9
+ </ul>
10
+
11
+ <blockquote>
12
+ <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
13
+ </blockquote>
14
+
15
+ <p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
16
+
17
+ <pre><code>or here: &lt;http://example.com/&gt;
18
+ </code></pre>
@@ -0,0 +1,13 @@
1
+ Link: <http://example.com/>.
2
+
3
+ With an ampersand: <http://example.com/?foo=1&bar=2>
4
+
5
+ * In a list?
6
+ * <http://example.com/>
7
+ * It should.
8
+
9
+ > Blockquoted: <http://example.com/>
10
+
11
+ Auto-links should not occur here: `<http://example.com/>`
12
+
13
+ or here: <http://example.com/>