-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathprocessor_spec.rb
1882 lines (1626 loc) · 56.1 KB
/
processor_spec.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
require "active_support/core_ext/string/strip"
describe Qiita::Markdown::Processor do
describe "#call" do
subject do
result[:output].to_s
end
let(:context) do
{ hostname: "example.com" }
end
let(:markdown) do
raise NotImplementedError
end
let(:result) do
described_class.new(context).call(markdown)
end
shared_examples_for "basic markdown syntax" do
context "with valid condition" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
example
MARKDOWN
end
it "returns a Hash with HTML output and other metadata" do
expect(result[:codes]).to be_an Array
expect(result[:mentioned_usernames]).to be_an Array
expect(result[:output]).to be_a Nokogiri::HTML::DocumentFragment
end
end
context "with HTML-characters" do
let(:markdown) do
"<>&"
end
it "sanitizes them" do
should eq <<-HTML.strip_heredoc
<p><>&</p>
HTML
end
end
context "with email address" do
let(:markdown) do
end
it "replaces with mailto link" do
should eq <<-HTML.strip_heredoc
<p><a href="mailto:[email protected]" class="autolink">[email protected]</a></p>
HTML
end
end
context "with headings" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
# a
## a
### a
### a
MARKDOWN
end
it "adds ID for ToC" do
should eq <<-HTML.strip_heredoc
<h1>
<span id="a" class="fragment"></span><a href="#a"><i class="fa fa-link"></i></a>a</h1>
<h2>
<span id="a-1" class="fragment"></span><a href="#a-1"><i class="fa fa-link"></i></a>a</h2>
<h3>
<span id="a-2" class="fragment"></span><a href="#a-2"><i class="fa fa-link"></i></a>a</h3>
<h3>
<span id="a-3" class="fragment"></span><a href="#a-3"><i class="fa fa-link"></i></a>a</h3>
HTML
end
end
context "with heading whose title includes special HTML characters" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
# <b>R&B</b>
MARKDOWN
end
it "generates fragment identifier by sanitizing the special characters in the title" do
should eq <<-HTML.strip_heredoc
<h1>
<span id="rb" class="fragment"></span><a href="#rb"><i class="fa fa-link"></i></a><b>R&B</b>
</h1>
HTML
end
end
context "with manually inputted heading HTML tags without id attribute" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<h1>foo</h1>
MARKDOWN
end
it "does nothing" do
should eq <<-HTML.strip_heredoc
<h1>foo</h1>
HTML
end
end
context "with code" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```foo.rb
puts 'hello world'
```
MARKDOWN
end
it "returns detected codes" do
expect(result[:codes]).to eq [
{
code: "puts 'hello world'\n",
filename: "foo.rb",
language: "ruby",
},
]
end
end
context "with code & filename" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```example.rb
1
```
MARKDOWN
end
it "returns code-frame, code-lang, and highlighted pre element" do
should eq <<-HTML.strip_heredoc
<div class="code-frame" data-lang="ruby">
<div class="code-lang"><span class="bold">example.rb</span></div>
<div class="highlight"><pre class="codehilite"><code><span class="mi">1</span>
</code></pre></div>
</div>
HTML
end
end
context "with code & filename with .php" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```example.php
1
```
MARKDOWN
end
it "returns PHP code-frame" do
should eq <<-HTML.strip_heredoc
<div class="code-frame" data-lang="php">
<div class="code-lang"><span class="bold">example.php</span></div>
<div class="highlight"><pre class="codehilite"><code><span class="mi">1</span>
</code></pre></div>
</div>
HTML
end
end
context "with code & no filename" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```ruby
1
```
MARKDOWN
end
it "returns code-frame and highlighted pre element" do
should eq <<-HTML.strip_heredoc
<div class="code-frame" data-lang="ruby"><div class="highlight"><pre class="codehilite"><code><span class="mi">1</span>
</code></pre></div></div>
HTML
end
end
context "with undefined but aliased language" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```zsh
true
```
MARKDOWN
end
it "returns aliased language name" do
expect(result[:codes]).to eq [
{
code: "true\n",
filename: nil,
language: "bash",
},
]
end
end
context "with code with leading and trailing newlines" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```
foo
```
MARKDOWN
end
it "does not strip the newlines" do
should eq <<-HTML.strip_heredoc
<div class="code-frame" data-lang="text"><div class="highlight"><pre class="codehilite"><code>
foo
</code></pre></div></div>
HTML
end
end
context "with mention" do
let(:markdown) do
"@alice"
end
it "replaces mention with link" do
should include(<<-HTML.strip_heredoc.rstrip)
<a href="/alice" class="user-mention js-hovercard" title="alice" data-hovercard-target-type="user" data-hovercard-target-name="alice">@alice</a>
HTML
end
end
context "with mention to short name user" do
let(:markdown) do
"@al"
end
it "replaces mention with link" do
should include(<<-HTML.strip_heredoc.rstrip)
<a href="/al" class="user-mention js-hovercard" title="al" data-hovercard-target-type="user" data-hovercard-target-name="al">@al</a>
HTML
end
end
context "with mentions in complex patterns" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
@alice
```
@bob
```
@charlie/@dave
@ell_en
@fran-k
@Isaac
@justin
@justin
@mallory@github
@#{'o' * 33}
@o
@o-
@-o
@o_
@_o
MARKDOWN
end
it "extracts mentions correctly" do
expect(result[:mentioned_usernames]).to eq %w[
alice
dave
ell_en
fran-k
Isaac
justin
mallory@github
o_
_o
]
end
end
context "with mention-like filename on code block" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```ruby:@alice
1
```
MARKDOWN
end
it "does not treat it as mention" do
should include(<<-HTML.strip_heredoc.rstrip)
<div class="code-frame" data-lang="ruby">
<div class="code-lang"><span class="bold">@alice</span></div>
<div class="highlight"><pre class="codehilite"><code><span class="mi">1</span>
</code></pre></div>
</div>
HTML
end
end
context "with mention in blockquote" do
let(:markdown) do
"> @alice"
end
it "does not replace mention with link" do
should include(<<-HTML.strip_heredoc.rstrip)
<blockquote>
<p>@alice</p>
</blockquote>
HTML
end
end
context "with mention to user whose name starts and ends with underscore" do
let(:markdown) do
"@_alice_"
end
it "does not emphasize the name" do
should include(<<-HTML.strip_heredoc.rstrip)
<a href="/_alice_" class="user-mention js-hovercard" title="_alice_" data-hovercard-target-type="user" data-hovercard-target-name="_alice_">@_alice_</a>
HTML
end
end
context "with allowed_usernames context" do
before do
context[:allowed_usernames] = ["alice"]
end
let(:markdown) do
<<-MARKDOWN.strip_heredoc
@alice
@bob
MARKDOWN
end
it "limits mentions to allowed usernames" do
expect(result[:mentioned_usernames]).to eq ["alice"]
end
end
context "with @all and allowed_usernames context" do
before do
context[:allowed_usernames] = ["alice", "bob"]
end
let(:markdown) do
"@all"
end
it "links it and reports all allowed users as mentioned user names" do
should include(<<-HTML.strip_heredoc.rstrip)
<a href="/" class="user-mention" title="all">@all</a>
HTML
expect(result[:mentioned_usernames]).to eq context[:allowed_usernames]
end
end
context "with @all and @alice" do
before do
context[:allowed_usernames] = ["alice", "bob"]
end
let(:markdown) do
"@all @alice"
end
it "does not duplicate mentioned user names" do
expect(result[:mentioned_usernames]).to eq context[:allowed_usernames]
end
end
context "with @all and no allowed_usernames context" do
let(:markdown) do
"@all"
end
it "does not repond to @all" do
should eq "<p>@all</p>\n"
expect(result[:mentioned_usernames]).to eq []
end
end
context "with group mention without group_memberion_url_generator" do
let(:markdown) do
"@alice/bob"
end
it "does not replace it" do
is_expected.to eq <<-HTML.strip_heredoc
<p>@alice/bob</p>
HTML
end
end
context "with group mention" do
let(:context) do
super().merge(group_mention_url_generator: lambda do |group|
"https://#{group[:team_url_name]}.example.com/groups/#{group[:group_url_name]}"
end)
end
let(:markdown) do
"@alice/bob"
end
it "replaces it with preferred link and updates :mentioned_groups" do
is_expected.to eq <<-HTML.strip_heredoc
<p><a href="https://alice.example.com/groups/bob" rel="nofollow noopener" target="_blank">@alice/bob</a></p>
HTML
expect(result[:mentioned_groups]).to eq [{
group_url_name: "bob",
team_url_name: "alice",
}]
end
end
context "with group mention following another text" do
let(:context) do
super().merge(group_mention_url_generator: lambda do |group|
"https://#{group[:team_url_name]}.example.com/groups/#{group[:group_url_name]}"
end)
end
let(:markdown) do
"FYI @alice/bob"
end
it "preserves space after preceding text" do
is_expected.to start_with("<p>FYI <a ")
end
end
context "with normal link" do
let(:markdown) do
"[](/example)"
end
it "creates link for that" do
should eq <<-HTML.strip_heredoc
<p><a href="/example"></a></p>
HTML
end
end
context "with anchor link" do
let(:markdown) do
"[](#example)"
end
it "creates link for that" do
should eq <<-HTML.strip_heredoc
<p><a href="#example"></a></p>
HTML
end
end
context "with link with title" do
let(:markdown) do
'[](/example "Title")'
end
it "creates link for that with the title" do
should eq <<-HTML.strip_heredoc
<p><a href="/example" title="Title"></a></p>
HTML
end
end
context "with raw URL" do
let(:markdown) do
"http://example.com/search?q=日本語"
end
it "creates link for that with .autolink class" do
should eq(
'<p><a href="http://example.com/search?q=%E6%97%A5%E6%9C%AC%E8%AA%9E" class="autolink">' \
"http://example.com/search?q=日本語</a></p>\n"
)
end
end
context "with javascript: link" do
let(:markdown) do
"[](javascript:alert(1))"
end
it "removes that link by creating empty a element" do
should eq <<-HTML.strip_heredoc
<p><a></a></p>
HTML
end
end
context "with emoji" do
let(:markdown) do
":+1:"
end
it "replaces it with img element" do
should include("img")
end
end
context "with emoji in pre or code element" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```
:+1:
```
MARKDOWN
end
it "does not replace it" do
should_not include("img")
end
end
context "with image notation" do
let(:markdown) do
""
end
it "wraps it in a element" do
should eq %(<p><a href="http://example.com/b.png" target="_blank">) +
%(<img src="http://example.com/b.png" alt="a"></a></p>\n)
end
end
context "with image notation with title" do
let(:markdown) do
''
end
it "generates <img> tag with the title" do
should eq %(<p><a href="http://example.com/b.png" target="_blank">) +
%(<img src="http://example.com/b.png" alt="a" title="Title"></a></p>\n)
end
end
context "with <img> tag with width and height attribute (for Retina image)" do
let(:markdown) do
'<img width="80" height="48" alt="a" src="http://example.com/b.png">'
end
it "wraps it in a element while keeping the width attribute" do
should eq %(<p><a href="http://example.com/b.png" target="_blank">) +
%(<img width="80" height="48" alt="a" src="http://example.com/b.png"></a></p>\n)
end
end
context "with colon-only label" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```:
1
```
MARKDOWN
end
it "does not replace it" do
expect(result[:codes]).to eq [
{
code: "1\n",
filename: nil,
language: nil,
},
]
end
end
context "with font element with color attribute" do
let(:markdown) do
%[<font color="red">test</font>]
end
it "allows font element with color attribute" do
should eq <<-HTML.strip_heredoc
<p>#{markdown}</p>
HTML
end
end
context "with task list" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
- [ ] a
- [x] b
MARKDOWN
end
it "inserts checkbox" do
should eq <<-HTML.strip_heredoc
<ul>
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled>a</li>
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" checked disabled>b</li>
</ul>
HTML
end
end
context "with nested task list" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
- [ ] a
- [ ] b
MARKDOWN
end
it "inserts checkbox" do
should eq <<-HTML.strip_heredoc
<ul>
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled>a
<ul>
<li class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled>b</li>
</ul>
</li>
</ul>
HTML
end
end
context "with task list in code block" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```
- [ ] a
- [x] b
```
MARKDOWN
end
it "does not replace checkbox" do
should eq <<-HTML.strip_heredoc
<div class="code-frame" data-lang="text"><div class="highlight"><pre class="codehilite"><code>- [ ] a
- [x] b
</code></pre></div></div>
HTML
end
end
context "with empty line between task list" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
- [ ] a
- [x] b
MARKDOWN
end
it "inserts checkbox" do
should eq <<-HTML.strip_heredoc
<ul>
<li class="task-list-item"><p><input type="checkbox" class="task-list-item-checkbox" disabled>a</p></li>
<li class="task-list-item"><p><input type="checkbox" class="task-list-item-checkbox" checked disabled>b</p></li>
</ul>
HTML
end
end
context "with empty list" do
let(:markdown) do
"- \n"
end
it "inserts checkbox" do
should eq <<-HTML.strip_heredoc
<ul>
<li>
</ul>
HTML
end
end
context "with text-aligned table" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
| a | b | c |
|:---|---:|:---:|
| a | b | c |
MARKDOWN
end
it "creates table element with text-align style" do
should eq <<-HTML.strip_heredoc
<table>
<thead>
<tr>
<th style="text-align: left">a</th>
<th style="text-align: right">b</th>
<th style="text-align: center">c</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">a</td>
<td style="text-align: right">b</td>
<td style="text-align: center">c</td>
</tr>
</tbody>
</table>
HTML
end
end
context "with footenotes syntax" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
[^1]
[^1]: test
MARKDOWN
end
it "generates footnotes elements" do
should eq <<-HTML.strip_heredoc
<p><sup id="fnref1"><a href="#fn1" title="test">1</a></sup></p>
<div class="footnotes">
<hr>
<ol>
<li id="fn1">
<p>test <a href="#fnref1">↩</a></p>
</li>
</ol>
</div>
HTML
end
end
context "with footenotes syntax with code block" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
```
[^1]
[^1]: test
```
MARKDOWN
end
it "generates only code blocks without footnotes" do
should eq <<-HTML.strip_heredoc
<div class="code-frame" data-lang="text"><div class="highlight"><pre class="codehilite"><code>[^1]
[^1]: test
</code></pre></div></div>
HTML
end
end
context "with manually written link inside of <sup> tag" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<sup>[Example](http://example.com/)</sup>
MARKDOWN
end
it "does not confuse the structure with automatically generated footnote reference" do
should eq <<-HTML.strip_heredoc
<p><sup><a href="http://example.com/">Example</a></sup></p>
HTML
end
end
context "with manually written <a> tag with strange href inside of <sup> tag" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<sup><a href="#foo.1">Link</a></sup>
MARKDOWN
end
it "does not confuse the structure with automatically generated footnote reference" do
should eq <<-HTML.strip_heredoc
<p><sup><a href="#foo.1">Link</a></sup></p>
HTML
end
end
context "with markdown: { footnotes: false } context" do
before do
context[:markdown] = { footnotes: false }
end
let(:markdown) do
<<-MARKDOWN.strip_heredoc
[^1]
[^1]: test
MARKDOWN
end
it "does not generate footnote elements" do
should eq <<-HTML.strip_heredoc
<p><a href="test">^1</a></p>
HTML
end
end
context "with emoji_names and emoji_url_generator context" do
before do
context[:emoji_names] = %w(foo o)
context[:emoji_url_generator] = proc do |emoji_name|
"https://example.com/foo.png" if emoji_name == "foo"
end
end
let(:markdown) do
<<-MARKDOWN.strip_heredoc
:foo: :o: :x:
MARKDOWN
end
it "replaces only the specified emoji names with img elements with custom URL" do
should include(
'<img class="emoji" title=":foo:" alt=":foo:" src="https://example.com/foo.png"',
'<img class="emoji" title=":o:" alt=":o:" src="/images/emoji/unicode/2b55.png"'
)
should_not include(
'<img class="emoji" title=":x:" alt=":x:"'
)
end
end
context "with internal URL" do
let(:markdown) do
"http://qiita.com/?a=b"
end
let(:context) do
{ hostname: "qiita.com" }
end
it "creates link which does not have rel='nofollow noopener' and target='_blank'" do
should eq(
'<p><a href="http://qiita.com/?a=b" class="autolink">' \
"http://qiita.com/?a=b</a></p>\n"
)
end
end
context "with external URL" do
let(:markdown) do
"http://external.com/?a=b"
end
let(:context) do
{ hostname: "qiita.com" }
end
it "creates link which has rel='nofollow noopener' and target='_blank'" do
should eq(
'<p><a href="http://external.com/?a=b" class="autolink" rel="nofollow noopener" target="_blank">' \
"http://external.com/?a=b</a></p>\n"
)
end
end
context "with internal anchor tag" do
let(:markdown) do
'<a href="http://qiita.com/?a=b">foobar</a>'
end
let(:context) do
{ hostname: "qiita.com" }
end
it "creates link which does not have rel='nofollow noopener' and target='_blank'" do
should eq(
"<p><a href=\"http://qiita.com/?a=b\">foobar</a></p>\n"
)
end
end
context "with external anchor tag" do
let(:markdown) do
'<a href="http://external.com/?a=b">foobar</a>'
end
let(:context) do
{ hostname: "qiita.com" }
end
it "creates link which has rel='nofollow noopener' and target='_blank'" do
should eq(
"<p><a href=\"http://external.com/?a=b\" rel=\"nofollow noopener\" target=\"_blank\">foobar</a></p>\n"
)
end
end
context "with external URL which ends with the hostname parameter" do
let(:markdown) do
"http://qqqqqqiita.com/?a=b"
end
let(:context) do
{ hostname: "qiita.com" }
end
it "creates link which has rel='nofollow noopener' and target='_blank'" do
should eq(
'<p><a href="http://qqqqqqiita.com/?a=b" class="autolink" rel="nofollow noopener" target="_blank">' \
"http://qqqqqqiita.com/?a=b</a></p>\n"
)
end
end
context "with external anchor tag which ends with the hostname parameter" do
let(:markdown) do
'<a href="http://qqqqqqiita.com/?a=b">foobar</a>'
end
let(:context) do
{ hostname: "qiita.com" }
end
it "creates link which has rel='nofollow noopener' and target='_blank'" do
should eq(
"<p><a href=\"http://qqqqqqiita.com/?a=b\" rel=\"nofollow noopener\" target=\"_blank\">foobar</a></p>\n"
)
end
end
context "with sub-domain URL of hostname parameter" do
let(:markdown) do
"http://sub.qiita.com/?a=b"
end
let(:context) do
{ hostname: "qiita.com" }
end
it "creates link which has rel='nofollow noopener' and target='_blank'" do
should eq(
'<p><a href="http://sub.qiita.com/?a=b" class="autolink" rel="nofollow noopener" target="_blank">' \
"http://sub.qiita.com/?a=b</a></p>\n"
)
end
end
context "with external anchor tag which has rel attribute" do
let(:markdown) do
'<a href="http://external.com/?a=b" rel="url">foobar</a>'
end
let(:context) do
{ hostname: "qiita.com" }
end
it "creates link which has rel='nofollow noopener' and target='_blank', and rel value is overwritten" do
should eq(
"<p><a href=\"http://external.com/?a=b\" rel=\"nofollow noopener\" target=\"_blank\">foobar</a></p>\n"
)
end
end
context "with blockquote syntax" do
let(:markdown) do
"> foo"
end
it "does not confuse it with HTML tag angle brackets" do
should eq "<blockquote>\n<p>foo</p>\n</blockquote>\n"
end
end
context "with inline code containing hexadecimal color only" do
let(:markdown) do
"`#FF0000`"
end
it "returns code element with its color" do
should eq "<p><code>#FF0000<span class=\"inline-code-color\" style=\"background-color: #FF0000;\"></span></code></p>\n"