safe-mdx 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1566 @@
1
+ import React from 'react'
2
+ import dedent from 'dedent'
3
+ import { test, expect } from 'vitest'
4
+ import { MdastToJsx } from './safe-mdx'
5
+ void React
6
+
7
+ const components = {
8
+ Heading({ level, children }) {
9
+ return <h1>{children}</h1>
10
+ },
11
+ } as any
12
+
13
+ function render(code) {
14
+ const visitor = new MdastToJsx({ code, components })
15
+ const result = visitor.run()
16
+ // console.log(JSON.stringify(result, null, 2))
17
+ return { result, errors: visitor.errors || [] }
18
+ }
19
+
20
+ test('basic', () => {
21
+ expect(
22
+ render(dedent`
23
+ # Hello
24
+
25
+ i am a paragraph
26
+ `),
27
+ ).toMatchInlineSnapshot(`
28
+ {
29
+ "errors": [],
30
+ "result": <React.Fragment>
31
+ <h1>
32
+ Hello
33
+ </h1>
34
+ <p>
35
+ i am a paragraph
36
+ </p>
37
+ </React.Fragment>,
38
+ }
39
+ `)
40
+ })
41
+
42
+ test('inline jsx', () => {
43
+ expect(
44
+ render(dedent`
45
+ <Heading level={2}>hello</Heading>
46
+ `),
47
+ ).toMatchInlineSnapshot(`
48
+ {
49
+ "errors": [],
50
+ "result": <React.Fragment>
51
+ <p>
52
+ <Heading
53
+ level={2}
54
+ >
55
+ hello
56
+ </Heading>
57
+ </p>
58
+ </React.Fragment>,
59
+ }
60
+ `)
61
+ })
62
+
63
+ test('block jsx', () => {
64
+ expect(
65
+ render(dedent`
66
+ <Heading level={2}>
67
+ > hello
68
+ </Heading>
69
+ `),
70
+ ).toMatchInlineSnapshot(`
71
+ {
72
+ "errors": [],
73
+ "result": <React.Fragment>
74
+ <Heading
75
+ level={2}
76
+ >
77
+ <blockquote>
78
+ <p>
79
+ hello
80
+ </p>
81
+ </blockquote>
82
+ </Heading>
83
+ </React.Fragment>,
84
+ }
85
+ `)
86
+ })
87
+
88
+ test('missing components are ignored', () => {
89
+ expect(
90
+ render(dedent`
91
+ <MissingComponent level={2} />
92
+ `),
93
+ ).toMatchInlineSnapshot(`
94
+ {
95
+ "errors": [
96
+ {
97
+ "message": "Unsupported jsx component MissingComponent",
98
+ },
99
+ ],
100
+ "result": <React.Fragment />,
101
+ }
102
+ `)
103
+ })
104
+
105
+ test('props parsing', () => {
106
+ expect(
107
+ render(dedent`
108
+ <Heading
109
+ num={2}
110
+ doublequote={"a \" string"}
111
+ quote={'a \' string'}
112
+ backTick={\`some ${'${expr}'} value\`}
113
+ boolean={false}
114
+ expression1={1 + 3}
115
+ expression2={Boolean(1)}
116
+ jsx={<SomeComponent />}
117
+ undef={undefined}
118
+ null={null}
119
+ {...{
120
+ spread: true
121
+ }}
122
+ >
123
+ hi
124
+ </Heading>
125
+
126
+ `),
127
+ ).toMatchInlineSnapshot(`
128
+ {
129
+ "errors": [
130
+ {
131
+ "message": "Expressions in jsx props are not supported (expression1={1 + 3})",
132
+ },
133
+ {
134
+ "message": "Expressions in jsx props are not supported (expression2={Boolean(1)})",
135
+ },
136
+ {
137
+ "message": "Expressions in jsx props are not supported (jsx={<SomeComponent />})",
138
+ },
139
+ {
140
+ "message": "Expressions in jsx props are not supported (...{ spread: true })",
141
+ },
142
+ ],
143
+ "result": <React.Fragment>
144
+ <Heading
145
+ backTick="some \${expr} value"
146
+ boolean={false}
147
+ doublequote="a \\" string"
148
+ null={null}
149
+ num={2}
150
+ quote="a \\" string"
151
+ >
152
+ <p>
153
+ hi
154
+ </p>
155
+ </Heading>
156
+ </React.Fragment>,
157
+ }
158
+ `)
159
+ })
160
+ test('breaks', () => {
161
+ expect(
162
+ render(dedent`
163
+ To have a line break without a paragraph, you will need to use two trailing spaces.
164
+ Note that this line is separate, but within the same paragraph.
165
+ (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
166
+ `),
167
+ ).toMatchInlineSnapshot(`
168
+ {
169
+ "errors": [],
170
+ "result": <React.Fragment>
171
+ <p>
172
+ To have a line break without a paragraph, you will need to use two trailing spaces.
173
+ <br />
174
+ Note that this line is separate, but within the same paragraph.
175
+ <br />
176
+ (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
177
+ </p>
178
+ </React.Fragment>,
179
+ }
180
+ `)
181
+ })
182
+
183
+ // https://github.com/obedm503/markdown-kitchen-sink/blob/master/README.md?plain=1
184
+ test('kitchen sink', () => {
185
+ expect(
186
+ render(dedent`
187
+ # Markdown Kitchen Sink
188
+ This file is https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet plus a few fixes and additions. Used by [obedm503/bootmark](https://github.com/obedm503/bootmark) to [demonstrate](https://obedm503.github.io/bootmark/docs/markdown-cheatsheet.html) it's styling features.
189
+
190
+ This is intended as a quick reference and showcase. For more complete info, see [John Gruber's original spec](http://daringfireball.net/projects/markdown/) and the [Github-flavored Markdown info page](http://github.github.com/github-flavored-markdown/).
191
+
192
+ Note that there is also a [Cheatsheet specific to Markdown Here](./Markdown-Here-Cheatsheet) if that's what you're looking for. You can also check out [more Markdown tools](./Other-Markdown-Tools).
193
+
194
+ ##### Table of Contents
195
+ [Headers](#headers)
196
+ [Emphasis](#emphasis)
197
+ [Lists](#lists)
198
+ [Links](#links)
199
+ [Images](#images)
200
+ [Code and Syntax Highlighting](#code)
201
+ [Tables](#tables)
202
+ [Blockquotes](#blockquotes)
203
+ [Inline HTML](#html)
204
+ [Horizontal Rule](#hr)
205
+ [Line Breaks](#lines)
206
+ [YouTube Videos](#videos)
207
+
208
+ <a name="headers"></a>
209
+
210
+ ## Headers
211
+
212
+ \`\`\`no-highlight
213
+ # H1
214
+ ## H2
215
+ ### H3
216
+ #### H4
217
+ ##### H5
218
+ ###### H6
219
+
220
+ Alternatively, for H1 and H2, an underline-ish style:
221
+
222
+ Alt-H1
223
+ ======
224
+
225
+ Alt-H2
226
+ ------
227
+ \`\`\`
228
+
229
+ # H1
230
+ ## H2
231
+ ### H3
232
+ #### H4
233
+ ##### H5
234
+ ###### H6
235
+
236
+ Alternatively, for H1 and H2, an underline-ish style:
237
+
238
+ Alt-H1
239
+ ======
240
+
241
+ Alt-H2
242
+ ------
243
+
244
+ <a name="emphasis"></a>
245
+
246
+ ## Emphasis
247
+
248
+ \`\`\`no-highlight
249
+ Emphasis, aka italics, with *asterisks* or _underscores_.
250
+
251
+ Strong emphasis, aka bold, with **asterisks** or __underscores__.
252
+
253
+ Combined emphasis with **asterisks and _underscores_**.
254
+
255
+ Strikethrough uses two tildes. ~~Scratch this.~~
256
+ \`\`\`
257
+
258
+ Emphasis, aka italics, with *asterisks* or _underscores_.
259
+
260
+ Strong emphasis, aka bold, with **asterisks** or __underscores__.
261
+
262
+ Combined emphasis with **asterisks and _underscores_**.
263
+
264
+ Strikethrough uses two tildes. ~~Scratch this.~~
265
+
266
+
267
+ <a name="lists"></a>
268
+
269
+ ## Lists
270
+
271
+ (In this example, leading and trailing spaces are shown with with dots: ⋅)
272
+
273
+ \`\`\`no-highlight
274
+ 1. First ordered list item
275
+ 2. Another item
276
+ ⋅⋅* Unordered sub-list.
277
+ 1. Actual numbers don't matter, just that it's a number
278
+ ⋅⋅1. Ordered sub-list
279
+ 4. And another item.
280
+
281
+ ⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
282
+
283
+ ⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅
284
+ ⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅
285
+ ⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
286
+
287
+ * Unordered list can use asterisks
288
+ - Or minuses
289
+ + Or pluses
290
+ \`\`\`
291
+
292
+ 1. First ordered list item
293
+ 2. Another item
294
+ * Unordered sub-list.
295
+ 1. Actual numbers don't matter, just that it's a number
296
+ 1. Ordered sub-list
297
+ 4. And another item.
298
+
299
+ You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
300
+
301
+ To have a line break without a paragraph, you will need to use two trailing spaces.
302
+ Note that this line is separate, but within the same paragraph.
303
+ (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
304
+
305
+ * Unordered list can use asterisks
306
+ - Or minuses
307
+ + Or pluses
308
+
309
+ <a name="links"></a>
310
+
311
+ ## Links
312
+
313
+ There are two ways to create links.
314
+
315
+ \`\`\`no-highlight
316
+ [I'm an inline-style link](https://www.google.com)
317
+
318
+ [I'm an inline-style link with title](https://www.google.com "Google's Homepage")
319
+
320
+ [I'm a reference-style link][Arbitrary case-insensitive reference text]
321
+
322
+ [I'm a relative reference to a repository file](../blob/master/LICENSE)
323
+
324
+ [You can use numbers for reference-style link definitions][1]
325
+
326
+ Or leave it empty and use the [link text itself].
327
+
328
+ URLs and URLs in angle brackets will automatically get turned into links.
329
+ http://www.example.com and sometimes
330
+ example.com (but not on Github, for example).
331
+
332
+ Some text to show that the reference links can follow later.
333
+
334
+ [arbitrary case-insensitive reference text]: https://www.mozilla.org
335
+ [1]: http://slashdot.org
336
+ [link text itself]: http://www.reddit.com
337
+ \`\`\`
338
+
339
+ [I'm an inline-style link](https://www.google.com)
340
+
341
+ [I'm an inline-style link with title](https://www.google.com "Google's Homepage")
342
+
343
+ [I'm a reference-style link][Arbitrary case-insensitive reference text]
344
+
345
+ [I'm a relative reference to a repository file](../blob/master/LICENSE)
346
+
347
+ [You can use numbers for reference-style link definitions][1]
348
+
349
+ Or leave it empty and use the [link text itself].
350
+
351
+ URLs and URLs in angle brackets will automatically get turned into links.
352
+ http://www.example.com and sometimes
353
+ example.com (but not on Github, for example).
354
+
355
+ Some text to show that the reference links can follow later.
356
+
357
+ [arbitrary case-insensitive reference text]: https://www.mozilla.org
358
+ [1]: http://slashdot.org
359
+ [link text itself]: http://www.reddit.com
360
+
361
+ <a name="images"></a>
362
+
363
+ ## Images
364
+
365
+ \`\`\`no-highlight
366
+ Here's our logo (hover to see the title text):
367
+
368
+ Inline-style:
369
+ ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
370
+
371
+ Reference-style:
372
+ ![alt text][logo]
373
+
374
+ [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
375
+ \`\`\`
376
+
377
+ Here's our logo (hover to see the title text):
378
+
379
+ Inline-style:
380
+ ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
381
+
382
+ Reference-style:
383
+ ![alt text][logo]
384
+
385
+ [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
386
+
387
+ <a name="code"></a>
388
+
389
+ ## Code and Syntax Highlighting
390
+
391
+ Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and *Markdown Here* -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. *Markdown Here* supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the [highlight.js demo page](http://softwaremaniacs.org/media/soft/highlight/test.html).
392
+
393
+ \`\`\`no-highlight
394
+ Inline \`code\` has \`back-ticks around\` it.
395
+ \`\`\`
396
+
397
+ Inline \`code\` has \`back-ticks around\` it.
398
+
399
+ Blocks of code are either fenced by lines with three back-ticks <code>\`\`\`</code>, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.
400
+
401
+ \`\`\`javascript
402
+ var s = "JavaScript syntax highlighting";
403
+ alert(s);
404
+ \`\`\`
405
+
406
+ \`\`\`python
407
+ s = "Python syntax highlighting"
408
+ print s
409
+ \`\`\`
410
+
411
+ \`\`\`
412
+ No language indicated, so no syntax highlighting.
413
+ But let's throw in a &lt;b&gt;tag&lt;/b&gt;.
414
+ \`\`\`
415
+
416
+
417
+
418
+
419
+ \`\`\`javascript
420
+ var s = "JavaScript syntax highlighting";
421
+ alert(s);
422
+ \`\`\`
423
+
424
+ \`\`\`python
425
+ s = "Python syntax highlighting"
426
+ print s
427
+ \`\`\`
428
+
429
+ \`\`\`
430
+ No language indicated, so no syntax highlighting in Markdown Here (varies on Github).
431
+ But let's throw in a <b>tag</b>.
432
+ \`\`\`
433
+
434
+
435
+ <a name="tables"></a>
436
+
437
+ ## Tables
438
+
439
+ Tables aren't part of the core Markdown spec, but they are part of GFM and *Markdown Here* supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application.
440
+
441
+ \`\`\`no-highlight
442
+ Colons can be used to align columns.
443
+
444
+ | Tables | Are | Cool |
445
+ | ------------- |:-------------:| -----:|
446
+ | col 3 is | right-aligned | $1600 |
447
+ | col 2 is | centered | $12 |
448
+ | zebra stripes | are neat | $1 |
449
+
450
+ There must be at least 3 dashes separating each header cell.
451
+ The outer pipes (|) are optional, and you don't need to make the
452
+ raw Markdown line up prettily. You can also use inline Markdown.
453
+
454
+ Markdown | Less | Pretty
455
+ --- | --- | ---
456
+ *Still* | \`renders\` | **nicely**
457
+ 1 | 2 | 3
458
+ \`\`\`
459
+
460
+ Colons can be used to align columns.
461
+
462
+ | Tables | Are | Cool |
463
+ | ------------- |:-------------:| -----:|
464
+ | col 3 is | right-aligned | $1600 |
465
+ | col 2 is | centered | $12 |
466
+ | zebra stripes | are neat | $1 |
467
+
468
+ There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
469
+
470
+ Markdown | Less | Pretty
471
+ --- | --- | ---
472
+ *Still* | \`renders\` | **nicely**
473
+ 1 | 2 | 3
474
+
475
+ <a name="blockquotes"></a>
476
+
477
+ ## Blockquotes
478
+
479
+ \`\`\`no-highlight
480
+ > Blockquotes are very handy in email to emulate reply text.
481
+ > This line is part of the same quote.
482
+
483
+ Quote break.
484
+
485
+ > This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
486
+ \`\`\`
487
+
488
+ > Blockquotes are very handy in email to emulate reply text.
489
+ > This line is part of the same quote.
490
+
491
+ Quote break.
492
+
493
+ > This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
494
+
495
+ <a name="html"></a>
496
+
497
+ ## Inline HTML
498
+
499
+ You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
500
+
501
+ \`\`\`no-highlight
502
+ <dl>
503
+ <dt>Definition list</dt>
504
+ <dd>Is something people use sometimes.</dd>
505
+
506
+ <dt>Markdown in HTML</dt>
507
+ <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
508
+ </dl>
509
+ \`\`\`
510
+
511
+ <dl>
512
+ <dt>Definition list</dt>
513
+ <dd>Is something people use sometimes.</dd>
514
+
515
+ <dt>Markdown in HTML</dt>
516
+ <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
517
+ </dl>
518
+
519
+ <a name="hr"></a>
520
+
521
+ ## Horizontal Rule
522
+
523
+ \`\`\`
524
+ Three or more...
525
+
526
+ ---
527
+
528
+ Hyphens
529
+
530
+ ***
531
+
532
+ Asterisks
533
+
534
+ ___
535
+
536
+ Underscores
537
+ \`\`\`
538
+
539
+ Three or more...
540
+
541
+ ---
542
+
543
+ Hyphens
544
+
545
+ ***
546
+
547
+ Asterisks
548
+
549
+ ___
550
+
551
+ Underscores
552
+
553
+ <a name="lines"></a>
554
+
555
+ ## Line Breaks
556
+
557
+ My basic recommendation for learning how line breaks work is to experiment and discover -- hit &lt;Enter&gt; once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend.
558
+
559
+ Here are some things to try out:
560
+
561
+ \`\`\`
562
+ Here's a line for us to start with.
563
+
564
+ This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
565
+
566
+ This line is also a separate paragraph, but...
567
+ This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
568
+ \`\`\`
569
+
570
+ Here's a line for us to start with.
571
+
572
+ This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
573
+
574
+ This line is also begins a separate paragraph, but...
575
+ This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
576
+
577
+ (Technical note: *Markdown Here* uses GFM line breaks, so there's no need to use MD's two-space line breaks.)
578
+
579
+ <a name="videos"></a>
580
+
581
+ ## YouTube Videos
582
+
583
+ They can't be added directly but you can add an image with a link to the video like this:
584
+
585
+ \`\`\`no-highlight
586
+ <a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE
587
+ " target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg"
588
+ alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /></a>
589
+ \`\`\`
590
+
591
+ Or, in pure Markdown, but losing the image sizing and border:
592
+
593
+ \`\`\`no-highlight
594
+ [![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE)
595
+ \`\`\`
596
+
597
+ `),
598
+ ).toMatchInlineSnapshot(`
599
+ {
600
+ "errors": [
601
+ {
602
+ "message": "Unsupported jsx component dl",
603
+ },
604
+ ],
605
+ "result": <React.Fragment>
606
+ <h1>
607
+ Markdown Kitchen Sink
608
+ </h1>
609
+ <p>
610
+ This file is
611
+ <a
612
+ href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet"
613
+ title=""
614
+ >
615
+ https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
616
+ </a>
617
+ plus a few fixes and additions. Used by
618
+ <a
619
+ href="https://github.com/obedm503/bootmark"
620
+ title=""
621
+ >
622
+ obedm503/bootmark
623
+ </a>
624
+ to
625
+ <a
626
+ href="https://obedm503.github.io/bootmark/docs/markdown-cheatsheet.html"
627
+ title=""
628
+ >
629
+ demonstrate
630
+ </a>
631
+ it's styling features.
632
+ </p>
633
+ <p>
634
+ This is intended as a quick reference and showcase. For more complete info, see
635
+ <a
636
+ href="http://daringfireball.net/projects/markdown/"
637
+ title=""
638
+ >
639
+ John Gruber's original spec
640
+ </a>
641
+ and the
642
+ <a
643
+ href="http://github.github.com/github-flavored-markdown/"
644
+ title=""
645
+ >
646
+ Github-flavored Markdown info page
647
+ </a>
648
+ .
649
+ </p>
650
+ <p>
651
+ Note that there is also a
652
+ <a
653
+ href="./Markdown-Here-Cheatsheet"
654
+ title=""
655
+ >
656
+ Cheatsheet specific to Markdown Here
657
+ </a>
658
+ if that's what you're looking for. You can also check out
659
+ <a
660
+ href="./Other-Markdown-Tools"
661
+ title=""
662
+ >
663
+ more Markdown tools
664
+ </a>
665
+ .
666
+ </p>
667
+ <h5>
668
+ Table of Contents
669
+ </h5>
670
+ <p>
671
+ <a
672
+ href="#headers"
673
+ title=""
674
+ >
675
+ Headers
676
+ </a>
677
+ <br />
678
+ <a
679
+ href="#emphasis"
680
+ title=""
681
+ >
682
+ Emphasis
683
+ </a>
684
+ <br />
685
+ <a
686
+ href="#lists"
687
+ title=""
688
+ >
689
+ Lists
690
+ </a>
691
+ <br />
692
+ <a
693
+ href="#links"
694
+ title=""
695
+ >
696
+ Links
697
+ </a>
698
+ <br />
699
+ <a
700
+ href="#images"
701
+ title=""
702
+ >
703
+ Images
704
+ </a>
705
+ <br />
706
+ <a
707
+ href="#code"
708
+ title=""
709
+ >
710
+ Code and Syntax Highlighting
711
+ </a>
712
+ <br />
713
+ <a
714
+ href="#tables"
715
+ title=""
716
+ >
717
+ Tables
718
+ </a>
719
+ <br />
720
+ <a
721
+ href="#blockquotes"
722
+ title=""
723
+ >
724
+ Blockquotes
725
+ </a>
726
+ <br />
727
+ <a
728
+ href="#html"
729
+ title=""
730
+ >
731
+ Inline HTML
732
+ </a>
733
+ <br />
734
+ <a
735
+ href="#hr"
736
+ title=""
737
+ >
738
+ Horizontal Rule
739
+ </a>
740
+ <br />
741
+ <a
742
+ href="#lines"
743
+ title=""
744
+ >
745
+ Line Breaks
746
+ </a>
747
+ <br />
748
+ <a
749
+ href="#videos"
750
+ title=""
751
+ >
752
+ YouTube Videos
753
+ </a>
754
+ </p>
755
+ <a
756
+ name="headers"
757
+ />
758
+ <h2>
759
+ Headers
760
+ </h2>
761
+ <pre>
762
+ <code
763
+ className="language-no-highlight"
764
+ >
765
+ # H1
766
+ ## H2
767
+ ### H3
768
+ #### H4
769
+ ##### H5
770
+ ###### H6
771
+
772
+ Alternatively, for H1 and H2, an underline-ish style:
773
+
774
+ Alt-H1
775
+ ======
776
+
777
+ Alt-H2
778
+ ------
779
+ </code>
780
+ </pre>
781
+ <h1>
782
+ H1
783
+ </h1>
784
+ <h2>
785
+ H2
786
+ </h2>
787
+ <h3>
788
+ H3
789
+ </h3>
790
+ <h4>
791
+ H4
792
+ </h4>
793
+ <h5>
794
+ H5
795
+ </h5>
796
+ <h6>
797
+ H6
798
+ </h6>
799
+ <p>
800
+ Alternatively, for H1 and H2, an underline-ish style:
801
+ </p>
802
+ <h1>
803
+ Alt-H1
804
+ </h1>
805
+ <h2>
806
+ Alt-H2
807
+ </h2>
808
+ <a
809
+ name="emphasis"
810
+ />
811
+ <h2>
812
+ Emphasis
813
+ </h2>
814
+ <pre>
815
+ <code
816
+ className="language-no-highlight"
817
+ >
818
+ Emphasis, aka italics, with *asterisks* or _underscores_.
819
+
820
+ Strong emphasis, aka bold, with **asterisks** or __underscores__.
821
+
822
+ Combined emphasis with **asterisks and _underscores_**.
823
+
824
+ Strikethrough uses two tildes. ~~Scratch this.~~
825
+ </code>
826
+ </pre>
827
+ <p>
828
+ Emphasis, aka italics, with
829
+ <em>
830
+ asterisks
831
+ </em>
832
+ or
833
+ <em>
834
+ underscores
835
+ </em>
836
+ .
837
+ </p>
838
+ <p>
839
+ Strong emphasis, aka bold, with
840
+ <strong>
841
+ asterisks
842
+ </strong>
843
+ or
844
+ <strong>
845
+ underscores
846
+ </strong>
847
+ .
848
+ </p>
849
+ <p>
850
+ Combined emphasis with
851
+ <strong>
852
+ asterisks and
853
+ <em>
854
+ underscores
855
+ </em>
856
+ </strong>
857
+ .
858
+ </p>
859
+ <p>
860
+ Strikethrough uses two tildes.
861
+ <del>
862
+ Scratch this.
863
+ </del>
864
+ </p>
865
+ <a
866
+ name="lists"
867
+ />
868
+ <h2>
869
+ Lists
870
+ </h2>
871
+ <p>
872
+ (In this example, leading and trailing spaces are shown with with dots: ⋅)
873
+ </p>
874
+ <pre>
875
+ <code
876
+ className="language-no-highlight"
877
+ >
878
+ 1. First ordered list item
879
+ 2. Another item
880
+ ⋅⋅* Unordered sub-list.
881
+ 1. Actual numbers don't matter, just that it's a number
882
+ ⋅⋅1. Ordered sub-list
883
+ 4. And another item.
884
+
885
+ ⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
886
+
887
+ ⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅
888
+ ⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅
889
+ ⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
890
+
891
+ * Unordered list can use asterisks
892
+ - Or minuses
893
+ + Or pluses
894
+ </code>
895
+ </pre>
896
+ <ol
897
+ start={1}
898
+ >
899
+ <li>
900
+ <p>
901
+ First ordered list item
902
+ </p>
903
+ </li>
904
+ <li>
905
+ <p>
906
+ Another item
907
+ </p>
908
+ </li>
909
+ </ol>
910
+ <ul>
911
+ <li>
912
+ <p>
913
+ Unordered sub-list.
914
+ </p>
915
+ </li>
916
+ </ul>
917
+ <ol
918
+ start={1}
919
+ >
920
+ <li>
921
+ <p>
922
+ Actual numbers don't matter, just that it's a number
923
+ </p>
924
+ </li>
925
+ <li>
926
+ <p>
927
+ Ordered sub-list
928
+ </p>
929
+ </li>
930
+ <li>
931
+ <p>
932
+ And another item.
933
+ </p>
934
+ <p>
935
+ You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
936
+ </p>
937
+ <p>
938
+ To have a line break without a paragraph, you will need to use two trailing spaces.
939
+ <br />
940
+ Note that this line is separate, but within the same paragraph.
941
+ <br />
942
+ (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
943
+ </p>
944
+ </li>
945
+ </ol>
946
+ <ul>
947
+ <li>
948
+ <p>
949
+ Unordered list can use asterisks
950
+ </p>
951
+ </li>
952
+ </ul>
953
+ <ul>
954
+ <li>
955
+ <p>
956
+ Or minuses
957
+ </p>
958
+ </li>
959
+ </ul>
960
+ <ul>
961
+ <li>
962
+ <p>
963
+ Or pluses
964
+ </p>
965
+ </li>
966
+ </ul>
967
+ <a
968
+ name="links"
969
+ />
970
+ <h2>
971
+ Links
972
+ </h2>
973
+ <p>
974
+ There are two ways to create links.
975
+ </p>
976
+ <pre>
977
+ <code
978
+ className="language-no-highlight"
979
+ >
980
+ [I'm an inline-style link](https://www.google.com)
981
+
982
+ [I'm an inline-style link with title](https://www.google.com "Google's Homepage")
983
+
984
+ [I'm a reference-style link][Arbitrary case-insensitive reference text]
985
+
986
+ [I'm a relative reference to a repository file](../blob/master/LICENSE)
987
+
988
+ [You can use numbers for reference-style link definitions][1]
989
+
990
+ Or leave it empty and use the [link text itself].
991
+
992
+ URLs and URLs in angle brackets will automatically get turned into links.
993
+ http://www.example.com and sometimes
994
+ example.com (but not on Github, for example).
995
+
996
+ Some text to show that the reference links can follow later.
997
+
998
+ [arbitrary case-insensitive reference text]: https://www.mozilla.org
999
+ [1]: http://slashdot.org
1000
+ [link text itself]: http://www.reddit.com
1001
+ </code>
1002
+ </pre>
1003
+ <p>
1004
+ <a
1005
+ href="https://www.google.com"
1006
+ title=""
1007
+ >
1008
+ I'm an inline-style link
1009
+ </a>
1010
+ </p>
1011
+ <p>
1012
+ <a
1013
+ href="https://www.google.com"
1014
+ title="Google's Homepage"
1015
+ >
1016
+ I'm an inline-style link with title
1017
+ </a>
1018
+ </p>
1019
+ <p>
1020
+ <a
1021
+ href="https://www.mozilla.org"
1022
+ >
1023
+ I'm a reference-style link
1024
+ </a>
1025
+ </p>
1026
+ <p>
1027
+ <a
1028
+ href="../blob/master/LICENSE"
1029
+ title=""
1030
+ >
1031
+ I'm a relative reference to a repository file
1032
+ </a>
1033
+ </p>
1034
+ <p>
1035
+ <a
1036
+ href="http://slashdot.org"
1037
+ >
1038
+ You can use numbers for reference-style link definitions
1039
+ </a>
1040
+ </p>
1041
+ <p>
1042
+ Or leave it empty and use the
1043
+ <a
1044
+ href="http://www.reddit.com"
1045
+ >
1046
+ link text itself
1047
+ </a>
1048
+ .
1049
+ </p>
1050
+ <p>
1051
+ URLs and URLs in angle brackets will automatically get turned into links.
1052
+
1053
+ <a
1054
+ href="http://www.example.com"
1055
+ title=""
1056
+ >
1057
+ http://www.example.com
1058
+ </a>
1059
+ and sometimes
1060
+ example.com (but not on Github, for example).
1061
+ </p>
1062
+ <p>
1063
+ Some text to show that the reference links can follow later.
1064
+ </p>
1065
+ <a
1066
+ name="images"
1067
+ />
1068
+ <h2>
1069
+ Images
1070
+ </h2>
1071
+ <pre>
1072
+ <code
1073
+ className="language-no-highlight"
1074
+ >
1075
+ Here's our logo (hover to see the title text):
1076
+
1077
+ Inline-style:
1078
+ ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
1079
+
1080
+ Reference-style:
1081
+ ![alt text][logo]
1082
+
1083
+ [logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
1084
+ </code>
1085
+ </pre>
1086
+ <p>
1087
+ Here's our logo (hover to see the title text):
1088
+ </p>
1089
+ <p>
1090
+ Inline-style:
1091
+
1092
+ <img
1093
+ alt="alt text"
1094
+ src="https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png"
1095
+ title="Logo Title Text 1"
1096
+ />
1097
+ </p>
1098
+ <p>
1099
+ Reference-style:
1100
+
1101
+ </p>
1102
+ <a
1103
+ name="code"
1104
+ />
1105
+ <h2>
1106
+ Code and Syntax Highlighting
1107
+ </h2>
1108
+ <p>
1109
+ Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and
1110
+ <em>
1111
+ Markdown Here
1112
+ </em>
1113
+ -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer.
1114
+ <em>
1115
+ Markdown Here
1116
+ </em>
1117
+ supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the
1118
+ <a
1119
+ href="http://softwaremaniacs.org/media/soft/highlight/test.html"
1120
+ title=""
1121
+ >
1122
+ highlight.js demo page
1123
+ </a>
1124
+ .
1125
+ </p>
1126
+ <pre>
1127
+ <code
1128
+ className="language-no-highlight"
1129
+ >
1130
+ Inline \`code\` has \`back-ticks around\` it.
1131
+ </code>
1132
+ </pre>
1133
+ <p>
1134
+ Inline
1135
+ <code>
1136
+ code
1137
+ </code>
1138
+ has
1139
+ <code>
1140
+ back-ticks around
1141
+ </code>
1142
+ it.
1143
+ </p>
1144
+ <p>
1145
+ Blocks of code are either fenced by lines with three back-ticks
1146
+ <code>
1147
+ \`\`\`
1148
+ </code>
1149
+ , or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.
1150
+ </p>
1151
+ <pre>
1152
+ <code
1153
+ className="language-javascript"
1154
+ >
1155
+ var s = "JavaScript syntax highlighting";
1156
+ alert(s);
1157
+ </code>
1158
+ </pre>
1159
+ <pre>
1160
+ <code
1161
+ className="language-python"
1162
+ >
1163
+ s = "Python syntax highlighting"
1164
+ print s
1165
+ </code>
1166
+ </pre>
1167
+ <pre>
1168
+ <code
1169
+ className="language-"
1170
+ >
1171
+ No language indicated, so no syntax highlighting.
1172
+ But let's throw in a &lt;b&gt;tag&lt;/b&gt;.
1173
+ </code>
1174
+ </pre>
1175
+ <pre>
1176
+ <code
1177
+ className="language-javascript"
1178
+ >
1179
+ var s = "JavaScript syntax highlighting";
1180
+ alert(s);
1181
+ </code>
1182
+ </pre>
1183
+ <pre>
1184
+ <code
1185
+ className="language-python"
1186
+ >
1187
+ s = "Python syntax highlighting"
1188
+ print s
1189
+ </code>
1190
+ </pre>
1191
+ <pre>
1192
+ <code
1193
+ className="language-"
1194
+ >
1195
+ No language indicated, so no syntax highlighting in Markdown Here (varies on Github).
1196
+ But let's throw in a &lt;b&gt;tag&lt;/b&gt;.
1197
+ </code>
1198
+ </pre>
1199
+ <a
1200
+ name="tables"
1201
+ />
1202
+ <h2>
1203
+ Tables
1204
+ </h2>
1205
+ <p>
1206
+ Tables aren't part of the core Markdown spec, but they are part of GFM and
1207
+ <em>
1208
+ Markdown Here
1209
+ </em>
1210
+ supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application.
1211
+ </p>
1212
+ <pre>
1213
+ <code
1214
+ className="language-no-highlight"
1215
+ >
1216
+ Colons can be used to align columns.
1217
+
1218
+ | Tables | Are | Cool |
1219
+ | ------------- |:-------------:| -----:|
1220
+ | col 3 is | right-aligned | $1600 |
1221
+ | col 2 is | centered | $12 |
1222
+ | zebra stripes | are neat | $1 |
1223
+
1224
+ There must be at least 3 dashes separating each header cell.
1225
+ The outer pipes (|) are optional, and you don't need to make the
1226
+ raw Markdown line up prettily. You can also use inline Markdown.
1227
+
1228
+ Markdown | Less | Pretty
1229
+ --- | --- | ---
1230
+ *Still* | \`renders\` | **nicely**
1231
+ 1 | 2 | 3
1232
+ </code>
1233
+ </pre>
1234
+ <p>
1235
+ Colons can be used to align columns.
1236
+ </p>
1237
+ <table>
1238
+ <tr
1239
+ className=""
1240
+ >
1241
+ <td
1242
+ className=""
1243
+ >
1244
+ Tables
1245
+ </td>
1246
+ <td
1247
+ className=""
1248
+ >
1249
+ Are
1250
+ </td>
1251
+ <td
1252
+ className=""
1253
+ >
1254
+ Cool
1255
+ </td>
1256
+ </tr>
1257
+ <tr
1258
+ className=""
1259
+ >
1260
+ <td
1261
+ className=""
1262
+ >
1263
+ col 3 is
1264
+ </td>
1265
+ <td
1266
+ className=""
1267
+ >
1268
+ right-aligned
1269
+ </td>
1270
+ <td
1271
+ className=""
1272
+ >
1273
+ $1600
1274
+ </td>
1275
+ </tr>
1276
+ <tr
1277
+ className=""
1278
+ >
1279
+ <td
1280
+ className=""
1281
+ >
1282
+ col 2 is
1283
+ </td>
1284
+ <td
1285
+ className=""
1286
+ >
1287
+ centered
1288
+ </td>
1289
+ <td
1290
+ className=""
1291
+ >
1292
+ $12
1293
+ </td>
1294
+ </tr>
1295
+ <tr
1296
+ className=""
1297
+ >
1298
+ <td
1299
+ className=""
1300
+ >
1301
+ zebra stripes
1302
+ </td>
1303
+ <td
1304
+ className=""
1305
+ >
1306
+ are neat
1307
+ </td>
1308
+ <td
1309
+ className=""
1310
+ >
1311
+ $1
1312
+ </td>
1313
+ </tr>
1314
+ </table>
1315
+ <p>
1316
+ There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
1317
+ </p>
1318
+ <table>
1319
+ <tr
1320
+ className=""
1321
+ >
1322
+ <td
1323
+ className=""
1324
+ >
1325
+ Markdown
1326
+ </td>
1327
+ <td
1328
+ className=""
1329
+ >
1330
+ Less
1331
+ </td>
1332
+ <td
1333
+ className=""
1334
+ >
1335
+ Pretty
1336
+ </td>
1337
+ </tr>
1338
+ <tr
1339
+ className=""
1340
+ >
1341
+ <td
1342
+ className=""
1343
+ >
1344
+ <em>
1345
+ Still
1346
+ </em>
1347
+ </td>
1348
+ <td
1349
+ className=""
1350
+ >
1351
+ <code>
1352
+ renders
1353
+ </code>
1354
+ </td>
1355
+ <td
1356
+ className=""
1357
+ >
1358
+ <strong>
1359
+ nicely
1360
+ </strong>
1361
+ </td>
1362
+ </tr>
1363
+ <tr
1364
+ className=""
1365
+ >
1366
+ <td
1367
+ className=""
1368
+ >
1369
+ 1
1370
+ </td>
1371
+ <td
1372
+ className=""
1373
+ >
1374
+ 2
1375
+ </td>
1376
+ <td
1377
+ className=""
1378
+ >
1379
+ 3
1380
+ </td>
1381
+ </tr>
1382
+ </table>
1383
+ <a
1384
+ name="blockquotes"
1385
+ />
1386
+ <h2>
1387
+ Blockquotes
1388
+ </h2>
1389
+ <pre>
1390
+ <code
1391
+ className="language-no-highlight"
1392
+ >
1393
+ &gt; Blockquotes are very handy in email to emulate reply text.
1394
+ &gt; This line is part of the same quote.
1395
+
1396
+ Quote break.
1397
+
1398
+ &gt; This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
1399
+ </code>
1400
+ </pre>
1401
+ <blockquote>
1402
+ <p>
1403
+ Blockquotes are very handy in email to emulate reply text.
1404
+ This line is part of the same quote.
1405
+ </p>
1406
+ </blockquote>
1407
+ <p>
1408
+ Quote break.
1409
+ </p>
1410
+ <blockquote>
1411
+ <p>
1412
+ This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can
1413
+ <em>
1414
+ put
1415
+ </em>
1416
+
1417
+ <strong>
1418
+ Markdown
1419
+ </strong>
1420
+ into a blockquote.
1421
+ </p>
1422
+ </blockquote>
1423
+ <a
1424
+ name="html"
1425
+ />
1426
+ <h2>
1427
+ Inline HTML
1428
+ </h2>
1429
+ <p>
1430
+ You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
1431
+ </p>
1432
+ <pre>
1433
+ <code
1434
+ className="language-no-highlight"
1435
+ >
1436
+ &lt;dl&gt;
1437
+ &lt;dt&gt;Definition list&lt;/dt&gt;
1438
+ &lt;dd&gt;Is something people use sometimes.&lt;/dd&gt;
1439
+
1440
+ &lt;dt&gt;Markdown in HTML&lt;/dt&gt;
1441
+ &lt;dd&gt;Does *not* work **very** well. Use HTML &lt;em&gt;tags&lt;/em&gt;.&lt;/dd&gt;
1442
+ &lt;/dl&gt;
1443
+ </code>
1444
+ </pre>
1445
+ <a
1446
+ name="hr"
1447
+ />
1448
+ <h2>
1449
+ Horizontal Rule
1450
+ </h2>
1451
+ <pre>
1452
+ <code
1453
+ className="language-"
1454
+ >
1455
+ Three or more...
1456
+
1457
+ ---
1458
+
1459
+ Hyphens
1460
+
1461
+ ***
1462
+
1463
+ Asterisks
1464
+
1465
+ ___
1466
+
1467
+ Underscores
1468
+ </code>
1469
+ </pre>
1470
+ <p>
1471
+ Three or more...
1472
+ </p>
1473
+ <hr />
1474
+ <p>
1475
+ Hyphens
1476
+ </p>
1477
+ <hr />
1478
+ <p>
1479
+ Asterisks
1480
+ </p>
1481
+ <hr />
1482
+ <p>
1483
+ Underscores
1484
+ </p>
1485
+ <a
1486
+ name="lines"
1487
+ />
1488
+ <h2>
1489
+ Line Breaks
1490
+ </h2>
1491
+ <p>
1492
+ My basic recommendation for learning how line breaks work is to experiment and discover -- hit &lt;Enter&gt; once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend.
1493
+ </p>
1494
+ <p>
1495
+ Here are some things to try out:
1496
+ </p>
1497
+ <pre>
1498
+ <code
1499
+ className="language-"
1500
+ >
1501
+ Here's a line for us to start with.
1502
+
1503
+ This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
1504
+
1505
+ This line is also a separate paragraph, but...
1506
+ This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
1507
+ </code>
1508
+ </pre>
1509
+ <p>
1510
+ Here's a line for us to start with.
1511
+ </p>
1512
+ <p>
1513
+ This line is separated from the one above by two newlines, so it will be a
1514
+ <em>
1515
+ separate paragraph
1516
+ </em>
1517
+ .
1518
+ </p>
1519
+ <p>
1520
+ This line is also begins a separate paragraph, but...
1521
+ <br />
1522
+ This line is only separated by a single newline, so it's a separate line in the
1523
+ <em>
1524
+ same paragraph
1525
+ </em>
1526
+ .
1527
+ </p>
1528
+ <p>
1529
+ (Technical note:
1530
+ <em>
1531
+ Markdown Here
1532
+ </em>
1533
+ uses GFM line breaks, so there's no need to use MD's two-space line breaks.)
1534
+ </p>
1535
+ <a
1536
+ name="videos"
1537
+ />
1538
+ <h2>
1539
+ YouTube Videos
1540
+ </h2>
1541
+ <p>
1542
+ They can't be added directly but you can add an image with a link to the video like this:
1543
+ </p>
1544
+ <pre>
1545
+ <code
1546
+ className="language-no-highlight"
1547
+ >
1548
+ &lt;a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE
1549
+ " target="_blank"&gt;&lt;img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg"
1550
+ alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /&gt;&lt;/a&gt;
1551
+ </code>
1552
+ </pre>
1553
+ <p>
1554
+ Or, in pure Markdown, but losing the image sizing and border:
1555
+ </p>
1556
+ <pre>
1557
+ <code
1558
+ className="language-no-highlight"
1559
+ >
1560
+ [![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE)
1561
+ </code>
1562
+ </pre>
1563
+ </React.Fragment>,
1564
+ }
1565
+ `)
1566
+ })