@podlite/to-jsx 0.0.15 → 0.0.17

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.
@@ -1,30 +1,12 @@
1
1
  import Podlite from '../src/index'
2
2
  import React from 'react'
3
- import ReactDOM from 'react-dom'
3
+ import { renderToStaticMarkup } from 'react-dom/server'
4
4
 
5
5
  const fs = require('fs')
6
6
  const path = require('path')
7
- const glob = require('glob')
7
+ const glob = require('glob')
8
8
 
9
-
10
- // const describe = ( _ , f)=> f()
11
- // const it = (_, f) => f()
12
- // const expect = (any):any=>{
13
- // const c=(any):any=>{}
14
- // c.toEqual = ()=>{}
15
- // return c
16
- // }
17
-
18
- const root = document.body.appendChild(document.createElement('div'))
19
-
20
- function render(jsx) {
21
- return ReactDOM.render(jsx, root)
22
- }
23
-
24
- afterEach(() => ReactDOM.unmountComponentAtNode(root))
25
-
26
-
27
- // load examples from fixtures src
9
+ // load examples from fixtures src
28
10
  /**
29
11
  *
30
12
  * @returns
@@ -34,33 +16,32 @@ afterEach(() => ReactDOM.unmountComponentAtNode(root))
34
16
  testFile: 't/fixtures/00-maintests_5.txt' }, 
35
17
  */
