-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_rdoc_markdown_test.rb
1883 lines (1415 loc) · 66.9 KB
/
test_rdoc_markdown_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# frozen_string_literal: true
require 'minitest_helper'
require 'pp'
require 'rdoc'
require 'rdoc/markdown'
class TestRDocMarkdownTest < RDoc::TestCase
MARKDOWN_TEST_PATH = File.expand_path '../MarkdownTest_1.0.3/', __FILE__
def setup
super
@parser = RDoc::Markdown.new
end
def test_amps_and_angle_encoding
input = File.read "#{MARKDOWN_TEST_PATH}/Amps and angle encoding.text"
doc = @parser.parse input
expected =
doc(
para("AT&T has an ampersand in their name."),
para("AT&T is another way to write it."),
para("This & that."),
para("4 < 5."),
para("6 > 5."),
para("Here's a {link}[http://example.com/?foo=1&bar=2] with " +
"an ampersand in the URL."),
para("Here's a link with an amersand in the link text: " +
"{AT&T}[http://att.com/]."),
para("Here's an inline {link}[/script?foo=1&bar=2]."),
para("Here's an inline {link}[/script?foo=1&bar=2]."))
assert_equal expected, doc
end
def test_auto_links
input = File.read "#{MARKDOWN_TEST_PATH}/Auto links.text"
doc = @parser.parse input
# TODO verify rdoc auto-links too
expected =
doc(
para("Link: http://example.com/."),
para("With an ampersand: http://example.com/?foo=1&bar=2"),
list(:BULLET,
item(nil, para("In a list?")),
item(nil, para("http://example.com/")),
item(nil, para("It should."))),
block(
para("Blockquoted: http://example.com/")),
para("Auto-links should not occur here: " +
"<code><http://example.com/></code>"),
verb("or here: <http://example.com/>\n"))
assert_equal expected, doc
end
def test_backslash_escapes
input = File.read "#{MARKDOWN_TEST_PATH}/Backslash escapes.text"
doc = @parser.parse input
expected =
doc(
para("These should all get escaped:"),
para("Backslash: \\"),
para("Backtick: `"),
para("Asterisk: *"),
para("Underscore: _"),
para("Left brace: {"),
para("Right brace: }"),
para("Left bracket: ["),
para("Right bracket: ]"),
para("Left paren: ("),
para("Right paren: )"),
para("Greater-than: >"),
para("Hash: #"),
para("Period: ."),
para("Bang: !"),
para("Plus: +"),
para("Minus: -"),
para("These should not, because they occur within a code block:"),
verb("Backslash: \\\\\n",
"\n",
"Backtick: \\`\n",
"\n",
"Asterisk: \\*\n",
"\n",
"Underscore: \\_\n",
"\n",
"Left brace: \\{\n",
"\n",
"Right brace: \\}\n",
"\n",
"Left bracket: \\[\n",
"\n",
"Right bracket: \\]\n",
"\n",
"Left paren: \\(\n",
"\n",
"Right paren: \\)\n",
"\n",
"Greater-than: \\>\n",
"\n",
"Hash: \\#\n",
"\n",
"Period: \\.\n",
"\n",
"Bang: \\!\n",
"\n",
"Plus: \\+\n",
"\n",
"Minus: \\-\n"),
para("Nor should these, which occur in code spans:"),
para("Backslash: <code>\\\\</code>"),
para("Backtick: <code>\\`</code>"),
para("Asterisk: <code>\\*</code>"),
para("Underscore: <code>\\_</code>"),
para("Left brace: <code>\\{</code>"),
para("Right brace: <code>\\}</code>"),
para("Left bracket: <code>\\[</code>"),
para("Right bracket: <code>\\]</code>"),
para("Left paren: <code>\\(</code>"),
para("Right paren: <code>\\)</code>"),
para("Greater-than: <code>\\></code>"),
para("Hash: <code>\\#</code>"),
para("Period: <code>\\.</code>"),
para("Bang: <code>\\!</code>"),
para("Plus: <code>\\+</code>"),
para("Minus: <code>\\-</code>"),
para("These should get escaped, even though they're matching pairs for\n" +
"other Markdown constructs:"),
para("\*asterisks\*"),
para("\_underscores\_"),
para("`backticks`"),
para("This is a code span with a literal backslash-backtick " +
"sequence: <code>\\`</code>"),
para("This is a tag with unescaped backticks " +
"<span attr='`ticks`'>bar</span>."),
para("This is a tag with backslashes " +
"<span attr='\\\\backslashes\\\\'>bar</span>."))
assert_equal expected, doc
end
def test_blockquotes_with_code_blocks
input = File.read "#{MARKDOWN_TEST_PATH}/Blockquotes with code blocks.text"
doc = @parser.parse input
expected =
doc(
block(
para("Example:"),
verb("sub status {\n",
" print \"working\";\n",
"}\n"),
para("Or:"),
verb("sub status {\n",
" return \"working\";\n",
"}\n")))
assert_equal expected, doc
end
def test_code_blocks
input = File.read "#{MARKDOWN_TEST_PATH}/Code Blocks.text"
doc = @parser.parse input
expected =
doc(
verb("code block on the first line\n"),
para("Regular text."),
verb("code block indented by spaces\n"),
para("Regular text."),
verb("the lines in this block \n",
"all contain trailing spaces \n"),
para("Regular Text."),
verb("code block on the last line\n"))
assert_equal expected, doc
end
def test_code_spans
input = File.read "#{MARKDOWN_TEST_PATH}/Code Spans.text"
doc = @parser.parse input
expected = doc(
para("<code><test a=\"</code> content of attribute <code>\"></code>"),
para("Fix for backticks within HTML tag: " +
"<span attr='`ticks`'>like this</span>"),
para("Here's how you put <code>`backticks`</code> in a code span."))
assert_equal expected, doc
end
def test_hard_wrapped_paragraphs_with_list_like_lines
input = File.read "#{MARKDOWN_TEST_PATH}/Hard-wrapped paragraphs with list-like lines.text"
doc = @parser.parse input
expected =
doc(
para("In Markdown 1.0.0 and earlier. Version\n" +
"8. This line turns into a list item.\n" +
"Because a hard-wrapped line in the\n" +
"middle of a paragraph looked like a\n" +
"list item."),
para("Here's one with a bullet.\n" +
"* criminey."))
assert_equal expected, doc
end
def test_horizontal_rules
input = File.read "#{MARKDOWN_TEST_PATH}/Horizontal rules.text"
doc = @parser.parse input
expected =
doc(
para("Dashes:"),
rule(1),
rule(1),
rule(1),
rule(1),
verb("---\n"),
rule(1),
rule(1),
rule(1),
rule(1),
verb("- - -\n"),
para("Asterisks:"),
rule(1),
rule(1),
rule(1),
rule(1),
verb("***\n"),
rule(1),
rule(1),
rule(1),
rule(1),
verb("* * *\n"),
para("Underscores:"),
rule(1),
rule(1),
rule(1),
rule(1),
verb("___\n"),
rule(1),
rule(1),
rule(1),
rule(1),
verb("_ _ _\n"))
assert_equal expected, doc
end
def test_inline_html_advanced
input = File.read "#{MARKDOWN_TEST_PATH}/Inline HTML (Advanced).text"
@parser.html = true
doc = @parser.parse input
expected =
doc(
para("Simple block on one line:"),
raw("<div>foo</div>"),
para("And nested without indentation:"),
raw(<<-RAW.chomp))
<div>
<div>
<div>
foo
</div>
<div style=">"/>
</div>
<div>bar</div>
</div>
RAW
assert_equal expected, doc
end
def test_inline_html_simple
input = File.read "#{MARKDOWN_TEST_PATH}/Inline HTML (Simple).text"
@parser.html = true
doc = @parser.parse input
expected =
doc(
para("Here's a simple block:"),
raw("<div>\n\tfoo\n</div>"),
para("This should be a code block, though:"),
verb("<div>\n",
"\tfoo\n",
"</div>\n"),
para("As should this:"),
verb("<div>foo</div>\n"),
para("Now, nested:"),
raw("<div>\n\t<div>\n\t\t<div>\n\t\t\tfoo\n" +
"\t\t</div>\n\t</div>\n</div>"),
para("This should just be an HTML comment:"),
raw("<!-- Comment -->"),
para("Multiline:"),
raw("<!--\nBlah\nBlah\n-->"),
para("Code block:"),
verb("<!-- Comment -->\n"),
para("Just plain comment, with trailing spaces on the line:"),
raw("<!-- foo -->"),
para("Code:"),
verb("<hr />\n"),
para("Hr's:"),
raw("<hr>"),
raw("<hr/>"),
raw("<hr />"),
raw("<hr>"),
raw("<hr/>"),
raw("<hr />"),
raw("<hr class=\"foo\" id=\"bar\" />"),
raw("<hr class=\"foo\" id=\"bar\"/>"),
raw("<hr class=\"foo\" id=\"bar\" >"))
assert_equal expected, doc
end
def test_inline_html_comments
input = File.read "#{MARKDOWN_TEST_PATH}/Inline HTML comments.text"
doc = @parser.parse input
expected =
doc(
para("Paragraph one."),
raw("<!-- This is a simple comment -->"),
raw("<!--\n\tThis is another comment.\n-->"),
para("Paragraph two."),
raw("<!-- one comment block -- -- with two comments -->"),
para("The end."))
assert_equal expected, doc
end
def test_links_inline_style
input = File.read "#{MARKDOWN_TEST_PATH}/Links, inline style.text"
doc = @parser.parse input
expected =
doc(
para("Just a {URL}[/url/]."),
para("{URL and title}[/url/]."),
para("{URL and title}[/url/]."),
para("{URL and title}[/url/]."),
para("{URL and title}[/url/]."),
para("{Empty}[]."))
assert_equal expected, doc
end
def test_links_reference_style
input = File.read "#{MARKDOWN_TEST_PATH}/Links, reference style.text"
doc = @parser.parse input
expected =
doc(
para("Foo {bar}[/url/]."),
para("Foo {bar}[/url/]."),
para("Foo {bar}[/url/]."),
para("With {embedded [brackets]}[/url/]."),
para("Indented {once}[/url]."),
para("Indented {twice}[/url]."),
para("Indented {thrice}[/url]."),
para("Indented [four][] times."),
verb("[four]: /url\n"),
rule(1),
para("{this}[foo] should work"),
para("So should {this}[foo]."),
para("And {this}[foo]."),
para("And {this}[foo]."),
para("And {this}[foo]."),
para("But not [that] []."),
para("Nor [that][]."),
para("Nor [that]."),
para("[Something in brackets like {this}[foo] should work]"),
para("[Same with {this}[foo].]"),
para("In this case, {this}[/somethingelse/] points to something else."),
para("Backslashing should suppress [this] and [this]."),
rule(1),
para("Here's one where the {link breaks}[/url/] across lines."),
para("Here's another where the {link breaks}[/url/] across lines, " +
"but with a line-ending space."))
assert_equal expected, doc
end
def test_links_shortcut_references
input = File.read "#{MARKDOWN_TEST_PATH}/Links, shortcut references.text"
doc = @parser.parse input
expected =
doc(
para("This is the {simple case}[/simple]."),
para("This one has a {line break}[/foo]."),
para("This one has a {line break}[/foo] with a line-ending space."),
para("{this}[/that] and the {other}[/other]"))
assert_equal expected, doc
end
def test_literal_quotes_in_titles
input = File.read "#{MARKDOWN_TEST_PATH}/Literal quotes in titles.text"
doc = @parser.parse input
# TODO support title attribute
expected =
doc(
para("Foo {bar}[/url/]."),
para("Foo {bar}[/url/]."))
assert_equal expected, doc
end
def test_markdown_documentation_basics
input = File.read "#{MARKDOWN_TEST_PATH}/Markdown Documentation - Basics.text"
doc = @parser.parse input
expected =
doc(
head(1, "Markdown: Basics"),
raw(<<-RAW.chomp),
<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
<li><a class="selected" title="Markdown Basics">Basics</a></li>
<li><a href="/projects/markdown/syntax" title="Markdown Syntax Documentation">Syntax</a></li>
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
</ul>
RAW
head(2, "Getting the Gist of Markdown's Formatting Syntax"),
para("This page offers a brief overview of what it's like to use Markdown.\n" +
"The {syntax page}[/projects/markdown/syntax] provides complete, detailed documentation for\n" +
"every feature, but Markdown should be very easy to pick up simply by\n" +
"looking at a few examples of it in action. The examples on this page\n" +
"are written in a before/after style, showing example syntax and the\n" +
"HTML output produced by Markdown."),
para("It's also helpful to simply try Markdown out; the {Dingus}[/projects/markdown/dingus] is a\n" +
"web application that allows you type your own Markdown-formatted text\n" +
"and translate it to XHTML."),
para("<b>Note:</b> This document is itself written using Markdown; you\n" +
"can {see the source for it by adding '.text' to the URL}[/projects/markdown/basics.text]."),
head(2, "Paragraphs, Headers, Blockquotes"),
para("A paragraph is simply one or more consecutive lines of text, separated\n" +
"by one or more blank lines. (A blank line is any line that looks like a\n" +
"blank line -- a line containing nothing spaces or tabs is considered\n" +
"blank.) Normal paragraphs should not be intended with spaces or tabs."),
para("Markdown offers two styles of headers: _Setext_ and _atx_.\n" +
"Setext-style headers for <code><h1></code> and <code><h2></code> are created by\n" +
"\"underlining\" with equal signs (<code>=</code>) and hyphens (<code>-</code>), respectively.\n" +
"To create an atx-style header, you put 1-6 hash marks (<code>#</code>) at the\n" +
"beginning of the line -- the number of hashes equals the resulting\n" +
"HTML header level."),
para("Blockquotes are indicated using email-style '<code>></code>' angle brackets."),
para("Markdown:"),
verb("A First Level Header\n",
"====================\n",
"\n",
"A Second Level Header\n",
"---------------------\n",
"\n",
"Now is the time for all good men to come to\n",
"the aid of their country. This is just a\n",
"regular paragraph.\n",
"\n",
"The quick brown fox jumped over the lazy\n",
"dog's back.\n",
"\n",
"### Header 3\n",
"\n",
"> This is a blockquote.\n",
"> \n",
"> This is the second paragraph in the blockquote.\n",
">\n",
"> ## This is an H2 in a blockquote\n"),
para("Output:"),
verb("<h1>A First Level Header</h1>\n",
"\n",
"<h2>A Second Level Header</h2>\n",
"\n",
"<p>Now is the time for all good men to come to\n",
"the aid of their country. This is just a\n",
"regular paragraph.</p>\n",
"\n",
"<p>The quick brown fox jumped over the lazy\n",
"dog's back.</p>\n",
"\n",
"<h3>Header 3</h3>\n",
"\n",
"<blockquote>\n",
" <p>This is a blockquote.</p>\n",
"\n",
" <p>This is the second paragraph in the blockquote.</p>\n",
"\n",
" <h2>This is an H2 in a blockquote</h2>\n",
"</blockquote>\n"),
head(3, "Phrase Emphasis"),
para("Markdown uses asterisks and underscores to indicate spans of emphasis."),
para("Markdown:"),
verb("Some of these words *are emphasized*.\n",
"Some of these words _are emphasized also_.\n",
"\n",
"Use two asterisks for **strong emphasis**.\n",
"Or, if you prefer, __use two underscores instead__.\n"),
para("Output:"),
verb("<p>Some of these words <em>are emphasized</em>.\n",
"Some of these words <em>are emphasized also</em>.</p>\n",
"\n",
"<p>Use two asterisks for <strong>strong emphasis</strong>.\n",
"Or, if you prefer, <strong>use two underscores instead</strong>.</p>\n"),
head(2, "Lists"),
para("Unordered (bulleted) lists use asterisks, pluses, and hyphens (<code>*</code>,\n" +
"<code>+</code>, and <code>-</code>) as list markers. These three markers are\n" +
"interchangeable; this:"),
verb("* Candy.\n",
"* Gum.\n",
"* Booze.\n"),
para("this:"),
verb("+ Candy.\n",
"+ Gum.\n",
"+ Booze.\n"),
para("and this:"),
verb("- Candy.\n",
"- Gum.\n",
"- Booze.\n"),
para("all produce the same output:"),
verb("<ul>\n",
"<li>Candy.</li>\n",
"<li>Gum.</li>\n",
"<li>Booze.</li>\n",
"</ul>\n"),
para("Ordered (numbered) lists use regular numbers, followed by periods, as\n" +
"list markers:"),
verb("1. Red\n",
"2. Green\n",
"3. Blue\n"),
para("Output:"),
verb("<ol>\n",
"<li>Red</li>\n",
"<li>Green</li>\n",
"<li>Blue</li>\n",
"</ol>\n"),
para("If you put blank lines between items, you'll get <code><p></code> tags for the\n" +
"list item text. You can create multi-paragraph list items by indenting\n" +
"the paragraphs by 4 spaces or 1 tab:"),
verb("* A list item.\n",
"\n",
" With multiple paragraphs.\n",
"\n",
"* Another item in the list.\n"),
para("Output:"),
verb("<ul>\n",
"<li><p>A list item.</p>\n",
"<p>With multiple paragraphs.</p></li>\n",
"<li><p>Another item in the list.</p></li>\n",
"</ul>\n"),
head(3, "Links"),
para("Markdown supports two styles for creating links: _inline_ and\n" +
"_reference_. With both styles, you use square brackets to delimit the\n" +
"text you want to turn into a link."),
para("Inline-style links use parentheses immediately after the link text.\n" +
"For example:"),
verb("This is an [example link](http://example.com/).\n"),
para("Output:"),
verb("<p>This is an <a href=\"http://example.com/\">\n",
"example link</a>.</p>\n"),
para("Optionally, you may include a title attribute in the parentheses:"),
verb("This is an [example link](http://example.com/ \"With a Title\").\n"),
para("Output:"),
verb("<p>This is an <a href=\"http://example.com/\" title=\"With a Title\">\n",
"example link</a>.</p>\n"),
para("Reference-style links allow you to refer to your links by names, which\n" +
"you define elsewhere in your document:"),
verb("I get 10 times more traffic from [Google][1] than from\n",
"[Yahoo][2] or [MSN][3].\n",
"\n",
"[1]: http://google.com/ \"Google\"\n",
"[2]: http://search.yahoo.com/ \"Yahoo Search\"\n",
"[3]: http://search.msn.com/ \"MSN Search\"\n"),
para("Output:"),
verb("<p>I get 10 times more traffic from <a href=\"http://google.com/\"\n",
"title=\"Google\">Google</a> than from <a href=\"http://search.yahoo.com/\"\n",
"title=\"Yahoo Search\">Yahoo</a> or <a href=\"http://search.msn.com/\"\n",
"title=\"MSN Search\">MSN</a>.</p>\n"),
para("The title attribute is optional. Link names may contain letters,\n" +
"numbers and spaces, but are _not_ case sensitive:"),
verb("I start my morning with a cup of coffee and\n",
"[The New York Times][NY Times].\n",
"\n",
"[ny times]: http://www.nytimes.com/\n"),
para("Output:"),
verb("<p>I start my morning with a cup of coffee and\n",
"<a href=\"http://www.nytimes.com/\">The New York Times</a>.</p>\n"),
head(3, "Images"),
para("Image syntax is very much like link syntax."),
para("Inline (titles are optional):"),
verb("\n"),
para("Reference-style:"),
verb("![alt text][id]\n",
"\n",
"[id]: /path/to/img.jpg \"Title\"\n"),
para("Both of the above examples produce the same output:"),
verb("<img src=\"/path/to/img.jpg\" alt=\"alt text\" title=\"Title\" />\n"),
head(3, "Code"),
para("In a regular paragraph, you can create code span by wrapping text in\n" +
"backtick quotes. Any ampersands (<code>&</code>) and angle brackets (<code><</code> or\n" +
"<code>></code>) will automatically be translated into HTML entities. This makes\n" +
"it easy to use Markdown to write about HTML example code:"),
verb(
"I strongly recommend against using any `<blink>` tags.\n",
"\n",
"I wish SmartyPants used named entities like `—`\n",
"instead of decimal-encoded entites like `—`.\n"),
para("Output:"),
verb("<p>I strongly recommend against using any\n",
"<code><blink></code> tags.</p>\n",
"\n",
"<p>I wish SmartyPants used named entities like\n",
"<code>&mdash;</code> instead of decimal-encoded\n",
"entites like <code>&#8212;</code>.</p>\n"),
para("To specify an entire block of pre-formatted code, indent every line of\n" +
"the block by 4 spaces or 1 tab. Just like with code spans, <code>&</code>, <code><</code>,\n" +
"and <code>></code> characters will be escaped automatically."),
para("Markdown:"),
verb("If you want your page to validate under XHTML 1.0 Strict,\n",
"you've got to put paragraph tags in your blockquotes:\n",
"\n",
" <blockquote>\n",
" <p>For example.</p>\n",
" </blockquote>\n"),
para("Output:"),
verb("<p>If you want your page to validate under XHTML 1.0 Strict,\n",
"you've got to put paragraph tags in your blockquotes:</p>\n",
"\n",
"<pre><code><blockquote>\n",
" <p>For example.</p>\n",
"</blockquote>\n",
"</code></pre>\n"))
assert_equal expected, doc
end
def test_markdown_documentation_syntax
input = File.read "#{MARKDOWN_TEST_PATH}/Markdown Documentation - Syntax.text"
doc = @parser.parse input
expected =
doc(
head(1, "Markdown: Syntax"),
raw(<<-RAW.chomp),
<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
<li><a href="/projects/markdown/basics" title="Markdown Basics">Basics</a></li>
<li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
</ul>
RAW
list(:BULLET,
item(nil,
para("{Overview}[#overview]"),
list(:BULLET,
item(nil,
para("{Philosophy}[#philosophy]")),
item(nil,
para("{Inline HTML}[#html]")),
item(nil,
para("{Automatic Escaping for Special Characters}[#autoescape]")))),
item(nil,
para("{Block Elements}[#block]"),
list(:BULLET,
item(nil,
para("{Paragraphs and Line Breaks}[#p]")),
item(nil,
para("{Headers}[#header]")),
item(nil,
para("{Blockquotes}[#blockquote]")),
item(nil,
para("{Lists}[#list]")),
item(nil,
para("{Code Blocks}[#precode]")),
item(nil,
para("{Horizontal Rules}[#hr]")))),
item(nil,
para("{Span Elements}[#span]"),
list(:BULLET,
item(nil,
para("{Links}[#link]")),
item(nil,
para("{Emphasis}[#em]")),
item(nil,
para("{Code}[#code]")),
item(nil,
para("{Images}[#img]")))),
item(nil,
para("{Miscellaneous}[#misc]"),
list(:BULLET,
item(nil,
para("{Backslash Escapes}[#backslash]")),
item(nil,
para("{Automatic Links}[#autolink]"))))),
para("<b>Note:</b> This document is itself written using Markdown; you\n" +
"can {see the source for it by adding '.text' to the URL}[/projects/markdown/syntax.text]."),
rule(1),
raw("<h2 id=\"overview\">Overview</h2>"),
raw("<h3 id=\"philosophy\">Philosophy</h3>"),
para("Markdown is intended to be as easy-to-read and easy-to-write as is feasible."),
para("Readability, however, is emphasized above all else. A Markdown-formatted\n" +
"document should be publishable as-is, as plain text, without looking\n" +
"like it's been marked up with tags or formatting instructions. While\n" +
"Markdown's syntax has been influenced by several existing text-to-HTML\n" +
"filters -- including {Setext}[http://docutils.sourceforge.net/mirror/setext.html], {atx}[http://www.aaronsw.com/2002/atx/], {Textile}[http://textism.com/tools/textile/], {reStructuredText}[http://docutils.sourceforge.net/rst.html],\n" +
"{Grutatext}[http://www.triptico.com/software/grutatxt.html], and {EtText}[http://ettext.taint.org/doc/] -- the single biggest source of\n" +
"inspiration for Markdown's syntax is the format of plain text email."),
para("To this end, Markdown's syntax is comprised entirely of punctuation\n" +
"characters, which punctuation characters have been carefully chosen so\n" +
"as to look like what they mean. E.g., asterisks around a word actually\n" +
"look like \*emphasis\*. Markdown lists look like, well, lists. Even\n" +
"blockquotes look like quoted passages of text, assuming you've ever\n" +
"used email."),
raw("<h3 id=\"html\">Inline HTML</h3>"),
para("Markdown's syntax is intended for one purpose: to be used as a\n" +
"format for _writing_ for the web."),
para("Markdown is not a replacement for HTML, or even close to it. Its\n" +
"syntax is very small, corresponding only to a very small subset of\n" +
"HTML tags. The idea is _not_ to create a syntax that makes it easier\n" +
"to insert HTML tags. In my opinion, HTML tags are already easy to\n" +
"insert. The idea for Markdown is to make it easy to read, write, and\n" +
"edit prose. HTML is a _publishing_ format; Markdown is a _writing_\n" +
"format. Thus, Markdown's formatting syntax only addresses issues that\n" +
"can be conveyed in plain text."),
para("For any markup that is not covered by Markdown's syntax, you simply\n" +
"use HTML itself. There's no need to preface it or delimit it to\n" +
"indicate that you're switching from Markdown to HTML; you just use\n" +
"the tags."),
para("The only restrictions are that block-level HTML elements -- e.g. <code><div></code>,\n" +
"<code><table></code>, <code><pre></code>, <code><p></code>, etc. -- must be separated from surrounding\n" +
"content by blank lines, and the start and end tags of the block should\n" +
"not be indented with tabs or spaces. Markdown is smart enough not\n" +
"to add extra (unwanted) <code><p></code> tags around HTML block-level tags."),
para("For example, to add an HTML table to a Markdown article:"),
verb("This is a regular paragraph.\n",
"\n",
"<table>\n",
" <tr>\n",
" <td>Foo</td>\n",
" </tr>\n",
"</table>\n",
"\n",
"This is another regular paragraph.\n"),
para("Note that Markdown formatting syntax is not processed within block-level\n" +
"HTML tags. E.g., you can't use Markdown-style <code>*emphasis*</code> inside an\n" +
"HTML block."),
para("Span-level HTML tags -- e.g. <code><span></code>, <code><cite></code>, or <code><del></code> -- can be\n" +
"used anywhere in a Markdown paragraph, list item, or header. If you\n" +
"want, you can even use HTML tags instead of Markdown formatting; e.g. if\n" +
"you'd prefer to use HTML <code><a></code> or <code><img></code> tags instead of Markdown's\n" +
"link or image syntax, go right ahead."),
para("Unlike block-level HTML tags, Markdown syntax _is_ processed within\n" +
"span-level tags."),
raw("<h3 id=\"autoescape\">Automatic Escaping for Special Characters</h3>"),
para("In HTML, there are two characters that demand special treatment: <code><</code>\n" +
"and <code>&</code>. Left angle brackets are used to start tags; ampersands are\n" +
"used to denote HTML entities. If you want to use them as literal\n" +
"characters, you must escape them as entities, e.g. <code><</code>, and\n" +
"<code>&</code>."),
para("Ampersands in particular are bedeviling for web writers. If you want to\n" +
"write about 'AT&T', you need to write '<code>AT&T</code>'. You even need to\n" +
"escape ampersands within URLs. Thus, if you want to link to:"),
verb("http://images.google.com/images?num=30&q=larry+bird\n"),
para("you need to encode the URL as:"),
verb("http://images.google.com/images?num=30&q=larry+bird\n"),
para("in your anchor tag <code>href</code> attribute. Needless to say, this is easy to\n" +
"forget, and is probably the single most common source of HTML validation\n" +
"errors in otherwise well-marked-up web sites."),
para("Markdown allows you to use these characters naturally, taking care of\n" +
"all the necessary escaping for you. If you use an ampersand as part of\n" +
"an HTML entity, it remains unchanged; otherwise it will be translated\n" +
"into <code>&</code>."),
para("So, if you want to include a copyright symbol in your article, you can write:"),
verb("©\n"),
para("and Markdown will leave it alone. But if you write:"),
verb("AT&T\n"),
para("Markdown will translate it to:"),
verb("AT&T\n"),
para("Similarly, because Markdown supports {inline HTML}[#html], if you use\n" +
"angle brackets as delimiters for HTML tags, Markdown will treat them as\n" +
"such. But if you write:"),
verb("4 < 5\n"),
para("Markdown will translate it to:"),
verb("4 < 5\n"),
para("However, inside Markdown code spans and blocks, angle brackets and\n" +
"ampersands are _always_ encoded automatically. This makes it easy to use\n" +
"Markdown to write about HTML code. (As opposed to raw HTML, which is a\n" +
"terrible format for writing about HTML syntax, because every single <code><</code>\n" +
"and <code>&</code> in your example code needs to be escaped.)"),
rule(1),
raw("<h2 id=\"block\">Block Elements</h2>"),
raw("<h3 id=\"p\">Paragraphs and Line Breaks</h3>"),
para("A paragraph is simply one or more consecutive lines of text, separated\n" +
"by one or more blank lines. (A blank line is any line that looks like a\n" +
"blank line -- a line containing nothing but spaces or tabs is considered\n" +
"blank.) Normal paragraphs should not be intended with spaces or tabs."),
para("The implication of the \"one or more consecutive lines of text\" rule is\n" +
"that Markdown supports \"hard-wrapped\" text paragraphs. This differs\n" +
"significantly from most other text-to-HTML formatters (including Movable\n" +
"Type's \"Convert Line Breaks\" option) which translate every line break\n" +
"character in a paragraph into a <code><br /></code> tag."),
para("When you _do_ want to insert a <code><br /></code> break tag using Markdown, you\n" +
"end a line with two or more spaces, then type return."),
para("Yes, this takes a tad more effort to create a <code><br /></code>, but a simplistic\n" +
"\"every line break is a <code><br /></code>\" rule wouldn't work for Markdown.\n" +
"Markdown's email-style {blockquoting}[#blockquote] and multi-paragraph {list items}[#list]\n" +