pagedown-bootstrap-rails 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Readme.md +12 -4
- data/lib/pagedown_bootstrap/rails/version.rb +1 -1
- data/vendor/assets/javascripts/{markdown.editor.js → markdown.editor.js.erb} +2127 -2110
- data/vendor/assets/javascripts/pagedown_init.js.coffee.erb +12 -0
- data/vendor/assets/stylesheets/pagedown_bootstrap.css.scss +6 -47
- metadata +11 -15
- data/vendor/assets/images/pagedown-bootstrap-buttons.png +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a307a393788650a9f78969912ff53bdca22a9fae
|
4
|
+
data.tar.gz: ada91b0e137e1798ae79cb0765b1b7e2d5ee7b89
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee4440e135283ea4577ca6dcb24eac207b65899c8c779868eb13c7fd98912eba62df24e660c06f762fb54f50ee197c5910f616114e6cd540ad3c6caba9c86daa
|
7
|
+
data.tar.gz: 121c1e590ecf395c588b510e35dca7a7a4640463e030a549acc617b17699b134fd48a9eea253e94422535ae7dcddd4051c015b4e30f72c35f855223f8e473ea0
|
data/Readme.md
CHANGED
@@ -10,6 +10,8 @@ Add to your `Gemfile`:
|
|
10
10
|
|
11
11
|
In Rails 3.1 or Rails 3.2 this goes in the `:asset` group, but in Rails 4 it goes with the top level gems.
|
12
12
|
|
13
|
+
You will also need Bootstrap and FontAwesome for PageDown Bootstrap Rails to work.
|
14
|
+
|
13
15
|
## Usage
|
14
16
|
|
15
17
|
Require the CSS with Sprockets:
|
@@ -29,23 +31,29 @@ Or individually as you please:
|
|
29
31
|
//= require markdown.converter
|
30
32
|
//= require markdown.editor
|
31
33
|
//= require markdown.sanitizer
|
34
|
+
//= require markdown.extra
|
32
35
|
|
33
|
-
You will need to instantiate PageDown
|
36
|
+
You will need to instantiate PageDown and pagedown-bootstrap-rails comes with `pagedown_init` for you to optionally include:
|
34
37
|
|
35
38
|
$ ->
|
36
39
|
$('textarea.wmd-input').each (i, input) ->
|
37
40
|
attr = $(input).attr('id').split('wmd-input')[1]
|
38
41
|
converter = new Markdown.Converter()
|
39
42
|
Markdown.Extra.init(converter)
|
40
|
-
|
43
|
+
help =
|
44
|
+
handler: () ->
|
45
|
+
window.open('http://daringfireball.net/projects/markdown/syntax')
|
46
|
+
return false
|
47
|
+
title: "<%= I18n.t('components.markdown_editor.help', default: 'Markdown Editing Help') %>"
|
48
|
+
editor = new Markdown.Editor(converter, attr, help)
|
41
49
|
editor.run()
|
42
50
|
|
43
|
-
|
51
|
+
Just require it with Sprockets after `pagedown_bootstrap`:
|
44
52
|
|
45
53
|
//= require pagedown_bootstrap
|
46
54
|
//= require pagedown_init
|
47
55
|
|
48
|
-
|
56
|
+
I like to then use a new [SimpleForm](https://github.com/plataformatec/simple_form) input:
|
49
57
|
|
50
58
|
class PagedownInput < SimpleForm::Inputs::TextInput
|
51
59
|
def input
|
@@ -1,2110 +1,2127 @@
|
|
1
|
-
// needs Markdown.Converter.js at the moment
|
2
|
-
|
3
|
-
(function () {
|
4
|
-
|
5
|
-
var util = {},
|
6
|
-
position = {},
|
7
|
-
ui = {},
|
8
|
-
doc = window.document,
|
9
|
-
re = window.RegExp,
|
10
|
-
nav = window.navigator,
|
11
|
-
SETTINGS = { lineLength: 72 },
|
12
|
-
|
13
|
-
// Used to work around some browser bugs where we can't use feature testing.
|
14
|
-
uaSniffed = {
|
15
|
-
isIE: /msie/.test(nav.userAgent.toLowerCase()),
|
16
|
-
isIE_5or6: /msie 6/.test(nav.userAgent.toLowerCase()) || /msie 5/.test(nav.userAgent.toLowerCase()),
|
17
|
-
isOpera: /opera/.test(nav.userAgent.toLowerCase())
|
18
|
-
};
|
19
|
-
|
20
|
-
|
21
|
-
// -------------------------------------------------------------------
|
22
|
-
// YOUR CHANGES GO HERE
|
23
|
-
//
|
24
|
-
// I've tried to localize the things you are likely to change to
|
25
|
-
// this area.
|
26
|
-
// -------------------------------------------------------------------
|
27
|
-
|
28
|
-
// The text that appears on the upper part of the dialog box when
|
29
|
-
// entering links.
|
30
|
-
var
|
31
|
-
var
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
var
|
36
|
-
var
|
37
|
-
|
38
|
-
var
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
// -------------------------------------------------------------------
|
43
|
-
|
44
|
-
//
|
45
|
-
|
46
|
-
//
|
47
|
-
//
|
48
|
-
//
|
49
|
-
//
|
50
|
-
//
|
51
|
-
// -
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
hooks
|
59
|
-
hooks.
|
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
|
-
pattern =
|
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
|
-
var
|
405
|
-
var
|
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
|
-
setMode("
|
577
|
-
}
|
578
|
-
else if (keyCode ==
|
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
|
-
if (!
|
660
|
-
|
661
|
-
}
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
inputArea.
|
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
|
-
var
|
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
|
-
this.
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
chunk.
|
762
|
-
chunk.after =
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
this.
|
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
|
-
text
|
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
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
//
|
1032
|
-
// <div class="modal-
|
1033
|
-
//
|
1034
|
-
//
|
1035
|
-
//
|
1036
|
-
// </
|
1037
|
-
|
1038
|
-
//
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
//
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
// The
|
1050
|
-
|
1051
|
-
|
1052
|
-
dialog.
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
// The
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
// The
|
1084
|
-
var
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
}
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
}
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
}
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
buttons.
|
1383
|
-
buttons.
|
1384
|
-
|
1385
|
-
|
1386
|
-
buttons.
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
buttons.
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
}
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
chunk.
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
}
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
//
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
}
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
//
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
}
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
//
|
1768
|
-
//
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
|
1863
|
-
}
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
chunk.
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
}
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
return
|
1984
|
-
};
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
}
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
var
|
2028
|
-
|
2029
|
-
chunk.
|
2030
|
-
function (itemText) {
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
//
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
|
2078
|
-
//
|
2079
|
-
chunk.
|
2080
|
-
chunk.
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
1
|
+
// needs Markdown.Converter.js at the moment
|
2
|
+
|
3
|
+
(function () {
|
4
|
+
|
5
|
+
var util = {},
|
6
|
+
position = {},
|
7
|
+
ui = {},
|
8
|
+
doc = window.document,
|
9
|
+
re = window.RegExp,
|
10
|
+
nav = window.navigator,
|
11
|
+
SETTINGS = { lineLength: 72 },
|
12
|
+
|
13
|
+
// Used to work around some browser bugs where we can't use feature testing.
|
14
|
+
uaSniffed = {
|
15
|
+
isIE: /msie/.test(nav.userAgent.toLowerCase()),
|
16
|
+
isIE_5or6: /msie 6/.test(nav.userAgent.toLowerCase()) || /msie 5/.test(nav.userAgent.toLowerCase()),
|
17
|
+
isOpera: /opera/.test(nav.userAgent.toLowerCase())
|
18
|
+
};
|
19
|
+
|
20
|
+
|
21
|
+
// -------------------------------------------------------------------
|
22
|
+
// YOUR CHANGES GO HERE
|
23
|
+
//
|
24
|
+
// I've tried to localize the things you are likely to change to
|
25
|
+
// this area.
|
26
|
+
// -------------------------------------------------------------------
|
27
|
+
|
28
|
+
// The text that appears on the upper part of the dialog box when
|
29
|
+
// entering links.
|
30
|
+
var linkDialogTitle = "<%= I18n.t('components.markdown_editor.insert_link.dialog_title', default: 'Insert link') %>";
|
31
|
+
var linkInputLabel = "<%= I18n.t('components.markdown_editor.insert_link.input_label', default: 'Link URL') %>";
|
32
|
+
var linkInputPlaceholder = "http://example.com/ \"optional title\"";
|
33
|
+
var linkInputHelp = "<%= I18n.t('components.markdown_editor.insert_link.input_help', default: 'Enter URL to point link to and optional title to display when mouse is placed over the link') %>";
|
34
|
+
|
35
|
+
var imageDialogTitle = "<%= I18n.t('components.markdown_editor.insert_image.dialog_title', default: 'Insert image') %>";
|
36
|
+
var imageInputLabel = "<%= I18n.t('components.markdown_editor.insert_image.input_label', default: 'Image URL') %>";
|
37
|
+
var imageInputPlaceholder = "http://example.com/images/diagram.jpg \"optional title\"";
|
38
|
+
var imageInputHelp = "<%= I18n.t('components.markdown_editor.insert_link.input_help', default: 'Enter URL where image is located and optional title to display when mouse is placed over the image') %>";
|
39
|
+
|
40
|
+
var defaultHelpHoverTitle = "Markdown Editing Help";
|
41
|
+
|
42
|
+
// -------------------------------------------------------------------
|
43
|
+
// END OF YOUR CHANGES
|
44
|
+
// -------------------------------------------------------------------
|
45
|
+
|
46
|
+
// help, if given, should have a property "handler", the click handler for the help button,
|
47
|
+
// and can have an optional property "title" for the button's tooltip (defaults to "Markdown Editing Help").
|
48
|
+
// If help isn't given, not help button is created.
|
49
|
+
//
|
50
|
+
// The constructed editor object has the methods:
|
51
|
+
// - getConverter() returns the markdown converter object that was passed to the constructor
|
52
|
+
// - run() actually starts the editor; should be called after all necessary plugins are registered. Calling this more than once is a no-op.
|
53
|
+
// - refreshPreview() forces the preview to be updated. This method is only available after run() was called.
|
54
|
+
Markdown.Editor = function (markdownConverter, idPostfix, help) {
|
55
|
+
|
56
|
+
idPostfix = idPostfix || "";
|
57
|
+
|
58
|
+
var hooks = this.hooks = new Markdown.HookCollection();
|
59
|
+
hooks.addNoop("onPreviewRefresh"); // called with no arguments after the preview has been refreshed
|
60
|
+
hooks.addNoop("postBlockquoteCreation"); // called with the user's selection *after* the blockquote was created; should return the actual to-be-inserted text
|
61
|
+
hooks.addFalse("insertImageDialog");
|
62
|
+
/* called with one parameter: a callback to be called with the URL of the image. If the application creates
|
63
|
+
* its own image insertion dialog, this hook should return true, and the callback should be called with the chosen
|
64
|
+
* image url (or null if the user cancelled). If this hook returns false, the default dialog will be used.
|
65
|
+
*/
|
66
|
+
|
67
|
+
this.getConverter = function () {
|
68
|
+
return markdownConverter;
|
69
|
+
}
|
70
|
+
|
71
|
+
var that = this,
|
72
|
+
panels;
|
73
|
+
|
74
|
+
this.run = function () {
|
75
|
+
if (panels)
|
76
|
+
return; // already initialized
|
77
|
+
|
78
|
+
panels = new PanelCollection(idPostfix);
|
79
|
+
var commandManager = new CommandManager(hooks);
|
80
|
+
var previewManager = new PreviewManager(markdownConverter, panels, function () {
|
81
|
+
hooks.onPreviewRefresh();
|
82
|
+
});
|
83
|
+
var undoManager, uiManager;
|
84
|
+
|
85
|
+
if (!/\?noundo/.test(doc.location.href)) {
|
86
|
+
undoManager = new UndoManager(function () {
|
87
|
+
previewManager.refresh();
|
88
|
+
if (uiManager) // not available on the first call
|
89
|
+
uiManager.setUndoRedoButtonStates();
|
90
|
+
}, panels);
|
91
|
+
this.textOperation = function (f) {
|
92
|
+
undoManager.setCommandMode();
|
93
|
+
f();
|
94
|
+
that.refreshPreview();
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
uiManager = new UIManager(idPostfix, panels, undoManager, previewManager, commandManager, help);
|
99
|
+
uiManager.setUndoRedoButtonStates();
|
100
|
+
|
101
|
+
var forceRefresh = that.refreshPreview = function () {
|
102
|
+
previewManager.refresh(true);
|
103
|
+
};
|
104
|
+
|
105
|
+
forceRefresh();
|
106
|
+
};
|
107
|
+
|
108
|
+
};
|
109
|
+
|
110
|
+
// before: contains all the text in the input box BEFORE the selection.
|
111
|
+
// after: contains all the text in the input box AFTER the selection.
|
112
|
+
function Chunks() { }
|
113
|
+
|
114
|
+
// startRegex: a regular expression to find the start tag
|
115
|
+
// endRegex: a regular expresssion to find the end tag
|
116
|
+
Chunks.prototype.findTags = function (startRegex, endRegex) {
|
117
|
+
|
118
|
+
var chunkObj = this;
|
119
|
+
var regex;
|
120
|
+
|
121
|
+
if (startRegex) {
|
122
|
+
|
123
|
+
regex = util.extendRegExp(startRegex, "", "$");
|
124
|
+
|
125
|
+
this.before = this.before.replace(regex,
|
126
|
+
function (match) {
|
127
|
+
chunkObj.startTag = chunkObj.startTag + match;
|
128
|
+
return "";
|
129
|
+
});
|
130
|
+
|
131
|
+
regex = util.extendRegExp(startRegex, "^", "");
|
132
|
+
|
133
|
+
this.selection = this.selection.replace(regex,
|
134
|
+
function (match) {
|
135
|
+
chunkObj.startTag = chunkObj.startTag + match;
|
136
|
+
return "";
|
137
|
+
});
|
138
|
+
}
|
139
|
+
|
140
|
+
if (endRegex) {
|
141
|
+
|
142
|
+
regex = util.extendRegExp(endRegex, "", "$");
|
143
|
+
|
144
|
+
this.selection = this.selection.replace(regex,
|
145
|
+
function (match) {
|
146
|
+
chunkObj.endTag = match + chunkObj.endTag;
|
147
|
+
return "";
|
148
|
+
});
|
149
|
+
|
150
|
+
regex = util.extendRegExp(endRegex, "^", "");
|
151
|
+
|
152
|
+
this.after = this.after.replace(regex,
|
153
|
+
function (match) {
|
154
|
+
chunkObj.endTag = match + chunkObj.endTag;
|
155
|
+
return "";
|
156
|
+
});
|
157
|
+
}
|
158
|
+
};
|
159
|
+
|
160
|
+
// If remove is false, the whitespace is transferred
|
161
|
+
// to the before/after regions.
|
162
|
+
//
|
163
|
+
// If remove is true, the whitespace disappears.
|
164
|
+
Chunks.prototype.trimWhitespace = function (remove) {
|
165
|
+
var beforeReplacer, afterReplacer, that = this;
|
166
|
+
if (remove) {
|
167
|
+
beforeReplacer = afterReplacer = "";
|
168
|
+
} else {
|
169
|
+
beforeReplacer = function (s) {
|
170
|
+
that.before += s;
|
171
|
+
return "";
|
172
|
+
};
|
173
|
+
afterReplacer = function (s) { that.after = s + that.after; return ""; }
|
174
|
+
}
|
175
|
+
|
176
|
+
this.selection = this.selection.replace(/^(\s*)/, beforeReplacer).replace(/(\s*)$/, afterReplacer);
|
177
|
+
};
|
178
|
+
|
179
|
+
|
180
|
+
Chunks.prototype.skipLines = function (nLinesBefore, nLinesAfter, findExtraNewlines) {
|
181
|
+
|
182
|
+
if (nLinesBefore === undefined) {
|
183
|
+
nLinesBefore = 1;
|
184
|
+
}
|
185
|
+
|
186
|
+
if (nLinesAfter === undefined) {
|
187
|
+
nLinesAfter = 1;
|
188
|
+
}
|
189
|
+
|
190
|
+
nLinesBefore++;
|
191
|
+
nLinesAfter++;
|
192
|
+
|
193
|
+
var regexText;
|
194
|
+
var replacementText;
|
195
|
+
|
196
|
+
// chrome bug ... documented at: http://meta.stackoverflow.com/questions/63307/blockquote-glitch-in-editor-in-chrome-6-and-7/65985#65985
|
197
|
+
if (navigator.userAgent.match(/Chrome/)) {
|
198
|
+
"X".match(/()./);
|
199
|
+
}
|
200
|
+
|
201
|
+
this.selection = this.selection.replace(/(^\n*)/, "");
|
202
|
+
|
203
|
+
this.startTag = this.startTag + re.$1;
|
204
|
+
|
205
|
+
this.selection = this.selection.replace(/(\n*$)/, "");
|
206
|
+
this.endTag = this.endTag + re.$1;
|
207
|
+
this.startTag = this.startTag.replace(/(^\n*)/, "");
|
208
|
+
this.before = this.before + re.$1;
|
209
|
+
this.endTag = this.endTag.replace(/(\n*$)/, "");
|
210
|
+
this.after = this.after + re.$1;
|
211
|
+
|
212
|
+
if (this.before) {
|
213
|
+
|
214
|
+
regexText = replacementText = "";
|
215
|
+
|
216
|
+
while (nLinesBefore--) {
|
217
|
+
regexText += "\\n?";
|
218
|
+
replacementText += "\n";
|
219
|
+
}
|
220
|
+
|
221
|
+
if (findExtraNewlines) {
|
222
|
+
regexText = "\\n*";
|
223
|
+
}
|
224
|
+
this.before = this.before.replace(new re(regexText + "$", ""), replacementText);
|
225
|
+
}
|
226
|
+
|
227
|
+
if (this.after) {
|
228
|
+
|
229
|
+
regexText = replacementText = "";
|
230
|
+
|
231
|
+
while (nLinesAfter--) {
|
232
|
+
regexText += "\\n?";
|
233
|
+
replacementText += "\n";
|
234
|
+
}
|
235
|
+
if (findExtraNewlines) {
|
236
|
+
regexText = "\\n*";
|
237
|
+
}
|
238
|
+
|
239
|
+
this.after = this.after.replace(new re(regexText, ""), replacementText);
|
240
|
+
}
|
241
|
+
};
|
242
|
+
|
243
|
+
// end of Chunks
|
244
|
+
|
245
|
+
// A collection of the important regions on the page.
|
246
|
+
// Cached so we don't have to keep traversing the DOM.
|
247
|
+
// Also holds ieCachedRange and ieCachedScrollTop, where necessary; working around
|
248
|
+
// this issue:
|
249
|
+
// Internet explorer has problems with CSS sprite buttons that use HTML
|
250
|
+
// lists. When you click on the background image "button", IE will
|
251
|
+
// select the non-existent link text and discard the selection in the
|
252
|
+
// textarea. The solution to this is to cache the textarea selection
|
253
|
+
// on the button's mousedown event and set a flag. In the part of the
|
254
|
+
// code where we need to grab the selection, we check for the flag
|
255
|
+
// and, if it's set, use the cached area instead of querying the
|
256
|
+
// textarea.
|
257
|
+
//
|
258
|
+
// This ONLY affects Internet Explorer (tested on versions 6, 7
|
259
|
+
// and 8) and ONLY on button clicks. Keyboard shortcuts work
|
260
|
+
// normally since the focus never leaves the textarea.
|
261
|
+
function PanelCollection(postfix) {
|
262
|
+
this.buttonBar = doc.getElementById("wmd-button-bar" + postfix);
|
263
|
+
this.preview = doc.getElementById("wmd-preview" + postfix);
|
264
|
+
this.input = doc.getElementById("wmd-input" + postfix);
|
265
|
+
}
|
266
|
+
// Returns true if the DOM element is visible, false if it's hidden.
|
267
|
+
// Checks if display is anything other than none.
|
268
|
+
util.isVisible = function (elem) {
|
269
|
+
|
270
|
+
if (window.getComputedStyle) {
|
271
|
+
// Most browsers
|
272
|
+
return window.getComputedStyle(elem, null).getPropertyValue("display") !== "none";
|
273
|
+
}
|
274
|
+
else if (elem.currentStyle) {
|
275
|
+
// IE
|
276
|
+
return elem.currentStyle["display"] !== "none";
|
277
|
+
}
|
278
|
+
};
|
279
|
+
|
280
|
+
|
281
|
+
// Adds a listener callback to a DOM element which is fired on a specified
|
282
|
+
// event.
|
283
|
+
util.addEvent = function (elem, event, listener) {
|
284
|
+
if (elem.attachEvent) {
|
285
|
+
// IE only. The "on" is mandatory.
|
286
|
+
elem.attachEvent("on" + event, listener);
|
287
|
+
}
|
288
|
+
else {
|
289
|
+
// Other browsers.
|
290
|
+
elem.addEventListener(event, listener, false);
|
291
|
+
}
|
292
|
+
};
|
293
|
+
|
294
|
+
|
295
|
+
// Removes a listener callback from a DOM element which is fired on a specified
|
296
|
+
// event.
|
297
|
+
util.removeEvent = function (elem, event, listener) {
|
298
|
+
if (elem.detachEvent) {
|
299
|
+
// IE only. The "on" is mandatory.
|
300
|
+
elem.detachEvent("on" + event, listener);
|
301
|
+
}
|
302
|
+
else {
|
303
|
+
// Other browsers.
|
304
|
+
elem.removeEventListener(event, listener, false);
|
305
|
+
}
|
306
|
+
};
|
307
|
+
|
308
|
+
// Converts \r\n and \r to \n.
|
309
|
+
util.fixEolChars = function (text) {
|
310
|
+
text = text.replace(/\r\n/g, "\n");
|
311
|
+
text = text.replace(/\r/g, "\n");
|
312
|
+
return text;
|
313
|
+
};
|
314
|
+
|
315
|
+
// Extends a regular expression. Returns a new RegExp
|
316
|
+
// using pre + regex + post as the expression.
|
317
|
+
// Used in a few functions where we have a base
|
318
|
+
// expression and we want to pre- or append some
|
319
|
+
// conditions to it (e.g. adding "$" to the end).
|
320
|
+
// The flags are unchanged.
|
321
|
+
//
|
322
|
+
// regex is a RegExp, pre and post are strings.
|
323
|
+
util.extendRegExp = function (regex, pre, post) {
|
324
|
+
|
325
|
+
if (pre === null || pre === undefined) {
|
326
|
+
pre = "";
|
327
|
+
}
|
328
|
+
if (post === null || post === undefined) {
|
329
|
+
post = "";
|
330
|
+
}
|
331
|
+
|
332
|
+
var pattern = regex.toString();
|
333
|
+
var flags;
|
334
|
+
|
335
|
+
// Replace the flags with empty space and store them.
|
336
|
+
pattern = pattern.replace(/\/([gim]*)$/, function (wholeMatch, flagsPart) {
|
337
|
+
flags = flagsPart;
|
338
|
+
return "";
|
339
|
+
});
|
340
|
+
|
341
|
+
// Remove the slash delimiters on the regular expression.
|
342
|
+
pattern = pattern.replace(/(^\/|\/$)/g, "");
|
343
|
+
pattern = pre + pattern + post;
|
344
|
+
|
345
|
+
return new re(pattern, flags);
|
346
|
+
};
|
347
|
+
|
348
|
+
// UNFINISHED
|
349
|
+
// The assignment in the while loop makes jslint cranky.
|
350
|
+
// I'll change it to a better loop later.
|
351
|
+
position.getTop = function (elem, isInner) {
|
352
|
+
var result = elem.offsetTop;
|
353
|
+
if (!isInner) {
|
354
|
+
while (elem = elem.offsetParent) {
|
355
|
+
result += elem.offsetTop;
|
356
|
+
}
|
357
|
+
}
|
358
|
+
return result;
|
359
|
+
};
|
360
|
+
|
361
|
+
position.getHeight = function (elem) {
|
362
|
+
return elem.offsetHeight || elem.scrollHeight;
|
363
|
+
};
|
364
|
+
|
365
|
+
position.getWidth = function (elem) {
|
366
|
+
return elem.offsetWidth || elem.scrollWidth;
|
367
|
+
};
|
368
|
+
|
369
|
+
position.getPageSize = function () {
|
370
|
+
|
371
|
+
var scrollWidth, scrollHeight;
|
372
|
+
var innerWidth, innerHeight;
|
373
|
+
|
374
|
+
// It's not very clear which blocks work with which browsers.
|
375
|
+
if (self.innerHeight && self.scrollMaxY) {
|
376
|
+
scrollWidth = doc.body.scrollWidth;
|
377
|
+
scrollHeight = self.innerHeight + self.scrollMaxY;
|
378
|
+
}
|
379
|
+
else if (doc.body.scrollHeight > doc.body.offsetHeight) {
|
380
|
+
scrollWidth = doc.body.scrollWidth;
|
381
|
+
scrollHeight = doc.body.scrollHeight;
|
382
|
+
}
|
383
|
+
else {
|
384
|
+
scrollWidth = doc.body.offsetWidth;
|
385
|
+
scrollHeight = doc.body.offsetHeight;
|
386
|
+
}
|
387
|
+
|
388
|
+
if (self.innerHeight) {
|
389
|
+
// Non-IE browser
|
390
|
+
innerWidth = self.innerWidth;
|
391
|
+
innerHeight = self.innerHeight;
|
392
|
+
}
|
393
|
+
else if (doc.documentElement && doc.documentElement.clientHeight) {
|
394
|
+
// Some versions of IE (IE 6 w/ a DOCTYPE declaration)
|
395
|
+
innerWidth = doc.documentElement.clientWidth;
|
396
|
+
innerHeight = doc.documentElement.clientHeight;
|
397
|
+
}
|
398
|
+
else if (doc.body) {
|
399
|
+
// Other versions of IE
|
400
|
+
innerWidth = doc.body.clientWidth;
|
401
|
+
innerHeight = doc.body.clientHeight;
|
402
|
+
}
|
403
|
+
|
404
|
+
var maxWidth = Math.max(scrollWidth, innerWidth);
|
405
|
+
var maxHeight = Math.max(scrollHeight, innerHeight);
|
406
|
+
return [maxWidth, maxHeight, innerWidth, innerHeight];
|
407
|
+
};
|
408
|
+
|
409
|
+
// Handles pushing and popping TextareaStates for undo/redo commands.
|
410
|
+
// I should rename the stack variables to list.
|
411
|
+
function UndoManager(callback, panels) {
|
412
|
+
|
413
|
+
var undoObj = this;
|
414
|
+
var undoStack = []; // A stack of undo states
|
415
|
+
var stackPtr = 0; // The index of the current state
|
416
|
+
var mode = "none";
|
417
|
+
var lastState; // The last state
|
418
|
+
var timer; // The setTimeout handle for cancelling the timer
|
419
|
+
var inputStateObj;
|
420
|
+
|
421
|
+
// Set the mode for later logic steps.
|
422
|
+
var setMode = function (newMode, noSave) {
|
423
|
+
if (mode != newMode) {
|
424
|
+
mode = newMode;
|
425
|
+
if (!noSave) {
|
426
|
+
saveState();
|
427
|
+
}
|
428
|
+
}
|
429
|
+
|
430
|
+
if (!uaSniffed.isIE || mode != "moving") {
|
431
|
+
timer = setTimeout(refreshState, 1);
|
432
|
+
}
|
433
|
+
else {
|
434
|
+
inputStateObj = null;
|
435
|
+
}
|
436
|
+
};
|
437
|
+
|
438
|
+
var refreshState = function (isInitialState) {
|
439
|
+
inputStateObj = new TextareaState(panels, isInitialState);
|
440
|
+
timer = undefined;
|
441
|
+
};
|
442
|
+
|
443
|
+
this.setCommandMode = function () {
|
444
|
+
mode = "command";
|
445
|
+
saveState();
|
446
|
+
timer = setTimeout(refreshState, 0);
|
447
|
+
};
|
448
|
+
|
449
|
+
this.canUndo = function () {
|
450
|
+
return stackPtr > 1;
|
451
|
+
};
|
452
|
+
|
453
|
+
this.canRedo = function () {
|
454
|
+
if (undoStack[stackPtr + 1]) {
|
455
|
+
return true;
|
456
|
+
}
|
457
|
+
return false;
|
458
|
+
};
|
459
|
+
|
460
|
+
// Removes the last state and restores it.
|
461
|
+
this.undo = function () {
|
462
|
+
|
463
|
+
if (undoObj.canUndo()) {
|
464
|
+
if (lastState) {
|
465
|
+
// What about setting state -1 to null or checking for undefined?
|
466
|
+
lastState.restore();
|
467
|
+
lastState = null;
|
468
|
+
}
|
469
|
+
else {
|
470
|
+
undoStack[stackPtr] = new TextareaState(panels);
|
471
|
+
undoStack[--stackPtr].restore();
|
472
|
+
|
473
|
+
if (callback) {
|
474
|
+
callback();
|
475
|
+
}
|
476
|
+
}
|
477
|
+
}
|
478
|
+
|
479
|
+
mode = "none";
|
480
|
+
panels.input.focus();
|
481
|
+
refreshState();
|
482
|
+
};
|
483
|
+
|
484
|
+
// Redo an action.
|
485
|
+
this.redo = function () {
|
486
|
+
|
487
|
+
if (undoObj.canRedo()) {
|
488
|
+
|
489
|
+
undoStack[++stackPtr].restore();
|
490
|
+
|
491
|
+
if (callback) {
|
492
|
+
callback();
|
493
|
+
}
|
494
|
+
}
|
495
|
+
|
496
|
+
mode = "none";
|
497
|
+
panels.input.focus();
|
498
|
+
refreshState();
|
499
|
+
};
|
500
|
+
|
501
|
+
// Push the input area state to the stack.
|
502
|
+
var saveState = function () {
|
503
|
+
var currState = inputStateObj || new TextareaState(panels);
|
504
|
+
|
505
|
+
if (!currState) {
|
506
|
+
return false;
|
507
|
+
}
|
508
|
+
if (mode == "moving") {
|
509
|
+
if (!lastState) {
|
510
|
+
lastState = currState;
|
511
|
+
}
|
512
|
+
return;
|
513
|
+
}
|
514
|
+
if (lastState) {
|
515
|
+
if (undoStack[stackPtr - 1].text != lastState.text) {
|
516
|
+
undoStack[stackPtr++] = lastState;
|
517
|
+
}
|
518
|
+
lastState = null;
|
519
|
+
}
|
520
|
+
undoStack[stackPtr++] = currState;
|
521
|
+
undoStack[stackPtr + 1] = null;
|
522
|
+
if (callback) {
|
523
|
+
callback();
|
524
|
+
}
|
525
|
+
};
|
526
|
+
|
527
|
+
var handleCtrlYZ = function (event) {
|
528
|
+
|
529
|
+
var handled = false;
|
530
|
+
|
531
|
+
if (event.ctrlKey || event.metaKey) {
|
532
|
+
|
533
|
+
// IE and Opera do not support charCode.
|
534
|
+
var keyCode = event.charCode || event.keyCode;
|
535
|
+
var keyCodeChar = String.fromCharCode(keyCode);
|
536
|
+
|
537
|
+
switch (keyCodeChar) {
|
538
|
+
|
539
|
+
case "y":
|
540
|
+
undoObj.redo();
|
541
|
+
handled = true;
|
542
|
+
break;
|
543
|
+
|
544
|
+
case "z":
|
545
|
+
if (!event.shiftKey) {
|
546
|
+
undoObj.undo();
|
547
|
+
}
|
548
|
+
else {
|
549
|
+
undoObj.redo();
|
550
|
+
}
|
551
|
+
handled = true;
|
552
|
+
break;
|
553
|
+
}
|
554
|
+
}
|
555
|
+
|
556
|
+
if (handled) {
|
557
|
+
if (event.preventDefault) {
|
558
|
+
event.preventDefault();
|
559
|
+
}
|
560
|
+
if (window.event) {
|
561
|
+
window.event.returnValue = false;
|
562
|
+
}
|
563
|
+
}
|
564
|
+
};
|
565
|
+
|
566
|
+
// Set the mode depending on what is going on in the input area.
|
567
|
+
var handleModeChange = function (event) {
|
568
|
+
|
569
|
+
if (!event.ctrlKey && !event.metaKey) {
|
570
|
+
|
571
|
+
var keyCode = event.keyCode;
|
572
|
+
|
573
|
+
if ((keyCode >= 33 && keyCode <= 40) || (keyCode >= 63232 && keyCode <= 63235)) {
|
574
|
+
// 33 - 40: page up/dn and arrow keys
|
575
|
+
// 63232 - 63235: page up/dn and arrow keys on safari
|
576
|
+
setMode("moving");
|
577
|
+
}
|
578
|
+
else if (keyCode == 8 || keyCode == 46 || keyCode == 127) {
|
579
|
+
// 8: backspace
|
580
|
+
// 46: delete
|
581
|
+
// 127: delete
|
582
|
+
setMode("deleting");
|
583
|
+
}
|
584
|
+
else if (keyCode == 13) {
|
585
|
+
// 13: Enter
|
586
|
+
setMode("newlines");
|
587
|
+
}
|
588
|
+
else if (keyCode == 27) {
|
589
|
+
// 27: escape
|
590
|
+
setMode("escape");
|
591
|
+
}
|
592
|
+
else if ((keyCode < 16 || keyCode > 20) && keyCode != 91) {
|
593
|
+
// 16-20 are shift, etc.
|
594
|
+
// 91: left window key
|
595
|
+
// I think this might be a little messed up since there are
|
596
|
+
// a lot of nonprinting keys above 20.
|
597
|
+
setMode("typing");
|
598
|
+
}
|
599
|
+
}
|
600
|
+
};
|
601
|
+
|
602
|
+
var setEventHandlers = function () {
|
603
|
+
util.addEvent(panels.input, "keypress", function (event) {
|
604
|
+
// keyCode 89: y
|
605
|
+
// keyCode 90: z
|
606
|
+
if ((event.ctrlKey || event.metaKey) && (event.keyCode == 89 || event.keyCode == 90)) {
|
607
|
+
event.preventDefault();
|
608
|
+
}
|
609
|
+
});
|
610
|
+
|
611
|
+
var handlePaste = function () {
|
612
|
+
if (uaSniffed.isIE || (inputStateObj && inputStateObj.text != panels.input.value)) {
|
613
|
+
if (timer == undefined) {
|
614
|
+
mode = "paste";
|
615
|
+
saveState();
|
616
|
+
refreshState();
|
617
|
+
}
|
618
|
+
}
|
619
|
+
};
|
620
|
+
|
621
|
+
util.addEvent(panels.input, "keydown", handleCtrlYZ);
|
622
|
+
util.addEvent(panels.input, "keydown", handleModeChange);
|
623
|
+
util.addEvent(panels.input, "mousedown", function () {
|
624
|
+
setMode("moving");
|
625
|
+
});
|
626
|
+
|
627
|
+
panels.input.onpaste = handlePaste;
|
628
|
+
panels.input.ondrop = handlePaste;
|
629
|
+
};
|
630
|
+
|
631
|
+
var init = function () {
|
632
|
+
setEventHandlers();
|
633
|
+
refreshState(true);
|
634
|
+
saveState();
|
635
|
+
};
|
636
|
+
|
637
|
+
init();
|
638
|
+
}
|
639
|
+
|
640
|
+
// end of UndoManager
|
641
|
+
|
642
|
+
// The input textarea state/contents.
|
643
|
+
// This is used to implement undo/redo by the undo manager.
|
644
|
+
function TextareaState(panels, isInitialState) {
|
645
|
+
|
646
|
+
// Aliases
|
647
|
+
var stateObj = this;
|
648
|
+
var inputArea = panels.input;
|
649
|
+
this.init = function () {
|
650
|
+
if (!util.isVisible(inputArea)) {
|
651
|
+
return;
|
652
|
+
}
|
653
|
+
if (!isInitialState && doc.activeElement && doc.activeElement !== inputArea) { // this happens when tabbing out of the input box
|
654
|
+
return;
|
655
|
+
}
|
656
|
+
|
657
|
+
this.setInputAreaSelectionStartEnd();
|
658
|
+
this.scrollTop = inputArea.scrollTop;
|
659
|
+
if (!this.text && inputArea.selectionStart || inputArea.selectionStart === 0) {
|
660
|
+
this.text = inputArea.value;
|
661
|
+
}
|
662
|
+
|
663
|
+
};
|
664
|
+
|
665
|
+
// Sets the selected text in the input box after we've performed an
|
666
|
+
// operation.
|
667
|
+
this.setInputAreaSelection = function () {
|
668
|
+
|
669
|
+
if (!util.isVisible(inputArea)) {
|
670
|
+
return;
|
671
|
+
}
|
672
|
+
|
673
|
+
if (inputArea.selectionStart !== undefined && !uaSniffed.isOpera) {
|
674
|
+
|
675
|
+
inputArea.focus();
|
676
|
+
inputArea.selectionStart = stateObj.start;
|
677
|
+
inputArea.selectionEnd = stateObj.end;
|
678
|
+
inputArea.scrollTop = stateObj.scrollTop;
|
679
|
+
}
|
680
|
+
else if (doc.selection) {
|
681
|
+
|
682
|
+
if (doc.activeElement && doc.activeElement !== inputArea) {
|
683
|
+
return;
|
684
|
+
}
|
685
|
+
|
686
|
+
inputArea.focus();
|
687
|
+
var range = inputArea.createTextRange();
|
688
|
+
range.moveStart("character", -inputArea.value.length);
|
689
|
+
range.moveEnd("character", -inputArea.value.length);
|
690
|
+
range.moveEnd("character", stateObj.end);
|
691
|
+
range.moveStart("character", stateObj.start);
|
692
|
+
range.select();
|
693
|
+
}
|
694
|
+
};
|
695
|
+
|
696
|
+
this.setInputAreaSelectionStartEnd = function () {
|
697
|
+
|
698
|
+
if (!panels.ieCachedRange && (inputArea.selectionStart || inputArea.selectionStart === 0)) {
|
699
|
+
|
700
|
+
stateObj.start = inputArea.selectionStart;
|
701
|
+
stateObj.end = inputArea.selectionEnd;
|
702
|
+
}
|
703
|
+
else if (doc.selection) {
|
704
|
+
|
705
|
+
stateObj.text = util.fixEolChars(inputArea.value);
|
706
|
+
|
707
|
+
// IE loses the selection in the textarea when buttons are
|
708
|
+
// clicked. On IE we cache the selection. Here, if something is cached,
|
709
|
+
// we take it.
|
710
|
+
var range = panels.ieCachedRange || doc.selection.createRange();
|
711
|
+
|
712
|
+
var fixedRange = util.fixEolChars(range.text);
|
713
|
+
var marker = "\x07";
|
714
|
+
var markedRange = marker + fixedRange + marker;
|
715
|
+
range.text = markedRange;
|
716
|
+
var inputText = util.fixEolChars(inputArea.value);
|
717
|
+
|
718
|
+
range.moveStart("character", -markedRange.length);
|
719
|
+
range.text = fixedRange;
|
720
|
+
|
721
|
+
stateObj.start = inputText.indexOf(marker);
|
722
|
+
stateObj.end = inputText.lastIndexOf(marker) - marker.length;
|
723
|
+
|
724
|
+
var len = stateObj.text.length - util.fixEolChars(inputArea.value).length;
|
725
|
+
|
726
|
+
if (len) {
|
727
|
+
range.moveStart("character", -fixedRange.length);
|
728
|
+
while (len--) {
|
729
|
+
fixedRange += "\n";
|
730
|
+
stateObj.end += 1;
|
731
|
+
}
|
732
|
+
range.text = fixedRange;
|
733
|
+
}
|
734
|
+
|
735
|
+
if (panels.ieCachedRange)
|
736
|
+
stateObj.scrollTop = panels.ieCachedScrollTop; // this is set alongside with ieCachedRange
|
737
|
+
|
738
|
+
panels.ieCachedRange = null;
|
739
|
+
|
740
|
+
this.setInputAreaSelection();
|
741
|
+
}
|
742
|
+
};
|
743
|
+
|
744
|
+
// Restore this state into the input area.
|
745
|
+
this.restore = function () {
|
746
|
+
|
747
|
+
if (stateObj.text != undefined && stateObj.text != inputArea.value) {
|
748
|
+
inputArea.value = stateObj.text;
|
749
|
+
}
|
750
|
+
this.setInputAreaSelection();
|
751
|
+
inputArea.scrollTop = stateObj.scrollTop;
|
752
|
+
};
|
753
|
+
|
754
|
+
// Gets a collection of HTML chunks from the inptut textarea.
|
755
|
+
this.getChunks = function () {
|
756
|
+
|
757
|
+
var chunk = new Chunks();
|
758
|
+
chunk.before = util.fixEolChars(stateObj.text.substring(0, stateObj.start));
|
759
|
+
chunk.startTag = "";
|
760
|
+
chunk.selection = util.fixEolChars(stateObj.text.substring(stateObj.start, stateObj.end));
|
761
|
+
chunk.endTag = "";
|
762
|
+
chunk.after = util.fixEolChars(stateObj.text.substring(stateObj.end));
|
763
|
+
chunk.scrollTop = stateObj.scrollTop;
|
764
|
+
|
765
|
+
return chunk;
|
766
|
+
};
|
767
|
+
|
768
|
+
// Sets the TextareaState properties given a chunk of markdown.
|
769
|
+
this.setChunks = function (chunk) {
|
770
|
+
|
771
|
+
chunk.before = chunk.before + chunk.startTag;
|
772
|
+
chunk.after = chunk.endTag + chunk.after;
|
773
|
+
|
774
|
+
this.start = chunk.before.length;
|
775
|
+
this.end = chunk.before.length + chunk.selection.length;
|
776
|
+
this.text = chunk.before + chunk.selection + chunk.after;
|
777
|
+
this.scrollTop = chunk.scrollTop;
|
778
|
+
};
|
779
|
+
this.init();
|
780
|
+
}
|
781
|
+
function PreviewManager(converter, panels, previewRefreshCallback) {
|
782
|
+
|
783
|
+
var managerObj = this;
|
784
|
+
var timeout;
|
785
|
+
var elapsedTime;
|
786
|
+
var oldInputText;
|
787
|
+
var maxDelay = 3000;
|
788
|
+
var startType = "delayed"; // The other legal value is "manual"
|
789
|
+
|
790
|
+
// Adds event listeners to elements
|
791
|
+
var setupEvents = function (inputElem, listener) {
|
792
|
+
|
793
|
+
util.addEvent(inputElem, "input", listener);
|
794
|
+
inputElem.onpaste = listener;
|
795
|
+
inputElem.ondrop = listener;
|
796
|
+
|
797
|
+
util.addEvent(inputElem, "keypress", listener);
|
798
|
+
util.addEvent(inputElem, "keydown", listener);
|
799
|
+
};
|
800
|
+
|
801
|
+
var getDocScrollTop = function () {
|
802
|
+
|
803
|
+
var result = 0;
|
804
|
+
|
805
|
+
if (window.innerHeight) {
|
806
|
+
result = window.pageYOffset;
|
807
|
+
}
|
808
|
+
else
|
809
|
+
if (doc.documentElement && doc.documentElement.scrollTop) {
|
810
|
+
result = doc.documentElement.scrollTop;
|
811
|
+
}
|
812
|
+
else
|
813
|
+
if (doc.body) {
|
814
|
+
result = doc.body.scrollTop;
|
815
|
+
}
|
816
|
+
|
817
|
+
return result;
|
818
|
+
};
|
819
|
+
|
820
|
+
var makePreviewHtml = function () {
|
821
|
+
|
822
|
+
// If there is no registered preview panel
|
823
|
+
// there is nothing to do.
|
824
|
+
if (!panels.preview)
|
825
|
+
return;
|
826
|
+
|
827
|
+
|
828
|
+
var text = panels.input.value;
|
829
|
+
if (text && text == oldInputText) {
|
830
|
+
return; // Input text hasn't changed.
|
831
|
+
}
|
832
|
+
else {
|
833
|
+
oldInputText = text;
|
834
|
+
}
|
835
|
+
|
836
|
+
var prevTime = new Date().getTime();
|
837
|
+
|
838
|
+
text = converter.makeHtml(text);
|
839
|
+
|
840
|
+
// Calculate the processing time of the HTML creation.
|
841
|
+
// It's used as the delay time in the event listener.
|
842
|
+
var currTime = new Date().getTime();
|
843
|
+
elapsedTime = currTime - prevTime;
|
844
|
+
|
845
|
+
pushPreviewHtml(text);
|
846
|
+
};
|
847
|
+
|
848
|
+
// setTimeout is already used. Used as an event listener.
|
849
|
+
var applyTimeout = function () {
|
850
|
+
|
851
|
+
if (timeout) {
|
852
|
+
clearTimeout(timeout);
|
853
|
+
timeout = undefined;
|
854
|
+
}
|
855
|
+
|
856
|
+
if (startType !== "manual") {
|
857
|
+
|
858
|
+
var delay = 0;
|
859
|
+
|
860
|
+
if (startType === "delayed") {
|
861
|
+
delay = elapsedTime;
|
862
|
+
}
|
863
|
+
|
864
|
+
if (delay > maxDelay) {
|
865
|
+
delay = maxDelay;
|
866
|
+
}
|
867
|
+
timeout = setTimeout(makePreviewHtml, delay);
|
868
|
+
}
|
869
|
+
};
|
870
|
+
|
871
|
+
var getScaleFactor = function (panel) {
|
872
|
+
if (panel.scrollHeight <= panel.clientHeight) {
|
873
|
+
return 1;
|
874
|
+
}
|
875
|
+
return panel.scrollTop / (panel.scrollHeight - panel.clientHeight);
|
876
|
+
};
|
877
|
+
|
878
|
+
var setPanelScrollTops = function () {
|
879
|
+
if (panels.preview) {
|
880
|
+
panels.preview.scrollTop = (panels.preview.scrollHeight - panels.preview.clientHeight) * getScaleFactor(panels.preview);
|
881
|
+
}
|
882
|
+
};
|
883
|
+
|
884
|
+
this.refresh = function (requiresRefresh) {
|
885
|
+
|
886
|
+
if (requiresRefresh) {
|
887
|
+
oldInputText = "";
|
888
|
+
makePreviewHtml();
|
889
|
+
}
|
890
|
+
else {
|
891
|
+
applyTimeout();
|
892
|
+
}
|
893
|
+
};
|
894
|
+
|
895
|
+
this.processingTime = function () {
|
896
|
+
return elapsedTime;
|
897
|
+
};
|
898
|
+
|
899
|
+
var isFirstTimeFilled = true;
|
900
|
+
|
901
|
+
// IE doesn't let you use innerHTML if the element is contained somewhere in a table
|
902
|
+
// (which is the case for inline editing) -- in that case, detach the element, set the
|
903
|
+
// value, and reattach. Yes, that *is* ridiculous.
|
904
|
+
var ieSafePreviewSet = function (text) {
|
905
|
+
var preview = panels.preview;
|
906
|
+
var parent = preview.parentNode;
|
907
|
+
var sibling = preview.nextSibling;
|
908
|
+
parent.removeChild(preview);
|
909
|
+
preview.innerHTML = text;
|
910
|
+
if (!sibling)
|
911
|
+
parent.appendChild(preview);
|
912
|
+
else
|
913
|
+
parent.insertBefore(preview, sibling);
|
914
|
+
};
|
915
|
+
|
916
|
+
var nonSuckyBrowserPreviewSet = function (text) {
|
917
|
+
panels.preview.innerHTML = text;
|
918
|
+
};
|
919
|
+
|
920
|
+
var previewSetter;
|
921
|
+
|
922
|
+
var previewSet = function (text) {
|
923
|
+
if (previewSetter)
|
924
|
+
return previewSetter(text);
|
925
|
+
|
926
|
+
try {
|
927
|
+
nonSuckyBrowserPreviewSet(text);
|
928
|
+
previewSetter = nonSuckyBrowserPreviewSet;
|
929
|
+
} catch (e) {
|
930
|
+
previewSetter = ieSafePreviewSet;
|
931
|
+
previewSetter(text);
|
932
|
+
}
|
933
|
+
};
|
934
|
+
|
935
|
+
var pushPreviewHtml = function (text) {
|
936
|
+
|
937
|
+
var emptyTop = position.getTop(panels.input) - getDocScrollTop();
|
938
|
+
|
939
|
+
if (panels.preview) {
|
940
|
+
previewSet(text);
|
941
|
+
previewRefreshCallback();
|
942
|
+
}
|
943
|
+
|
944
|
+
setPanelScrollTops();
|
945
|
+
|
946
|
+
if (isFirstTimeFilled) {
|
947
|
+
isFirstTimeFilled = false;
|
948
|
+
return;
|
949
|
+
}
|
950
|
+
|
951
|
+
var fullTop = position.getTop(panels.input) - getDocScrollTop();
|
952
|
+
|
953
|
+
if (uaSniffed.isIE) {
|
954
|
+
setTimeout(function () {
|
955
|
+
window.scrollBy(0, fullTop - emptyTop);
|
956
|
+
}, 0);
|
957
|
+
}
|
958
|
+
else {
|
959
|
+
window.scrollBy(0, fullTop - emptyTop);
|
960
|
+
}
|
961
|
+
};
|
962
|
+
|
963
|
+
var init = function () {
|
964
|
+
|
965
|
+
setupEvents(panels.input, applyTimeout);
|
966
|
+
makePreviewHtml();
|
967
|
+
|
968
|
+
if (panels.preview) {
|
969
|
+
panels.preview.scrollTop = 0;
|
970
|
+
}
|
971
|
+
};
|
972
|
+
|
973
|
+
init();
|
974
|
+
}
|
975
|
+
// This simulates a modal dialog box and asks for the URL when you
|
976
|
+
// click the hyperlink or image buttons.
|
977
|
+
//
|
978
|
+
// text: The html for the input box.
|
979
|
+
// defaultInputText: The default value that appears in the input box.
|
980
|
+
// callback: The function which is executed when the prompt is dismissed, either via OK or Cancel.
|
981
|
+
// It receives a single argument; either the entered text (if OK was chosen) or null (if Cancel
|
982
|
+
// was chosen).
|
983
|
+
ui.prompt = function (title, inputLabel, inputPlaceholder, inputHelp, callback) {
|
984
|
+
|
985
|
+
// These variables need to be declared at this level since they are used
|
986
|
+
// in multiple functions.
|
987
|
+
var dialog; // The dialog box.
|
988
|
+
var input; // The text box where you enter the hyperlink.
|
989
|
+
|
990
|
+
|
991
|
+
if (inputPlaceholder === undefined) {
|
992
|
+
inputPlaceholder = "";
|
993
|
+
}
|
994
|
+
|
995
|
+
// Used as a keydown event handler. Esc dismisses the prompt.
|
996
|
+
// Key code 27 is ESC.
|
997
|
+
var checkEscape = function (key) {
|
998
|
+
var code = (key.charCode || key.keyCode);
|
999
|
+
if (code === 27) {
|
1000
|
+
close(true);
|
1001
|
+
}
|
1002
|
+
};
|
1003
|
+
|
1004
|
+
// Dismisses the hyperlink input box.
|
1005
|
+
// isCancel is true if we don't care about the input text.
|
1006
|
+
// isCancel is false if we are going to keep the text.
|
1007
|
+
var close = function (isCancel) {
|
1008
|
+
util.removeEvent(doc.body, "keydown", checkEscape);
|
1009
|
+
var text = input.value;
|
1010
|
+
|
1011
|
+
if (isCancel) {
|
1012
|
+
text = null;
|
1013
|
+
}
|
1014
|
+
else {
|
1015
|
+
// Fixes common pasting errors.
|
1016
|
+
text = text.replace(/^http:\/\/(https?|ftp):\/\//, '$1://');
|
1017
|
+
if (!/^(?:https?|ftp):\/\//.test(text))
|
1018
|
+
text = 'http://' + text;
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
$(dialog).modal('hide');
|
1022
|
+
|
1023
|
+
callback(text);
|
1024
|
+
return false;
|
1025
|
+
};
|
1026
|
+
|
1027
|
+
|
1028
|
+
|
1029
|
+
// Create the text input box form/window.
|
1030
|
+
var createDialog = function () {
|
1031
|
+
// <div class="modal" id="myModal">
|
1032
|
+
// <div class="modal-dialog">
|
1033
|
+
// <div class="modal-content">
|
1034
|
+
// <div class="modal-header">
|
1035
|
+
// <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
1036
|
+
// <h3 class="modal-title">Modal title</h3>
|
1037
|
+
// </div>
|
1038
|
+
// <div class="modal-body">
|
1039
|
+
// <p>One fine body…</p>
|
1040
|
+
// </div>
|
1041
|
+
// <div class="modal-footer">
|
1042
|
+
// <a href="#" class="btn btn-primary">Save changes</a>
|
1043
|
+
// <a href="#" class="btn">Close</a>
|
1044
|
+
// </div>
|
1045
|
+
// </div>
|
1046
|
+
// </div>
|
1047
|
+
// </div>
|
1048
|
+
|
1049
|
+
// The main dialog box.
|
1050
|
+
dialog = doc.createElement("div");
|
1051
|
+
dialog.className = "modal fade";
|
1052
|
+
dialog.style.display = "none";
|
1053
|
+
|
1054
|
+
var dialogContainer = doc.createElement("div");
|
1055
|
+
dialogContainer.className = "modal-dialog";
|
1056
|
+
dialog.appendChild(dialogContainer);
|
1057
|
+
|
1058
|
+
var dialogContent = doc.createElement("div");
|
1059
|
+
dialogContent.className = "modal-content";
|
1060
|
+
dialogContainer.appendChild(dialogContent);
|
1061
|
+
|
1062
|
+
// The header.
|
1063
|
+
var header = doc.createElement("div");
|
1064
|
+
header.className = "modal-header";
|
1065
|
+
header.innerHTML = '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 class="modal-title">'+title+'</h3>';
|
1066
|
+
dialogContent.appendChild(header);
|
1067
|
+
|
1068
|
+
// The body.
|
1069
|
+
var body = doc.createElement("div");
|
1070
|
+
body.className = "modal-body";
|
1071
|
+
dialogContent.appendChild(body);
|
1072
|
+
|
1073
|
+
// The footer.
|
1074
|
+
var footer = doc.createElement("div");
|
1075
|
+
footer.className = "modal-footer";
|
1076
|
+
dialogContent.appendChild(footer);
|
1077
|
+
|
1078
|
+
// The web form container for the text box and buttons.
|
1079
|
+
var form = doc.createElement("form");
|
1080
|
+
form.onsubmit = function () { return close(false); };
|
1081
|
+
body.appendChild(form);
|
1082
|
+
|
1083
|
+
// The input text box
|
1084
|
+
var formGroup = doc.createElement("div");
|
1085
|
+
formGroup.className = "form-group";
|
1086
|
+
form.appendChild(formGroup);
|
1087
|
+
|
1088
|
+
var label = doc.createElement("label");
|
1089
|
+
label.htmlFor = "url-" + new Date().getTime();
|
1090
|
+
label.innerHTML = inputLabel;
|
1091
|
+
formGroup.appendChild(label);
|
1092
|
+
|
1093
|
+
input = doc.createElement("input");
|
1094
|
+
input.id = label.htmlFor;
|
1095
|
+
input.type = "text";
|
1096
|
+
input.className = "form-control";
|
1097
|
+
input.placeholder = inputPlaceholder;
|
1098
|
+
formGroup.appendChild(input);
|
1099
|
+
|
1100
|
+
var helpBlock = doc.createElement("span");
|
1101
|
+
helpBlock.className = "help-block";
|
1102
|
+
helpBlock.innerHTML = inputHelp || '';
|
1103
|
+
formGroup.appendChild(helpBlock);
|
1104
|
+
|
1105
|
+
// The ok button
|
1106
|
+
var okButton = doc.createElement("button");
|
1107
|
+
okButton.className = "btn btn-primary";
|
1108
|
+
okButton.type = "button";
|
1109
|
+
okButton.onclick = function () { return close(false); };
|
1110
|
+
okButton.innerHTML = "OK";
|
1111
|
+
|
1112
|
+
// The cancel button
|
1113
|
+
var cancelButton = doc.createElement("button");
|
1114
|
+
cancelButton.className = "btn btn-default";
|
1115
|
+
cancelButton.type = "button";
|
1116
|
+
cancelButton.onclick = function () { return close(true); };
|
1117
|
+
cancelButton.innerHTML = "Cancel";
|
1118
|
+
|
1119
|
+
footer.appendChild(okButton);
|
1120
|
+
footer.appendChild(cancelButton);
|
1121
|
+
|
1122
|
+
util.addEvent(doc.body, "keydown", checkEscape);
|
1123
|
+
|
1124
|
+
doc.body.appendChild(dialog);
|
1125
|
+
|
1126
|
+
};
|
1127
|
+
|
1128
|
+
// Why is this in a zero-length timeout?
|
1129
|
+
// Is it working around a browser bug?
|
1130
|
+
setTimeout(function () {
|
1131
|
+
|
1132
|
+
createDialog();
|
1133
|
+
|
1134
|
+
var defTextLen = 0;
|
1135
|
+
if (input.selectionStart !== undefined) {
|
1136
|
+
input.selectionStart = 0;
|
1137
|
+
input.selectionEnd = defTextLen;
|
1138
|
+
}
|
1139
|
+
else if (input.createTextRange) {
|
1140
|
+
var range = input.createTextRange();
|
1141
|
+
range.collapse(false);
|
1142
|
+
range.moveStart("character", -defTextLen);
|
1143
|
+
range.moveEnd("character", defTextLen);
|
1144
|
+
range.select();
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
$(dialog).on('shown', function () {
|
1148
|
+
input.focus();
|
1149
|
+
});
|
1150
|
+
|
1151
|
+
$(dialog).on('hidden', function () {
|
1152
|
+
dialog.parentNode.removeChild(dialog);
|
1153
|
+
});
|
1154
|
+
|
1155
|
+
$(dialog).modal()
|
1156
|
+
|
1157
|
+
}, 0);
|
1158
|
+
};
|
1159
|
+
|
1160
|
+
function UIManager(postfix, panels, undoManager, previewManager, commandManager, helpOptions) {
|
1161
|
+
|
1162
|
+
var inputBox = panels.input,
|
1163
|
+
buttons = {}; // buttons.undo, buttons.link, etc. The actual DOM elements.
|
1164
|
+
|
1165
|
+
makeSpritedButtonRow();
|
1166
|
+
|
1167
|
+
var keyEvent = "keydown";
|
1168
|
+
if (uaSniffed.isOpera) {
|
1169
|
+
keyEvent = "keypress";
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
util.addEvent(inputBox, keyEvent, function (key) {
|
1173
|
+
|
1174
|
+
// Check to see if we have a button key and, if so execute the callback.
|
1175
|
+
if ((key.ctrlKey || key.metaKey) && !key.altKey && !key.shiftKey) {
|
1176
|
+
|
1177
|
+
var keyCode = key.charCode || key.keyCode;
|
1178
|
+
var keyCodeStr = String.fromCharCode(keyCode).toLowerCase();
|
1179
|
+
|
1180
|
+
switch (keyCodeStr) {
|
1181
|
+
case "b":
|
1182
|
+
doClick(buttons.bold);
|
1183
|
+
break;
|
1184
|
+
case "i":
|
1185
|
+
doClick(buttons.italic);
|
1186
|
+
break;
|
1187
|
+
case "l":
|
1188
|
+
doClick(buttons.link);
|
1189
|
+
break;
|
1190
|
+
case "q":
|
1191
|
+
doClick(buttons.quote);
|
1192
|
+
break;
|
1193
|
+
case "k":
|
1194
|
+
doClick(buttons.code);
|
1195
|
+
break;
|
1196
|
+
case "g":
|
1197
|
+
doClick(buttons.image);
|
1198
|
+
break;
|
1199
|
+
case "o":
|
1200
|
+
doClick(buttons.olist);
|
1201
|
+
break;
|
1202
|
+
case "u":
|
1203
|
+
doClick(buttons.ulist);
|
1204
|
+
break;
|
1205
|
+
case "h":
|
1206
|
+
doClick(buttons.heading);
|
1207
|
+
break;
|
1208
|
+
case "r":
|
1209
|
+
doClick(buttons.hr);
|
1210
|
+
break;
|
1211
|
+
case "y":
|
1212
|
+
doClick(buttons.redo);
|
1213
|
+
break;
|
1214
|
+
case "z":
|
1215
|
+
if (key.shiftKey) {
|
1216
|
+
doClick(buttons.redo);
|
1217
|
+
}
|
1218
|
+
else {
|
1219
|
+
doClick(buttons.undo);
|
1220
|
+
}
|
1221
|
+
break;
|
1222
|
+
default:
|
1223
|
+
return;
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
|
1227
|
+
if (key.preventDefault) {
|
1228
|
+
key.preventDefault();
|
1229
|
+
}
|
1230
|
+
|
1231
|
+
if (window.event) {
|
1232
|
+
window.event.returnValue = false;
|
1233
|
+
}
|
1234
|
+
}
|
1235
|
+
});
|
1236
|
+
|
1237
|
+
// Auto-indent on shift-enter
|
1238
|
+
util.addEvent(inputBox, "keyup", function (key) {
|
1239
|
+
if (key.shiftKey && !key.ctrlKey && !key.metaKey) {
|
1240
|
+
var keyCode = key.charCode || key.keyCode;
|
1241
|
+
// Character 13 is Enter
|
1242
|
+
if (keyCode === 13) {
|
1243
|
+
var fakeButton = {};
|
1244
|
+
fakeButton.textOp = bindCommand("doAutoindent");
|
1245
|
+
doClick(fakeButton);
|
1246
|
+
}
|
1247
|
+
}
|
1248
|
+
});
|
1249
|
+
|
1250
|
+
// special handler because IE clears the context of the textbox on ESC
|
1251
|
+
if (uaSniffed.isIE) {
|
1252
|
+
util.addEvent(inputBox, "keydown", function (key) {
|
1253
|
+
var code = key.keyCode;
|
1254
|
+
if (code === 27) {
|
1255
|
+
return false;
|
1256
|
+
}
|
1257
|
+
});
|
1258
|
+
}
|
1259
|
+
|
1260
|
+
|
1261
|
+
// Perform the button's action.
|
1262
|
+
function doClick(button) {
|
1263
|
+
|
1264
|
+
inputBox.focus();
|
1265
|
+
|
1266
|
+
if (button.textOp) {
|
1267
|
+
|
1268
|
+
if (undoManager) {
|
1269
|
+
undoManager.setCommandMode();
|
1270
|
+
}
|
1271
|
+
|
1272
|
+
var state = new TextareaState(panels);
|
1273
|
+
|
1274
|
+
if (!state) {
|
1275
|
+
return;
|
1276
|
+
}
|
1277
|
+
|
1278
|
+
var chunks = state.getChunks();
|
1279
|
+
|
1280
|
+
// Some commands launch a "modal" prompt dialog. Javascript
|
1281
|
+
// can't really make a modal dialog box and the WMD code
|
1282
|
+
// will continue to execute while the dialog is displayed.
|
1283
|
+
// This prevents the dialog pattern I'm used to and means
|
1284
|
+
// I can't do something like this:
|
1285
|
+
//
|
1286
|
+
// var link = CreateLinkDialog();
|
1287
|
+
// makeMarkdownLink(link);
|
1288
|
+
//
|
1289
|
+
// Instead of this straightforward method of handling a
|
1290
|
+
// dialog I have to pass any code which would execute
|
1291
|
+
// after the dialog is dismissed (e.g. link creation)
|
1292
|
+
// in a function parameter.
|
1293
|
+
//
|
1294
|
+
// Yes this is awkward and I think it sucks, but there's
|
1295
|
+
// no real workaround. Only the image and link code
|
1296
|
+
// create dialogs and require the function pointers.
|
1297
|
+
var fixupInputArea = function () {
|
1298
|
+
|
1299
|
+
inputBox.focus();
|
1300
|
+
|
1301
|
+
if (chunks) {
|
1302
|
+
state.setChunks(chunks);
|
1303
|
+
}
|
1304
|
+
|
1305
|
+
state.restore();
|
1306
|
+
previewManager.refresh();
|
1307
|
+
};
|
1308
|
+
|
1309
|
+
var noCleanup = button.textOp(chunks, fixupInputArea);
|
1310
|
+
|
1311
|
+
if (!noCleanup) {
|
1312
|
+
fixupInputArea();
|
1313
|
+
}
|
1314
|
+
|
1315
|
+
}
|
1316
|
+
|
1317
|
+
if (button.execute) {
|
1318
|
+
button.execute(undoManager);
|
1319
|
+
}
|
1320
|
+
}
|
1321
|
+
function setupButton(button, isEnabled) {
|
1322
|
+
|
1323
|
+
if (isEnabled) {
|
1324
|
+
button.disabled = false;
|
1325
|
+
|
1326
|
+
if (!button.isHelp) {
|
1327
|
+
button.onclick = function () {
|
1328
|
+
if (this.onmouseout) {
|
1329
|
+
this.onmouseout();
|
1330
|
+
}
|
1331
|
+
doClick(this);
|
1332
|
+
return false;
|
1333
|
+
}
|
1334
|
+
}
|
1335
|
+
}
|
1336
|
+
else {
|
1337
|
+
button.disabled = true;
|
1338
|
+
}
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
function bindCommand(method) {
|
1342
|
+
if (typeof method === "string")
|
1343
|
+
method = commandManager[method];
|
1344
|
+
return function () { method.apply(commandManager, arguments); }
|
1345
|
+
}
|
1346
|
+
|
1347
|
+
function makeSpritedButtonRow() {
|
1348
|
+
|
1349
|
+
var buttonBar = panels.buttonBar;
|
1350
|
+
var buttonRow = document.createElement("div");
|
1351
|
+
buttonRow.id = "wmd-button-row" + postfix;
|
1352
|
+
buttonRow.className = 'btn-toolbar';
|
1353
|
+
buttonRow = buttonBar.appendChild(buttonRow);
|
1354
|
+
|
1355
|
+
var makeButton = function (id, title, iconClass, textOp, group) {
|
1356
|
+
var button = document.createElement("button");
|
1357
|
+
button.className = "btn btn-default btn-sm";
|
1358
|
+
var buttonImage = document.createElement("i");
|
1359
|
+
buttonImage.className = iconClass;
|
1360
|
+
button.appendChild(buttonImage);
|
1361
|
+
button.id = id + postfix;
|
1362
|
+
button.title = title;
|
1363
|
+
if (textOp)
|
1364
|
+
button.textOp = textOp;
|
1365
|
+
setupButton(button, true);
|
1366
|
+
if (group) {
|
1367
|
+
group.appendChild(button);
|
1368
|
+
} else {
|
1369
|
+
buttonRow.appendChild(button);
|
1370
|
+
}
|
1371
|
+
return button;
|
1372
|
+
};
|
1373
|
+
var makeGroup = function (num) {
|
1374
|
+
var group = document.createElement("div");
|
1375
|
+
group.className = "btn-group wmd-button-group" + num;
|
1376
|
+
group.id = "wmd-button-group" + num + postfix;
|
1377
|
+
buttonRow.appendChild(group);
|
1378
|
+
return group
|
1379
|
+
};
|
1380
|
+
|
1381
|
+
group1 = makeGroup(1);
|
1382
|
+
buttons.bold = makeButton("wmd-bold-button", "<%= I18n.t('components.markdown_editor.bold.button_title', default: 'Bold (Ctrl+B)') %>", "fa fa-bold", bindCommand("doBold"), group1);
|
1383
|
+
buttons.italic = makeButton("wmd-italic-button", "<%= I18n.t('components.markdown_editor.italic.button_title', default: 'Italic (Ctrl+I)') %>", "fa fa-italic", bindCommand("doItalic"), group1);
|
1384
|
+
|
1385
|
+
group2 = makeGroup(2);
|
1386
|
+
buttons.link = makeButton("wmd-link-button", "<%= I18n.t('components.markdown_editor.insert_link.button_title', default: 'Link (Ctrl+L)') %>", "fa fa-link", bindCommand(function (chunk, postProcessing) {
|
1387
|
+
return this.doLinkOrImage(chunk, postProcessing, false);
|
1388
|
+
}), group2);
|
1389
|
+
buttons.image = makeButton("wmd-image-button", "<%= I18n.t('components.markdown_editor.insert_image.button_title', default: 'Image (Ctrl+G)') %>", "fa fa-picture-o", bindCommand(function (chunk, postProcessing) {
|
1390
|
+
return this.doLinkOrImage(chunk, postProcessing, true);
|
1391
|
+
}), group2);
|
1392
|
+
buttons.quote = makeButton("wmd-quote-button", "<%= I18n.t('components.markdown_editor.blockquoute.button_title', default: 'Blockquote (Ctrl+Q)') %>", "fa fa-quote-left", bindCommand("doBlockquote"), group2);
|
1393
|
+
buttons.code = makeButton("wmd-code-button", "<%= I18n.t('components.markdown_editor.code_sample.button_title', default: 'Code Sample (Ctrl+K)') %>", "fa fa-code", bindCommand("doCode"), group2);
|
1394
|
+
|
1395
|
+
group3 = makeGroup(3);
|
1396
|
+
buttons.ulist = makeButton("wmd-ulist-button", "<%= I18n.t('components.markdown_editor.bulleted_list.button_title', default: 'Bulleted List (Ctrl+U)') %>", "fa fa-list-ul", bindCommand(function (chunk, postProcessing) {
|
1397
|
+
this.doList(chunk, postProcessing, false);
|
1398
|
+
}), group3);
|
1399
|
+
buttons.olist = makeButton("wmd-olist-button", "<%= I18n.t('components.markdown_editor.numbered_list.button_title', default: 'Numbered List (Ctrl+O)') %>", "fa fa-list-ol", bindCommand(function (chunk, postProcessing) {
|
1400
|
+
this.doList(chunk, postProcessing, true);
|
1401
|
+
}), group3);
|
1402
|
+
buttons.heading = makeButton("wmd-heading-button", "<%= I18n.t('components.markdown_editor.heading.button_title', default: 'Heading (Ctrl+H)') %>", "glyphicon glyphicon-header", bindCommand("doHeading"), group3);
|
1403
|
+
|
1404
|
+
group4 = makeGroup(4);
|
1405
|
+
buttons.undo = makeButton("wmd-undo-button", "<%= I18n.t('components.markdown_editor.undo.button_title', default: 'Undo (Ctrl+Z)') %>", "fa fa-undo", null, group4);
|
1406
|
+
buttons.undo.execute = function (manager) { if (manager) manager.undo(); };
|
1407
|
+
|
1408
|
+
var redoTitle = /win/.test(nav.platform.toLowerCase()) ?
|
1409
|
+
"<%= I18n.t('components.markdown_editor.redo.button_title.win', default: 'Redo (Ctrl+Y)') %>" :
|
1410
|
+
"<%= I18n.t('components.markdown_editor.redo.button_title.other', default: 'Redo (Ctrl+Shift+Z)') %>"; // mac and other non-Windows platforms
|
1411
|
+
|
1412
|
+
buttons.redo = makeButton("wmd-redo-button", redoTitle, "fa fa-repeat", null, group4);
|
1413
|
+
buttons.redo.execute = function (manager) { if (manager) manager.redo(); };
|
1414
|
+
|
1415
|
+
if (helpOptions) {
|
1416
|
+
group5 = makeGroup(5);
|
1417
|
+
group5.className = group5.className + " pull-right";
|
1418
|
+
var helpButton = document.createElement("button");
|
1419
|
+
var helpButtonImage = document.createElement("i");
|
1420
|
+
helpButtonImage.className = "fa fa-info";
|
1421
|
+
helpButton.appendChild(helpButtonImage);
|
1422
|
+
helpButton.className = "btn btn-info btn-sm";
|
1423
|
+
helpButton.id = "wmd-help-button" + postfix;
|
1424
|
+
helpButton.isHelp = true;
|
1425
|
+
helpButton.title = helpOptions.title || defaultHelpHoverTitle;
|
1426
|
+
helpButton.onclick = helpOptions.handler;
|
1427
|
+
|
1428
|
+
setupButton(helpButton, true);
|
1429
|
+
group5.appendChild(helpButton);
|
1430
|
+
buttons.help = helpButton;
|
1431
|
+
}
|
1432
|
+
|
1433
|
+
setUndoRedoButtonStates();
|
1434
|
+
}
|
1435
|
+
|
1436
|
+
function setUndoRedoButtonStates() {
|
1437
|
+
if (undoManager) {
|
1438
|
+
setupButton(buttons.undo, undoManager.canUndo());
|
1439
|
+
setupButton(buttons.redo, undoManager.canRedo());
|
1440
|
+
}
|
1441
|
+
}
|
1442
|
+
this.setUndoRedoButtonStates = setUndoRedoButtonStates;
|
1443
|
+
|
1444
|
+
}
|
1445
|
+
|
1446
|
+
function CommandManager(pluginHooks) {
|
1447
|
+
this.hooks = pluginHooks;
|
1448
|
+
}
|
1449
|
+
|
1450
|
+
var commandProto = CommandManager.prototype;
|
1451
|
+
|
1452
|
+
// The markdown symbols - 4 spaces = code, > = blockquote, etc.
|
1453
|
+
commandProto.prefixes = "(?:\\s{4,}|\\s*>|\\s*-\\s+|\\s*\\d+\\.|=|\\+|-|_|\\*|#|\\s*\\[[^\n]]+\\]:)";
|
1454
|
+
|
1455
|
+
// Remove markdown symbols from the chunk selection.
|
1456
|
+
commandProto.unwrap = function (chunk) {
|
1457
|
+
var txt = new re("([^\\n])\\n(?!(\\n|" + this.prefixes + "))", "g");
|
1458
|
+
chunk.selection = chunk.selection.replace(txt, "$1 $2");
|
1459
|
+
};
|
1460
|
+
|
1461
|
+
commandProto.wrap = function (chunk, len) {
|
1462
|
+
this.unwrap(chunk);
|
1463
|
+
var regex = new re("(.{1," + len + "})( +|$\\n?)", "gm"),
|
1464
|
+
that = this;
|
1465
|
+
|
1466
|
+
chunk.selection = chunk.selection.replace(regex, function (line, marked) {
|
1467
|
+
if (new re("^" + that.prefixes, "").test(line)) {
|
1468
|
+
return line;
|
1469
|
+
}
|
1470
|
+
return marked + "\n";
|
1471
|
+
});
|
1472
|
+
|
1473
|
+
chunk.selection = chunk.selection.replace(/\s+$/, "");
|
1474
|
+
};
|
1475
|
+
|
1476
|
+
commandProto.doBold = function (chunk, postProcessing) {
|
1477
|
+
return this.doBorI(chunk, postProcessing, 2, "strong text");
|
1478
|
+
};
|
1479
|
+
|
1480
|
+
commandProto.doItalic = function (chunk, postProcessing) {
|
1481
|
+
return this.doBorI(chunk, postProcessing, 1, "emphasized text");
|
1482
|
+
};
|
1483
|
+
|
1484
|
+
// chunk: The selected region that will be enclosed with */**
|
1485
|
+
// nStars: 1 for italics, 2 for bold
|
1486
|
+
// insertText: If you just click the button without highlighting text, this gets inserted
|
1487
|
+
commandProto.doBorI = function (chunk, postProcessing, nStars, insertText) {
|
1488
|
+
|
1489
|
+
// Get rid of whitespace and fixup newlines.
|
1490
|
+
chunk.trimWhitespace();
|
1491
|
+
chunk.selection = chunk.selection.replace(/\n{2,}/g, "\n");
|
1492
|
+
|
1493
|
+
// Look for stars before and after. Is the chunk already marked up?
|
1494
|
+
// note that these regex matches cannot fail
|
1495
|
+
var starsBefore = /(\**$)/.exec(chunk.before)[0];
|
1496
|
+
var starsAfter = /(^\**)/.exec(chunk.after)[0];
|
1497
|
+
|
1498
|
+
var prevStars = Math.min(starsBefore.length, starsAfter.length);
|
1499
|
+
|
1500
|
+
// Remove stars if we have to since the button acts as a toggle.
|
1501
|
+
if ((prevStars >= nStars) && (prevStars != 2 || nStars != 1)) {
|
1502
|
+
chunk.before = chunk.before.replace(re("[*]{" + nStars + "}$", ""), "");
|
1503
|
+
chunk.after = chunk.after.replace(re("^[*]{" + nStars + "}", ""), "");
|
1504
|
+
}
|
1505
|
+
else if (!chunk.selection && starsAfter) {
|
1506
|
+
// It's not really clear why this code is necessary. It just moves
|
1507
|
+
// some arbitrary stuff around.
|
1508
|
+
chunk.after = chunk.after.replace(/^([*_]*)/, "");
|
1509
|
+
chunk.before = chunk.before.replace(/(\s?)$/, "");
|
1510
|
+
var whitespace = re.$1;
|
1511
|
+
chunk.before = chunk.before + starsAfter + whitespace;
|
1512
|
+
}
|
1513
|
+
else {
|
1514
|
+
|
1515
|
+
// In most cases, if you don't have any selected text and click the button
|
1516
|
+
// you'll get a selected, marked up region with the default text inserted.
|
1517
|
+
if (!chunk.selection && !starsAfter) {
|
1518
|
+
chunk.selection = insertText;
|
1519
|
+
}
|
1520
|
+
|
1521
|
+
// Add the true markup.
|
1522
|
+
var markup = nStars <= 1 ? "*" : "**"; // shouldn't the test be = ?
|
1523
|
+
chunk.before = chunk.before + markup;
|
1524
|
+
chunk.after = markup + chunk.after;
|
1525
|
+
}
|
1526
|
+
|
1527
|
+
|
1528
|
+
};
|
1529
|
+
|
1530
|
+
commandProto.stripLinkDefs = function (text, defsToAdd) {
|
1531
|
+
|
1532
|
+
text = text.replace(/^[ ]{0,3}\[(\d+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|$)/gm,
|
1533
|
+
function (totalMatch, id, link, newlines, title) {
|
1534
|
+
defsToAdd[id] = totalMatch.replace(/\s*$/, "");
|
1535
|
+
if (newlines) {
|
1536
|
+
// Strip the title and return that separately.
|
1537
|
+
defsToAdd[id] = totalMatch.replace(/["(](.+?)[")]$/, "");
|
1538
|
+
return newlines + title;
|
1539
|
+
}
|
1540
|
+
return "";
|
1541
|
+
});
|
1542
|
+
|
1543
|
+
return text;
|
1544
|
+
};
|
1545
|
+
|
1546
|
+
commandProto.addLinkDef = function (chunk, linkDef) {
|
1547
|
+
|
1548
|
+
var refNumber = 0; // The current reference number
|
1549
|
+
var defsToAdd = {}; //
|
1550
|
+
// Start with a clean slate by removing all previous link definitions.
|
1551
|
+
chunk.before = this.stripLinkDefs(chunk.before, defsToAdd);
|
1552
|
+
chunk.selection = this.stripLinkDefs(chunk.selection, defsToAdd);
|
1553
|
+
chunk.after = this.stripLinkDefs(chunk.after, defsToAdd);
|
1554
|
+
|
1555
|
+
var defs = "";
|
1556
|
+
var regex = /(\[)((?:\[[^\]]*\]|[^\[\]])*)(\][ ]?(?:\n[ ]*)?\[)(\d+)(\])/g;
|
1557
|
+
|
1558
|
+
var addDefNumber = function (def) {
|
1559
|
+
refNumber++;
|
1560
|
+
def = def.replace(/^[ ]{0,3}\[(\d+)\]:/, " [" + refNumber + "]:");
|
1561
|
+
defs += "\n" + def;
|
1562
|
+
};
|
1563
|
+
|
1564
|
+
// note that
|
1565
|
+
// a) the recursive call to getLink cannot go infinite, because by definition
|
1566
|
+
// of regex, inner is always a proper substring of wholeMatch, and
|
1567
|
+
// b) more than one level of nesting is neither supported by the regex
|
1568
|
+
// nor making a lot of sense (the only use case for nesting is a linked image)
|
1569
|
+
var getLink = function (wholeMatch, before, inner, afterInner, id, end) {
|
1570
|
+
inner = inner.replace(regex, getLink);
|
1571
|
+
if (defsToAdd[id]) {
|
1572
|
+
addDefNumber(defsToAdd[id]);
|
1573
|
+
return before + inner + afterInner + refNumber + end;
|
1574
|
+
}
|
1575
|
+
return wholeMatch;
|
1576
|
+
};
|
1577
|
+
|
1578
|
+
chunk.before = chunk.before.replace(regex, getLink);
|
1579
|
+
|
1580
|
+
if (linkDef) {
|
1581
|
+
addDefNumber(linkDef);
|
1582
|
+
}
|
1583
|
+
else {
|
1584
|
+
chunk.selection = chunk.selection.replace(regex, getLink);
|
1585
|
+
}
|
1586
|
+
|
1587
|
+
var refOut = refNumber;
|
1588
|
+
|
1589
|
+
chunk.after = chunk.after.replace(regex, getLink);
|
1590
|
+
|
1591
|
+
if (chunk.after) {
|
1592
|
+
chunk.after = chunk.after.replace(/\n*$/, "");
|
1593
|
+
}
|
1594
|
+
if (!chunk.after) {
|
1595
|
+
chunk.selection = chunk.selection.replace(/\n*$/, "");
|
1596
|
+
}
|
1597
|
+
|
1598
|
+
chunk.after += "\n\n" + defs;
|
1599
|
+
|
1600
|
+
return refOut;
|
1601
|
+
};
|
1602
|
+
|
1603
|
+
// takes the line as entered into the add link/as image dialog and makes
|
1604
|
+
// sure the URL and the optinal title are "nice".
|
1605
|
+
function properlyEncoded(linkdef) {
|
1606
|
+
return linkdef.replace(/^\s*(.*?)(?:\s+"(.+)")?\s*$/, function (wholematch, link, title) {
|
1607
|
+
link = link.replace(/\?.*$/, function (querypart) {
|
1608
|
+
return querypart.replace(/\+/g, " "); // in the query string, a plus and a space are identical
|
1609
|
+
});
|
1610
|
+
link = decodeURIComponent(link); // unencode first, to prevent double encoding
|
1611
|
+
link = encodeURI(link).replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29');
|
1612
|
+
link = link.replace(/\?.*$/, function (querypart) {
|
1613
|
+
return querypart.replace(/\+/g, "%2b"); // since we replaced plus with spaces in the query part, all pluses that now appear where originally encoded
|
1614
|
+
});
|
1615
|
+
if (title) {
|
1616
|
+
title = title.trim ? title.trim() : title.replace(/^\s*/, "").replace(/\s*$/, "");
|
1617
|
+
title = $.trim(title).replace(/"/g, "quot;").replace(/\(/g, "(").replace(/\)/g, ")").replace(/</g, "<").replace(/>/g, ">");
|
1618
|
+
}
|
1619
|
+
return title ? link + ' "' + title + '"' : link;
|
1620
|
+
});
|
1621
|
+
}
|
1622
|
+
|
1623
|
+
commandProto.doLinkOrImage = function (chunk, postProcessing, isImage) {
|
1624
|
+
|
1625
|
+
chunk.trimWhitespace();
|
1626
|
+
chunk.findTags(/\s*!?\[/, /\][ ]?(?:\n[ ]*)?(\[.*?\])?/);
|
1627
|
+
var background;
|
1628
|
+
|
1629
|
+
if (chunk.endTag.length > 1 && chunk.startTag.length > 0) {
|
1630
|
+
|
1631
|
+
chunk.startTag = chunk.startTag.replace(/!?\[/, "");
|
1632
|
+
chunk.endTag = "";
|
1633
|
+
this.addLinkDef(chunk, null);
|
1634
|
+
|
1635
|
+
}
|
1636
|
+
else {
|
1637
|
+
|
1638
|
+
// We're moving start and end tag back into the selection, since (as we're in the else block) we're not
|
1639
|
+
// *removing* a link, but *adding* one, so whatever findTags() found is now back to being part of the
|
1640
|
+
// link text. linkEnteredCallback takes care of escaping any brackets.
|
1641
|
+
chunk.selection = chunk.startTag + chunk.selection + chunk.endTag;
|
1642
|
+
chunk.startTag = chunk.endTag = "";
|
1643
|
+
|
1644
|
+
if (/\n\n/.test(chunk.selection)) {
|
1645
|
+
this.addLinkDef(chunk, null);
|
1646
|
+
return;
|
1647
|
+
}
|
1648
|
+
var that = this;
|
1649
|
+
// The function to be executed when you enter a link and press OK or Cancel.
|
1650
|
+
// Marks up the link and adds the ref.
|
1651
|
+
var linkEnteredCallback = function (link) {
|
1652
|
+
|
1653
|
+
if (link !== null) {
|
1654
|
+
// ( $1
|
1655
|
+
// [^\\] anything that's not a backslash
|
1656
|
+
// (?:\\\\)* an even number (this includes zero) of backslashes
|
1657
|
+
// )
|
1658
|
+
// (?= followed by
|
1659
|
+
// [[\]] an opening or closing bracket
|
1660
|
+
// )
|
1661
|
+
//
|
1662
|
+
// In other words, a non-escaped bracket. These have to be escaped now to make sure they
|
1663
|
+
// don't count as the end of the link or similar.
|
1664
|
+
// Note that the actual bracket has to be a lookahead, because (in case of to subsequent brackets),
|
1665
|
+
// the bracket in one match may be the "not a backslash" character in the next match, so it
|
1666
|
+
// should not be consumed by the first match.
|
1667
|
+
// The "prepend a space and finally remove it" steps makes sure there is a "not a backslash" at the
|
1668
|
+
// start of the string, so this also works if the selection begins with a bracket. We cannot solve
|
1669
|
+
// this by anchoring with ^, because in the case that the selection starts with two brackets, this
|
1670
|
+
// would mean a zero-width match at the start. Since zero-width matches advance the string position,
|
1671
|
+
// the first bracket could then not act as the "not a backslash" for the second.
|
1672
|
+
chunk.selection = (" " + chunk.selection).replace(/([^\\](?:\\\\)*)(?=[[\]])/g, "$1\\").substr(1);
|
1673
|
+
|
1674
|
+
var linkDef = " [999]: " + properlyEncoded(link);
|
1675
|
+
|
1676
|
+
var num = that.addLinkDef(chunk, linkDef);
|
1677
|
+
chunk.startTag = isImage ? "![" : "[";
|
1678
|
+
chunk.endTag = "][" + num + "]";
|
1679
|
+
|
1680
|
+
if (!chunk.selection) {
|
1681
|
+
if (isImage) {
|
1682
|
+
chunk.selection = "enter image description here";
|
1683
|
+
}
|
1684
|
+
else {
|
1685
|
+
chunk.selection = "enter link description here";
|
1686
|
+
}
|
1687
|
+
}
|
1688
|
+
}
|
1689
|
+
postProcessing();
|
1690
|
+
};
|
1691
|
+
|
1692
|
+
|
1693
|
+
if (isImage) {
|
1694
|
+
if (!this.hooks.insertImageDialog(linkEnteredCallback))
|
1695
|
+
ui.prompt(imageDialogTitle, imageInputLabel, imageInputPlaceholder, imageInputHelp, linkEnteredCallback);
|
1696
|
+
}
|
1697
|
+
else {
|
1698
|
+
ui.prompt(linkDialogTitle, linkInputLabel, linkInputPlaceholder, linkInputHelp, linkEnteredCallback);
|
1699
|
+
}
|
1700
|
+
return true;
|
1701
|
+
}
|
1702
|
+
};
|
1703
|
+
|
1704
|
+
// When making a list, hitting shift-enter will put your cursor on the next line
|
1705
|
+
// at the current indent level.
|
1706
|
+
commandProto.doAutoindent = function (chunk, postProcessing) {
|
1707
|
+
|
1708
|
+
var commandMgr = this,
|
1709
|
+
fakeSelection = false;
|
1710
|
+
|
1711
|
+
chunk.before = chunk.before.replace(/(\n|^)[ ]{0,3}([*+-]|\d+[.])[ \t]*\n$/, "\n\n");
|
1712
|
+
chunk.before = chunk.before.replace(/(\n|^)[ ]{0,3}>[ \t]*\n$/, "\n\n");
|
1713
|
+
chunk.before = chunk.before.replace(/(\n|^)[ \t]+\n$/, "\n\n");
|
1714
|
+
|
1715
|
+
// There's no selection, end the cursor wasn't at the end of the line:
|
1716
|
+
// The user wants to split the current list item / code line / blockquote line
|
1717
|
+
// (for the latter it doesn't really matter) in two. Temporarily select the
|
1718
|
+
// (rest of the) line to achieve this.
|
1719
|
+
if (!chunk.selection && !/^[ \t]*(?:\n|$)/.test(chunk.after)) {
|
1720
|
+
chunk.after = chunk.after.replace(/^[^\n]*/, function (wholeMatch) {
|
1721
|
+
chunk.selection = wholeMatch;
|
1722
|
+
return "";
|
1723
|
+
});
|
1724
|
+
fakeSelection = true;
|
1725
|
+
}
|
1726
|
+
|
1727
|
+
if (/(\n|^)[ ]{0,3}([*+-]|\d+[.])[ \t]+.*\n$/.test(chunk.before)) {
|
1728
|
+
if (commandMgr.doList) {
|
1729
|
+
commandMgr.doList(chunk);
|
1730
|
+
}
|
1731
|
+
}
|
1732
|
+
if (/(\n|^)[ ]{0,3}>[ \t]+.*\n$/.test(chunk.before)) {
|
1733
|
+
if (commandMgr.doBlockquote) {
|
1734
|
+
commandMgr.doBlockquote(chunk);
|
1735
|
+
}
|
1736
|
+
}
|
1737
|
+
if (/(\n|^)(\t|[ ]{4,}).*\n$/.test(chunk.before)) {
|
1738
|
+
if (commandMgr.doCode) {
|
1739
|
+
commandMgr.doCode(chunk);
|
1740
|
+
}
|
1741
|
+
}
|
1742
|
+
|
1743
|
+
if (fakeSelection) {
|
1744
|
+
chunk.after = chunk.selection + chunk.after;
|
1745
|
+
chunk.selection = "";
|
1746
|
+
}
|
1747
|
+
};
|
1748
|
+
|
1749
|
+
commandProto.doBlockquote = function (chunk, postProcessing) {
|
1750
|
+
|
1751
|
+
chunk.selection = chunk.selection.replace(/^(\n*)([^\r]+?)(\n*)$/,
|
1752
|
+
function (totalMatch, newlinesBefore, text, newlinesAfter) {
|
1753
|
+
chunk.before += newlinesBefore;
|
1754
|
+
chunk.after = newlinesAfter + chunk.after;
|
1755
|
+
return text;
|
1756
|
+
});
|
1757
|
+
|
1758
|
+
chunk.before = chunk.before.replace(/(>[ \t]*)$/,
|
1759
|
+
function (totalMatch, blankLine) {
|
1760
|
+
chunk.selection = blankLine + chunk.selection;
|
1761
|
+
return "";
|
1762
|
+
});
|
1763
|
+
|
1764
|
+
chunk.selection = chunk.selection.replace(/^(\s|>)+$/, "");
|
1765
|
+
chunk.selection = chunk.selection || "Blockquote";
|
1766
|
+
|
1767
|
+
// The original code uses a regular expression to find out how much of the
|
1768
|
+
// text *directly before* the selection already was a blockquote:
|
1769
|
+
|
1770
|
+
/*
|
1771
|
+
if (chunk.before) {
|
1772
|
+
chunk.before = chunk.before.replace(/\n?$/, "\n");
|
1773
|
+
}
|
1774
|
+
chunk.before = chunk.before.replace(/(((\n|^)(\n[ \t]*)*>(.+\n)*.*)+(\n[ \t]*)*$)/,
|
1775
|
+
function (totalMatch) {
|
1776
|
+
chunk.startTag = totalMatch;
|
1777
|
+
return "";
|
1778
|
+
});
|
1779
|
+
*/
|
1780
|
+
|
1781
|
+
// This comes down to:
|
1782
|
+
// Go backwards as many lines a possible, such that each line
|
1783
|
+
// a) starts with ">", or
|
1784
|
+
// b) is almost empty, except for whitespace, or
|
1785
|
+
// c) is preceeded by an unbroken chain of non-empty lines
|
1786
|
+
// leading up to a line that starts with ">" and at least one more character
|
1787
|
+
// and in addition
|
1788
|
+
// d) at least one line fulfills a)
|
1789
|
+
//
|
1790
|
+
// Since this is essentially a backwards-moving regex, it's susceptible to
|
1791
|
+
// catastrophic backtracking and can cause the browser to hang;
|
1792
|
+
// see e.g. http://meta.stackoverflow.com/questions/9807.
|
1793
|
+
//
|
1794
|
+
// Hence we replaced this by a simple state machine that just goes through the
|
1795
|
+
// lines and checks for a), b), and c).
|
1796
|
+
|
1797
|
+
var match = "",
|
1798
|
+
leftOver = "",
|
1799
|
+
line;
|
1800
|
+
if (chunk.before) {
|
1801
|
+
var lines = chunk.before.replace(/\n$/, "").split("\n");
|
1802
|
+
var inChain = false;
|
1803
|
+
for (var i = 0; i < lines.length; i++) {
|
1804
|
+
var good = false;
|
1805
|
+
line = lines[i];
|
1806
|
+
inChain = inChain && line.length > 0; // c) any non-empty line continues the chain
|
1807
|
+
if (/^>/.test(line)) { // a)
|
1808
|
+
good = true;
|
1809
|
+
if (!inChain && line.length > 1) // c) any line that starts with ">" and has at least one more character starts the chain
|
1810
|
+
inChain = true;
|
1811
|
+
} else if (/^[ \t]*$/.test(line)) { // b)
|
1812
|
+
good = true;
|
1813
|
+
} else {
|
1814
|
+
good = inChain; // c) the line is not empty and does not start with ">", so it matches if and only if we're in the chain
|
1815
|
+
}
|
1816
|
+
if (good) {
|
1817
|
+
match += line + "\n";
|
1818
|
+
} else {
|
1819
|
+
leftOver += match + line;
|
1820
|
+
match = "\n";
|
1821
|
+
}
|
1822
|
+
}
|
1823
|
+
if (!/(^|\n)>/.test(match)) { // d)
|
1824
|
+
leftOver += match;
|
1825
|
+
match = "";
|
1826
|
+
}
|
1827
|
+
}
|
1828
|
+
|
1829
|
+
chunk.startTag = match;
|
1830
|
+
chunk.before = leftOver;
|
1831
|
+
|
1832
|
+
// end of change
|
1833
|
+
|
1834
|
+
if (chunk.after) {
|
1835
|
+
chunk.after = chunk.after.replace(/^\n?/, "\n");
|
1836
|
+
}
|
1837
|
+
|
1838
|
+
chunk.after = chunk.after.replace(/^(((\n|^)(\n[ \t]*)*>(.+\n)*.*)+(\n[ \t]*)*)/,
|
1839
|
+
function (totalMatch) {
|
1840
|
+
chunk.endTag = totalMatch;
|
1841
|
+
return "";
|
1842
|
+
}
|
1843
|
+
);
|
1844
|
+
|
1845
|
+
var replaceBlanksInTags = function (useBracket) {
|
1846
|
+
|
1847
|
+
var replacement = useBracket ? "> " : "";
|
1848
|
+
|
1849
|
+
if (chunk.startTag) {
|
1850
|
+
chunk.startTag = chunk.startTag.replace(/\n((>|\s)*)\n$/,
|
1851
|
+
function (totalMatch, markdown) {
|
1852
|
+
return "\n" + markdown.replace(/^[ ]{0,3}>?[ \t]*$/gm, replacement) + "\n";
|
1853
|
+
});
|
1854
|
+
}
|
1855
|
+
if (chunk.endTag) {
|
1856
|
+
chunk.endTag = chunk.endTag.replace(/^\n((>|\s)*)\n/,
|
1857
|
+
function (totalMatch, markdown) {
|
1858
|
+
return "\n" + markdown.replace(/^[ ]{0,3}>?[ \t]*$/gm, replacement) + "\n";
|
1859
|
+
});
|
1860
|
+
}
|
1861
|
+
};
|
1862
|
+
|
1863
|
+
if (/^(?![ ]{0,3}>)/m.test(chunk.selection)) {
|
1864
|
+
this.wrap(chunk, SETTINGS.lineLength - 2);
|
1865
|
+
chunk.selection = chunk.selection.replace(/^/gm, "> ");
|
1866
|
+
replaceBlanksInTags(true);
|
1867
|
+
chunk.skipLines();
|
1868
|
+
} else {
|
1869
|
+
chunk.selection = chunk.selection.replace(/^[ ]{0,3}> ?/gm, "");
|
1870
|
+
this.unwrap(chunk);
|
1871
|
+
replaceBlanksInTags(false);
|
1872
|
+
|
1873
|
+
if (!/^(\n|^)[ ]{0,3}>/.test(chunk.selection) && chunk.startTag) {
|
1874
|
+
chunk.startTag = chunk.startTag.replace(/\n{0,2}$/, "\n\n");
|
1875
|
+
}
|
1876
|
+
|
1877
|
+
if (!/(\n|^)[ ]{0,3}>.*$/.test(chunk.selection) && chunk.endTag) {
|
1878
|
+
chunk.endTag = chunk.endTag.replace(/^\n{0,2}/, "\n\n");
|
1879
|
+
}
|
1880
|
+
}
|
1881
|
+
|
1882
|
+
chunk.selection = this.hooks.postBlockquoteCreation(chunk.selection);
|
1883
|
+
|
1884
|
+
if (!/\n/.test(chunk.selection)) {
|
1885
|
+
chunk.selection = chunk.selection.replace(/^(> *)/,
|
1886
|
+
function (wholeMatch, blanks) {
|
1887
|
+
chunk.startTag += blanks;
|
1888
|
+
return "";
|
1889
|
+
});
|
1890
|
+
}
|
1891
|
+
};
|
1892
|
+
|
1893
|
+
commandProto.doCode = function (chunk, postProcessing) {
|
1894
|
+
|
1895
|
+
var hasTextBefore = /\S[ ]*$/.test(chunk.before);
|
1896
|
+
var hasTextAfter = /^[ ]*\S/.test(chunk.after);
|
1897
|
+
|
1898
|
+
// Use 'four space' markdown if the selection is on its own
|
1899
|
+
// line or is multiline.
|
1900
|
+
if ((!hasTextAfter && !hasTextBefore) || /\n/.test(chunk.selection)) {
|
1901
|
+
|
1902
|
+
chunk.before = chunk.before.replace(/[ ]{4}$/,
|
1903
|
+
function (totalMatch) {
|
1904
|
+
chunk.selection = totalMatch + chunk.selection;
|
1905
|
+
return "";
|
1906
|
+
});
|
1907
|
+
|
1908
|
+
var nLinesBack = 1;
|
1909
|
+
var nLinesForward = 1;
|
1910
|
+
|
1911
|
+
if (/(\n|^)(\t|[ ]{4,}).*\n$/.test(chunk.before)) {
|
1912
|
+
nLinesBack = 0;
|
1913
|
+
}
|
1914
|
+
if (/^\n(\t|[ ]{4,})/.test(chunk.after)) {
|
1915
|
+
nLinesForward = 0;
|
1916
|
+
}
|
1917
|
+
|
1918
|
+
chunk.skipLines(nLinesBack, nLinesForward);
|
1919
|
+
|
1920
|
+
if (!chunk.selection) {
|
1921
|
+
chunk.startTag = " ";
|
1922
|
+
chunk.selection = "enter code here";
|
1923
|
+
}
|
1924
|
+
else {
|
1925
|
+
if (/^[ ]{0,3}\S/m.test(chunk.selection)) {
|
1926
|
+
if (/\n/.test(chunk.selection))
|
1927
|
+
chunk.selection = chunk.selection.replace(/^/gm, " ");
|
1928
|
+
else // if it's not multiline, do not select the four added spaces; this is more consistent with the doList behavior
|
1929
|
+
chunk.before += " ";
|
1930
|
+
}
|
1931
|
+
else {
|
1932
|
+
chunk.selection = chunk.selection.replace(/^[ ]{4}/gm, "");
|
1933
|
+
}
|
1934
|
+
}
|
1935
|
+
}
|
1936
|
+
else {
|
1937
|
+
// Use backticks (`) to delimit the code block.
|
1938
|
+
|
1939
|
+
chunk.trimWhitespace();
|
1940
|
+
chunk.findTags(/`/, /`/);
|
1941
|
+
|
1942
|
+
if (!chunk.startTag && !chunk.endTag) {
|
1943
|
+
chunk.startTag = chunk.endTag = "`";
|
1944
|
+
if (!chunk.selection) {
|
1945
|
+
chunk.selection = "enter code here";
|
1946
|
+
}
|
1947
|
+
}
|
1948
|
+
else if (chunk.endTag && !chunk.startTag) {
|
1949
|
+
chunk.before += chunk.endTag;
|
1950
|
+
chunk.endTag = "";
|
1951
|
+
}
|
1952
|
+
else {
|
1953
|
+
chunk.startTag = chunk.endTag = "";
|
1954
|
+
}
|
1955
|
+
}
|
1956
|
+
};
|
1957
|
+
|
1958
|
+
commandProto.doList = function (chunk, postProcessing, isNumberedList) {
|
1959
|
+
|
1960
|
+
// These are identical except at the very beginning and end.
|
1961
|
+
// Should probably use the regex extension function to make this clearer.
|
1962
|
+
var previousItemsRegex = /(\n|^)(([ ]{0,3}([*+-]|\d+[.])[ \t]+.*)(\n.+|\n{2,}([*+-].*|\d+[.])[ \t]+.*|\n{2,}[ \t]+\S.*)*)\n*$/;
|
1963
|
+
var nextItemsRegex = /^\n*(([ ]{0,3}([*+-]|\d+[.])[ \t]+.*)(\n.+|\n{2,}([*+-].*|\d+[.])[ \t]+.*|\n{2,}[ \t]+\S.*)*)\n*/;
|
1964
|
+
|
1965
|
+
// The default bullet is a dash but others are possible.
|
1966
|
+
// This has nothing to do with the particular HTML bullet,
|
1967
|
+
// it's just a markdown bullet.
|
1968
|
+
var bullet = "-";
|
1969
|
+
|
1970
|
+
// The number in a numbered list.
|
1971
|
+
var num = 1;
|
1972
|
+
|
1973
|
+
// Get the item prefix - e.g. " 1. " for a numbered list, " - " for a bulleted list.
|
1974
|
+
var getItemPrefix = function () {
|
1975
|
+
var prefix;
|
1976
|
+
if (isNumberedList) {
|
1977
|
+
prefix = " " + num + ". ";
|
1978
|
+
num++;
|
1979
|
+
}
|
1980
|
+
else {
|
1981
|
+
prefix = " " + bullet + " ";
|
1982
|
+
}
|
1983
|
+
return prefix;
|
1984
|
+
};
|
1985
|
+
|
1986
|
+
// Fixes the prefixes of the other list items.
|
1987
|
+
var getPrefixedItem = function (itemText) {
|
1988
|
+
|
1989
|
+
// The numbering flag is unset when called by autoindent.
|
1990
|
+
if (isNumberedList === undefined) {
|
1991
|
+
isNumberedList = /^\s*\d/.test(itemText);
|
1992
|
+
}
|
1993
|
+
|
1994
|
+
// Renumber/bullet the list element.
|
1995
|
+
itemText = itemText.replace(/^[ ]{0,3}([*+-]|\d+[.])\s/gm,
|
1996
|
+
function (_) {
|
1997
|
+
return getItemPrefix();
|
1998
|
+
});
|
1999
|
+
|
2000
|
+
return itemText;
|
2001
|
+
};
|
2002
|
+
|
2003
|
+
chunk.findTags(/(\n|^)*[ ]{0,3}([*+-]|\d+[.])\s+/, null);
|
2004
|
+
|
2005
|
+
if (chunk.before && !/\n$/.test(chunk.before) && !/^\n/.test(chunk.startTag)) {
|
2006
|
+
chunk.before += chunk.startTag;
|
2007
|
+
chunk.startTag = "";
|
2008
|
+
}
|
2009
|
+
|
2010
|
+
if (chunk.startTag) {
|
2011
|
+
|
2012
|
+
var hasDigits = /\d+[.]/.test(chunk.startTag);
|
2013
|
+
chunk.startTag = "";
|
2014
|
+
chunk.selection = chunk.selection.replace(/\n[ ]{4}/g, "\n");
|
2015
|
+
this.unwrap(chunk);
|
2016
|
+
chunk.skipLines();
|
2017
|
+
|
2018
|
+
if (hasDigits) {
|
2019
|
+
// Have to renumber the bullet points if this is a numbered list.
|
2020
|
+
chunk.after = chunk.after.replace(nextItemsRegex, getPrefixedItem);
|
2021
|
+
}
|
2022
|
+
if (isNumberedList == hasDigits) {
|
2023
|
+
return;
|
2024
|
+
}
|
2025
|
+
}
|
2026
|
+
|
2027
|
+
var nLinesUp = 1;
|
2028
|
+
|
2029
|
+
chunk.before = chunk.before.replace(previousItemsRegex,
|
2030
|
+
function (itemText) {
|
2031
|
+
if (/^\s*([*+-])/.test(itemText)) {
|
2032
|
+
bullet = re.$1;
|
2033
|
+
}
|
2034
|
+
nLinesUp = /[^\n]\n\n[^\n]/.test(itemText) ? 1 : 0;
|
2035
|
+
return getPrefixedItem(itemText);
|
2036
|
+
});
|
2037
|
+
|
2038
|
+
if (!chunk.selection) {
|
2039
|
+
chunk.selection = "List item";
|
2040
|
+
}
|
2041
|
+
|
2042
|
+
var prefix = getItemPrefix();
|
2043
|
+
|
2044
|
+
var nLinesDown = 1;
|
2045
|
+
|
2046
|
+
chunk.after = chunk.after.replace(nextItemsRegex,
|
2047
|
+
function (itemText) {
|
2048
|
+
nLinesDown = /[^\n]\n\n[^\n]/.test(itemText) ? 1 : 0;
|
2049
|
+
return getPrefixedItem(itemText);
|
2050
|
+
});
|
2051
|
+
|
2052
|
+
chunk.trimWhitespace(true);
|
2053
|
+
chunk.skipLines(nLinesUp, nLinesDown, true);
|
2054
|
+
chunk.startTag = prefix;
|
2055
|
+
var spaces = prefix.replace(/./g, " ");
|
2056
|
+
this.wrap(chunk, SETTINGS.lineLength - spaces.length);
|
2057
|
+
chunk.selection = chunk.selection.replace(/\n/g, "\n" + spaces);
|
2058
|
+
|
2059
|
+
};
|
2060
|
+
|
2061
|
+
commandProto.doHeading = function (chunk, postProcessing) {
|
2062
|
+
|
2063
|
+
// Remove leading/trailing whitespace and reduce internal spaces to single spaces.
|
2064
|
+
chunk.selection = chunk.selection.replace(/\s+/g, " ");
|
2065
|
+
chunk.selection = chunk.selection.replace(/(^\s+|\s+$)/g, "");
|
2066
|
+
|
2067
|
+
// If we clicked the button with no selected text, we just
|
2068
|
+
// make a level 2 hash header around some default text.
|
2069
|
+
if (!chunk.selection) {
|
2070
|
+
chunk.startTag = "## ";
|
2071
|
+
chunk.selection = "Heading";
|
2072
|
+
chunk.endTag = "";
|
2073
|
+
return;
|
2074
|
+
}
|
2075
|
+
|
2076
|
+
var headerLevel = 0; // The existing header level of the selected text.
|
2077
|
+
|
2078
|
+
// Remove any existing hash heading markdown and save the header level.
|
2079
|
+
chunk.findTags(/#+[ ]*/, /[ ]*#+/);
|
2080
|
+
if (/#+/.test(chunk.startTag)) {
|
2081
|
+
headerLevel = re.lastMatch.length;
|
2082
|
+
}
|
2083
|
+
chunk.startTag = chunk.endTag = "";
|
2084
|
+
|
2085
|
+
// Try to get the current header level by looking for - and = in the line
|
2086
|
+
// below the selection.
|
2087
|
+
chunk.findTags(null, /\s?(-+|=+)/);
|
2088
|
+
if (/=+/.test(chunk.endTag)) {
|
2089
|
+
headerLevel = 1;
|
2090
|
+
}
|
2091
|
+
if (/-+/.test(chunk.endTag)) {
|
2092
|
+
headerLevel = 2;
|
2093
|
+
}
|
2094
|
+
|
2095
|
+
// Skip to the next line so we can create the header markdown.
|
2096
|
+
chunk.startTag = chunk.endTag = "";
|
2097
|
+
chunk.skipLines(1, 1);
|
2098
|
+
|
2099
|
+
// We make a level 2 header if there is no current header.
|
2100
|
+
// If there is a header level, we substract one from the header level.
|
2101
|
+
// If it's already a level 1 header, it's removed.
|
2102
|
+
var headerLevelToCreate = headerLevel == 0 ? 2 : headerLevel - 1;
|
2103
|
+
|
2104
|
+
if (headerLevelToCreate > 0) {
|
2105
|
+
|
2106
|
+
// The button only creates level 1 and 2 underline headers.
|
2107
|
+
// Why not have it iterate over hash header levels? Wouldn't that be easier and cleaner?
|
2108
|
+
var headerChar = headerLevelToCreate >= 2 ? "-" : "=";
|
2109
|
+
var len = chunk.selection.length;
|
2110
|
+
if (len > SETTINGS.lineLength) {
|
2111
|
+
len = SETTINGS.lineLength;
|
2112
|
+
}
|
2113
|
+
chunk.endTag = "\n";
|
2114
|
+
while (len--) {
|
2115
|
+
chunk.endTag += headerChar;
|
2116
|
+
}
|
2117
|
+
}
|
2118
|
+
};
|
2119
|
+
|
2120
|
+
commandProto.doHorizontalRule = function (chunk, postProcessing) {
|
2121
|
+
chunk.startTag = "----------\n";
|
2122
|
+
chunk.selection = "";
|
2123
|
+
chunk.skipLines(2, 1, true);
|
2124
|
+
}
|
2125
|
+
|
2126
|
+
|
2127
|
+
})();
|