36
18
  const allSrcFixtures = () => {
37
- const pathToTests = path.resolve(__dirname, './fixtures-src')
38
- const files = glob.sync(`${pathToTests}/*.t`)
39
- const loaded = files.map( file => {
40
- const d = fs.readFileSync(file)
41
- const s = `${d}`.split(/#---+\n/)
42
- .filter( t => t.match(/^\s*=/))
43
- .map( (text,i) => {
44
- const { dir, name } = path.parse(file)
45
- const testFile = `t/fixtures/${name}_${i}.txt`
46
- return {file,
47
- id:i,
48
- text,
49
- testFile,
50
- }});
51
- return s
52
- }
53
- ).flat()
54
- return loaded
19
+ const pathToTests = path.resolve(__dirname, './fixtures-src')
20
+ const files = glob.sync(`${pathToTests}/*.t`)
21
+ const loaded = files
22
+ .map(file => {
23
+ const d = fs.readFileSync(file)
24
+ const s = `${d}`
25
+ .split(/#---+\n/)
26
+ .filter(t => t.match(/^\s*=/))
27
+ .map((text, i) => {
28
+ const { dir, name } = path.parse(file)
29
+ const testFile = `t/fixtures/${name}_${i}.txt`
30
+ return { file, id: i, text, testFile }
31
+ })
32
+ return s
33
+ })
34
+ .flat()
35
+ return loaded
55
36
  }
56
37
  const t = allSrcFixtures()
57
38
  t
58
39
 
59
- describe("run parser tests", () => {
60
- allSrcFixtures().map(i => test(i.file, ()=>{
61
- render(<Podlite>{i.text}</Podlite>)
62
- // console.log(root.innerHTML)
63
- expect(root.innerHTML).not.toBeNull()
64
- }
65
- ))
40
+ describe('run parser tests', () => {
41
+ allSrcFixtures().map(i =>
42
+ test(i.file, () => {
43
+ const result = renderToStaticMarkup(<Podlite>{i.text}</Podlite>)
44
+ expect(result).not.toBeNull()
45
+ }),
46
+ )
66
47
  })
@@ -1,29 +1,28 @@
1
- import { TestPodlite as Podlite } from "../src/index";
2
- import React from "react";
3
- import ReactDOM from "react-dom";
4
-
5
- const root = document.body.appendChild(document.createElement("div"));
1
+ import { TestPodlite as Podlite, Podlite as PodliteRaw } from '../src/index'
2
+ import React from 'react'
3
+ import { renderToStaticMarkup } from 'react-dom/server'
6
4
 
5
+ const root = { innerHTML: '' }
7
6
  function render(jsx) {
8
- return ReactDOM.render(jsx, root);
7
+ root.innerHTML = renderToStaticMarkup(jsx)
8
+ return root.innerHTML
9
9
  }
10
10
 
11
- afterEach(() => ReactDOM.unmountComponentAtNode(root));
12
-
13
- it("para content", () => {
14
- render(<Podlite>Hello!</Podlite>);
11
+ it('para content', () => {
12
+ render(<Podlite>Hello!</Podlite>)
15
13
 
16
14
  expect(root.innerHTML).toMatchInlineSnapshot(`
17
15
  <p>
18
16
  Hello!
19
17
  </p>
20
- `);
21
- });
18
+ `)
19
+ })
22
20
 
23
- it("table", () => {
24
- render(
25
- <Podlite>
26
- {`
21
+ it('table', () => {
22
+ expect(
23
+ render(
24
+ <Podlite>
25
+ {`
27
26
  =begin pod
28
27
  =para test
29
28
  sdsdsd
@@ -45,9 +44,9 @@ sdsdsd
45
44
  =end table
46
45
  =end pod
47
46
  `}
48
- </Podlite>
49
- );
50
- expect(root.innerHTML).toMatchInlineSnapshot(`
47
+ </Podlite>,
48
+ ),
49
+ ).toMatchInlineSnapshot(`
51
50
  <div id="id">
52
51
  <div id="id">
53
52
  <p>
@@ -82,7 +81,7 @@ sdsdsd
82
81
  Eddie Stevens
83
82
  </td>
84
83
  <td id="id">
85
- King Arthur's singing shovel
84
+ King Arthur&#x27;s singing shovel
86
85
  </td>
87
86
  </tr>
88
87
  <tr id="id">
@@ -124,30 +123,31 @@ sdsdsd
124
123
  </tbody>
125
124
  </table>
126
125
  </div>
127
- `);
128
- });
126
+ `)
127
+ })
129
128
 
130
- it("accepts =alias", () => {
131
- render(
132
- <Podlite>
133
- {`
129
+ it('accepts =alias', () => {
130
+ expect(
131
+ render(
132
+ <Podlite>
133
+ {`
134
134
  =begin pod
135
135
  =alias TEST 4D Kingdoms
136
136
  A<TEST>
137
137
  =end pod
138
138
  `}
139
- </Podlite>
140
- );
141
- expect(root.innerHTML).toMatchInlineSnapshot(`
139
+ </Podlite>,
140
+ ),
141
+ ).toMatchInlineSnapshot(`
142
142
  <div id="id">
143
143
  <p>
144
144
  4D Kingdoms
145
145
  </p>
146
146
  </div>
147
- `);
148
- });
147
+ `)
148
+ })
149
149
 
150
- it("accepts =code", () => {
150
+ it('accepts =code', () => {
151
151
  render(
152
152
  <Podlite>
153
153
  {`
@@ -162,8 +162,8 @@ it("accepts =code", () => {
162
162
  asdasdasdasdsad
163
163
  =end code
164
164
  `}
165
- </Podlite>
166
- );
165
+ </Podlite>,
166
+ )
167
167
  expect(root.innerHTML).toMatchInlineSnapshot(`
168
168
  <code>
169
169
  <pre>
@@ -183,10 +183,10 @@ it("accepts =code", () => {
183
183
  asdasdasdasdsad
184
184
  </pre>
185
185
  </code>
186
- `);
187
- });
186
+ `)
187
+ })
188
188
 
189
- it("accepts D<>", () => {
189
+ it('accepts D<>', () => {
190
190
  render(
191
191
  <Podlite>
192
192
  {`
@@ -194,8 +194,8 @@ it("accepts D<>", () => {
194
194
  A D<formatting code|formatting codes;formatters> provides a way
195
195
  to add inline mark-up to a D<piece> of text.
196
196
  `}
197
- </Podlite>
198
- );
197
+ </Podlite>,
198
+ )
199
199
  expect(root.innerHTML).toMatchInlineSnapshot(`
200
200
  <div id="id">
201
201
  <p>
@@ -211,18 +211,18 @@ it("accepts D<>", () => {
211
211
  of text.
212
212
  </p>
213
213
  </div>
214
- `);
215
- });
214
+ `)
215
+ })
216
216
 
217
- it("accepts L<>", () => {
217
+ it('accepts L<>', () => {
218
218
  render(
219
219
  <Podlite>
220
220
  {`
221
221
  L<https://www.python.org/dev/peps/pep-0001/#what-is-a-pep>
222
222
  L<Test|https://example.com>
223
223
  `}
224
- </Podlite>
225
- );
224
+ </Podlite>,
225
+ )
226
226
  expect(root.innerHTML).toMatchInlineSnapshot(`
227
227
  <p>
228
228
  <a href="https://www.python.org/dev/peps/pep-0001/#what-is-a-pep">
@@ -232,10 +232,10 @@ L<Test|https://example.com>
232
232
  Test
233
233
  </a>
234
234
  </p>
235
- `);
236
- });
235
+ `)
236
+ })
237
237
 
238
- it("accepts =comment, Z<>, ", () => {
238
+ it('accepts =comment, Z<>, ', () => {
239
239
  render(
240
240
  <Podlite>
241
241
  {`
@@ -244,17 +244,17 @@ Z<comment>
244
244
  =comment Test
245
245
  =end pod
246
246
  `}
247
- </Podlite>
248
- );
247
+ </Podlite>,
248
+ )
249
249
  expect(root.innerHTML).toMatchInlineSnapshot(`
250
250
  <div id="id">
251
251
  <p>
252
252
  </p>
253
253
  </div>
254
- `);
255
- });
254
+ `)
255
+ })
256
256
 
257
- it("accepts E<>, R<>, V<>", () => {
257
+ it('accepts E<>, R<>, V<>', () => {
258
258
  render(
259
259
  <Podlite>
260
260
  {`
@@ -264,8 +264,8 @@ E<0d171; 0o253; 0b10101011; 0xAB>
264
264
  V<C<boo> B<bar> asd>
265
265
  =end pod
266
266
  `}
267
- </Podlite>
268
- );
267
+ </Podlite>,
268
+ )
269
269
 
270
270
  expect(root.innerHTML).toMatchInlineSnapshot(`
271
271
  <div id="id">
@@ -290,10 +290,10 @@ V<C<boo> B<bar> asd>
290
290
  C&lt;boo&gt; B&lt;bar&gt; asd
291
291
  </p>
292
292
  </div>
293
- `);
294
- });
293
+ `)
294
+ })
295
295
 
296
- it("accepts =output", () => {
296
+ it('accepts =output', () => {
297
297
  render(
298
298
  <Podlite>
299
299
  {`
@@ -305,8 +305,8 @@ Print? B<K<n>>
305
305
  =for input
306
306
  Name: R<your surname>
307
307
  `}
308
- </Podlite>
309
- );
308
+ </Podlite>,
309
+ )
310
310
  expect(root.innerHTML).toMatchInlineSnapshot(`
311
311
  <code>
312
312
  <pre>
@@ -333,10 +333,10 @@ Print? B<K<n>>
333
333
  </var>
334
334
  </kbd>
335
335
  </pre>
336
- `);
337
- });
336
+ `)
337
+ })
338
338
 
339
- it("accepts N<>", () => {
339
+ it('accepts N<>', () => {
340
340
  render(
341
341
  <Podlite>
342
342
  {`
@@ -348,8 +348,8 @@ it("accepts N<>", () => {
348
348
 
349
349
  =end pod
350
350
  `}
351
- </Podlite>
352
- );
351
+ </Podlite>,
352
+ )
353
353
  expect(root.innerHTML).toMatchInlineSnapshot(`
354
354
  <div id="id">
355
355
  <div id="id">
@@ -390,10 +390,10 @@ it("accepts N<>", () => {
390
390
  powerful than its Perl 5 predecessor.
391
391
  </p>
392
392
  </div>
393
- `);
394
- });
393
+ `)
394
+ })
395
395
 
396
- it("accepts U<>, X<>, S<>", () => {
396
+ it('accepts U<>, X<>, S<>', () => {
397
397
  render(
398
398
  <Podlite>
399
399
  {`
@@ -402,8 +402,8 @@ it("accepts U<>, X<>, S<>", () => {
402
402
  U<a>. S<
403
403
  >
404
404
  `}
405
- </Podlite>
406
- );
405
+ </Podlite>,
406
+ )
407
407
 
408
408
  expect(root.innerHTML).toMatchInlineSnapshot(`
409
409
  <div id="id">
@@ -414,13 +414,13 @@ it("accepts U<>, X<>, S<>", () => {
414
414
  </u>
415
415
  .
416
416
  <br>
417
- &nbsp;&nbsp;&nbsp;
417
+    
418
418
  </p>
419
419
  </div>
420
- `);
421
- });
420
+ `)
421
+ })
422
422
 
423
- it("accepts =Image base", () => {
423
+ it('accepts =Image base', () => {
424
424
  render(
425
425
  <Podlite>
426
426
  {`
@@ -429,8 +429,8 @@ it("accepts =Image base", () => {
429
429
  alternative https://www.example.org
430
430
  =end pod
431
431
  `}
432
- </Podlite>
433
- );
432
+ </Podlite>,
433
+ )
434
434
  expect(root.innerHTML).toMatchInlineSnapshot(`
435
435
  <div id="id">
436
436
  <div class="image_block"
@@ -448,10 +448,10 @@ it("accepts =Image base", () => {
448
448
  </div>
449
449
  </div>
450
450
  </div>
451
- `);
452
- });
451
+ `)
452
+ })
453
453
 
454
- it("accepts =Image empty caption", () => {
454
+ it('accepts =Image empty caption', () => {
455
455
  render(
456
456
  <Podlite>
457
457
  {`
@@ -460,8 +460,8 @@ it("accepts =Image empty caption", () => {
460
460
  alternative https://www.example.org
461
461
  =end pod
462
462
  `}
463
- </Podlite>
464
- );
463
+ </Podlite>,
464
+ )
465
465
  // console.log(root.innerHTML);return;
466
466
  expect(root.innerHTML).toMatchInlineSnapshot(`
467
467
  <div id="id">
@@ -477,10 +477,10 @@ it("accepts =Image empty caption", () => {
477
477
  </div>
478
478
  <p>
479
479
  </p>
480
- `);
481
- });
480
+ `)
481
+ })
482
482
 
483
- it("accepts =Image with fullset of attributes", () => {
483
+ it('accepts =Image with fullset of attributes', () => {
484
484
  render(
485
485
  <Podlite>
486
486
  {`
@@ -493,8 +493,8 @@ it("accepts =Image with fullset of attributes", () => {
493
493
  content ignored
494
494
  =end pod
495
495
  `}
496
- </Podlite>
497
- );
496
+ </Podlite>,
497
+ )
498
498
  expect(root.innerHTML).toMatchInlineSnapshot(`
499
499
  <div id="id">
500
500
  <div class="image_block"
@@ -514,9 +514,9 @@ content ignored
514
514
  </div>
515
515
  <p>
516
516
  </p>
517
- `);
518
- });
519
- it("accepts =TITLE", () => {
517
+ `)
518
+ })
519
+ it('accepts =TITLE', () => {
520
520
  render(
521
521
  <Podlite>
522
522
  {`
@@ -524,8 +524,8 @@ it("accepts =TITLE", () => {
524
524
  =TITLE test
525
525
  =para 1
526
526
  =end pod`}
527
- </Podlite>
528
- );
527
+ </Podlite>,
528
+ )
529
529
  expect(root.innerHTML).toMatchInlineSnapshot(`
530
530
  <div id="id">
531
531
  <div>
@@ -542,10 +542,10 @@ it("accepts =TITLE", () => {
542
542
  </p>
543
543
  </div>
544
544
  </div>
545
- `);
546
- });
545
+ `)
546
+ })
547
547
 
548
- it("accepts =defn", () => {
548
+ it('accepts =defn', () => {
549
549
  render(
550
550
  <Podlite>
551
551
  {`
@@ -558,8 +558,8 @@ MORAL
558
558
  Conforming to a local and mutable standard of right.
559
559
  Having the quality of general expediency.
560
560
  `}
561
- </Podlite>
562
- );
561
+ </Podlite>,
562
+ )
563
563
  expect(root.innerHTML).toMatchInlineSnapshot(`
564
564
  <dl>
565
565
  <dt>
@@ -582,10 +582,10 @@ Having the quality of general expediency.
582
582
  Having the quality of general expediency.
583
583
  </dd>
584
584
  </dl>
585
- `);
586
- });
585
+ `)
586
+ })
587
587
 
588
- it("accepts =nested", () => {
588
+ it('accepts =nested', () => {
589
589
  render(
590
590
  <Podlite>
591
591
  {`
@@ -597,8 +597,8 @@ but some of us are looking at the stars!
597
597
  =end nested
598
598
  =end nested
599
599
  `}
600
- </Podlite>
601
- );
600
+ </Podlite>,
601
+ )
602
602
  expect(root.innerHTML).toMatchInlineSnapshot(`
603
603
  <blockquote>
604
604
  <p>
@@ -614,10 +614,10 @@ but some of us are looking at the stars!
614
614
  </p>
615
615
  </blockquote>
616
616
  </blockquote>
617
- `);
618
- });
617
+ `)
618
+ })
619
619
 
620
- it("accepts =Toc", () => {
620
+ it('accepts =Toc', () => {
621
621
  render(
622
622
  <Podlite>
623
623
  {`
@@ -629,8 +629,8 @@ it("accepts =Toc", () => {
629
629
  item1
630
630
  =end pod
631
631
  `}
632
- </Podlite>
633
- );
632
+ </Podlite>,
633
+ )
634
634
  expect(root.innerHTML).toMatchInlineSnapshot(`
635
635
  <div id="id">
636
636
  <div class="toc">
@@ -662,10 +662,23 @@ it("accepts =Toc", () => {
662
662
  </div>
663
663
  <p>
664
664
  </p>
665
- `);
666
- });
665
+ `)
666
+ })
667
+
668
+ it('id for headers', () => {
669
+ render(
670
+ <PodliteRaw>{`
671
+ =head1 Test
672
+ `}</PodliteRaw>,
673
+ )
674
+ expect(root.innerHTML).toMatchInlineSnapshot(`
675
+ <h1 id="Test">
676
+ Test
677
+ </h1>
678
+ `)
679
+ })
667
680
 
668
- it.skip("accepts =Diagram", () => {
681
+ it.skip('accepts =Diagram', () => {
669
682
  render(
670
683
  <Podlite>
671
684
  {`
@@ -677,13 +690,13 @@ B-->C[fa:fa-ban forbidden]
677
690
  B-->D(fa:fa-spinner aaaaa);
678
691
  =end pod
679
692
  `}
680
- </Podlite>
681
- );
682
- console.log(root.innerHTML);
693
+ </Podlite>,
694
+ )
695
+ console.log(root.innerHTML)
683
696
  // expect(root.innerHTML).toMatchInlineSnapshot();
684
- });
697
+ })
685
698
 
686
- it.skip("accepts =alias", () => {
699
+ it.skip('accepts =alias', () => {
687
700
  render(
688
701
  <Podlite>
689
702
  {`
@@ -700,8 +713,8 @@ A<TERMS_URLS>
700
713
 
701
714
  =end pod
702
715
  `}
703
- </Podlite>
704
- );
705
- console.log(root.innerHTML);
716
+ </Podlite>,
717
+ )
718
+ console.log(root.innerHTML)
706
719
  // expect(root.innerHTML).toMatchInlineSnapshot();
707
- });
720
+ })
package/tsconfig.json CHANGED
@@ -11,8 +11,10 @@
11
11
  "jsx": "react",
12
12
 
13
13
  "compilerOptions": {
14
- "target": "es2017",
15
- "module": "commonjs",
14
+ // "target": "es2017",
15
+ // "module": "commonjs",
16
+ "module": "esnext",
17
+ "target": "ESNext",
16
18
  "moduleResolution": "node",
17
19
  "sourceMap": true,
18
20
  "jsx": "react",
@@ -22,6 +24,8 @@
22
24
  "downlevelIteration": true,
23
25
  "declaration": true,
24
26
  "incremental": true,
27
+ "esModuleInterop":true,
28
+ "composite": true
25
29
  },
26
30
  "references": [
27
31
  {