@podlite/markdown 0.0.15 → 0.0.16

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podlite/markdown",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "=markdown - markdown text block",
5
5
  "main": "./lib/index.cjs",
6
6
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  "markup-language"
29
29
  ],
30
30
  "dependencies": {
31
- "@podlite/schema": "0.0.22",
31
+ "@podlite/schema": "0.0.23",
32
32
  "react": "^16.0.0 || ^17.0.0 ",
33
33
  "react-dom": "^16.0.0 || ^17.0.0",
34
34
  "react-is": "^17.0.0",
package/src/tools.ts CHANGED
@@ -180,12 +180,19 @@ export const md2ast = (src: string, { lineOffset }: Md2astArgs = { lineOffset: 0
180
180
  },
181
181
  //table section
182
182
  ':table': (writer, processor) => (node, ctx, interator) => {
183
- const { children, position, ...attr } = node
184
- return mkBlock({ name: 'table', location: applyLineOffset(position) }, interator(children, { ...ctx }))
183
+ const { children, position, align, ...attr } = node
184
+ return mkBlock(
185
+ { name: 'table', location: applyLineOffset(position), align },
186
+ interator(children, { ...ctx, isHeaderUsed: 0 }),
187
+ )
185
188
  },
186
189
  ':tableRow': (writer, processor) => (node, ctx, interator) => {
187
190
  const { children, position, ...attr } = node
188
- return mkBlock({ name: 'table_row', location: applyLineOffset(position) }, interator(children, { ...ctx }))
191
+ const isHeaderUsed = ctx.isHeaderUsed++
192
+ return mkBlock(
193
+ { name: isHeaderUsed ? 'table_row' : 'table_head', location: applyLineOffset(position) },
194
+ interator(children, { ...ctx }),
195
+ )
189
196
  },
190
197
  ':tableCell': (writer, processor) => (node, ctx, interator) => {
191
198
  const { children, position, ...attr } = node
package/t/parse.test.ts CHANGED
@@ -880,6 +880,10 @@ Content in the first column | Content in the second column
880
880
  Object {
881
881
  "content": Array [
882
882
  Object {
883
+ "align": Array [
884
+ null,
885
+ null,
886
+ ],
883
887
  "content": Array [
884
888
  Object {
885
889
  "content": Array [
@@ -940,7 +944,7 @@ Content in the first column | Content in the second column
940
944
  },
941
945
  },
942
946
  "margin": "",
943
- "name": "table_row",
947
+ "name": "table_head",
944
948
  "type": "block",
945
949
  },
946
950
  Object {
@@ -1094,6 +1098,553 @@ Content in the first column | Content in the second column
1094
1098
  `)
1095
1099
  })
1096
1100
 
1101
+ it('[markdown]: parse table with empty header', () => {
1102
+ const pod = `
1103
+ | | |
1104
+ ------------ | -------------
1105
+ Content from cell 1 | Content from cell 2
1106
+ Content in the first column | Content in the second column
1107
+ `
1108
+ const tree = process(pod)
1109
+ const r = validateAstTree([tree])
1110
+ expect(r).toEqual([])
1111
+ const errorDescribe = isValidateError(r, tree)
1112
+ expect(process(pod)).toMatchInlineSnapshot(`
1113
+ Object {
1114
+ "content": Array [
1115
+ Object {
1116
+ "align": Array [
1117
+ null,
1118
+ null,
1119
+ ],
1120
+ "content": Array [
1121
+ Object {
1122
+ "content": Array [
1123
+ Object {
1124
+ "content": Array [],
1125
+ "id": "id",
1126
+ "location": Object {
1127
+ "end": Object {
1128
+ "column": 6,
1129
+ "line": 2,
1130
+ "offset": 6,
1131
+ },
1132
+ "start": Object {
1133
+ "column": 3,
1134
+ "line": 2,
1135
+ "offset": 3,
1136
+ },
1137
+ },
1138
+ "margin": "",
1139
+ "name": "table_cell",
1140
+ "type": "block",
1141
+ },
1142
+ Object {
1143
+ "content": Array [],
1144
+ "id": "id",
1145
+ "location": Object {
1146
+ "end": Object {
1147
+ "column": 8,
1148
+ "line": 2,
1149
+ "offset": 8,
1150
+ },
1151
+ "start": Object {
1152
+ "column": 6,
1153
+ "line": 2,
1154
+ "offset": 6,
1155
+ },
1156
+ },
1157
+ "margin": "",
1158
+ "name": "table_cell",
1159
+ "type": "block",
1160
+ },
1161
+ ],
1162
+ "id": "id",
1163
+ "location": Object {
1164
+ "end": Object {
1165
+ "column": 8,
1166
+ "line": 2,
1167
+ "offset": 8,
1168
+ },
1169
+ "start": Object {
1170
+ "column": 3,
1171
+ "line": 2,
1172
+ "offset": 3,
1173
+ },
1174
+ },
1175
+ "margin": "",
1176
+ "name": "table_head",
1177
+ "type": "block",
1178
+ },
1179
+ Object {
1180
+ "content": Array [
1181
+ Object {
1182
+ "content": Array [
1183
+ "Content from cell 1",
1184
+ ],
1185
+ "id": "id",
1186
+ "location": Object {
1187
+ "end": Object {
1188
+ "column": 24,
1189
+ "line": 4,
1190
+ "offset": 63,
1191
+ },
1192
+ "start": Object {
1193
+ "column": 3,
1194
+ "line": 4,
1195
+ "offset": 42,
1196
+ },
1197
+ },
1198
+ "margin": "",
1199
+ "name": "table_cell",
1200
+ "type": "block",
1201
+ },
1202
+ Object {
1203
+ "content": Array [
1204
+ "Content from cell 2",
1205
+ ],
1206
+ "id": "id",
1207
+ "location": Object {
1208
+ "end": Object {
1209
+ "column": 44,
1210
+ "line": 4,
1211
+ "offset": 83,
1212
+ },
1213
+ "start": Object {
1214
+ "column": 24,
1215
+ "line": 4,
1216
+ "offset": 63,
1217
+ },
1218
+ },
1219
+ "margin": "",
1220
+ "name": "table_cell",
1221
+ "type": "block",
1222
+ },
1223
+ ],
1224
+ "id": "id",
1225
+ "location": Object {
1226
+ "end": Object {
1227
+ "column": 44,
1228
+ "line": 4,
1229
+ "offset": 83,
1230
+ },
1231
+ "start": Object {
1232
+ "column": 3,
1233
+ "line": 4,
1234
+ "offset": 42,
1235
+ },
1236
+ },
1237
+ "margin": "",
1238
+ "name": "table_row",
1239
+ "type": "block",
1240
+ },
1241
+ Object {
1242
+ "content": Array [
1243
+ Object {
1244
+ "content": Array [
1245
+ "Content in the first column",
1246
+ ],
1247
+ "id": "id",
1248
+ "location": Object {
1249
+ "end": Object {
1250
+ "column": 32,
1251
+ "line": 5,
1252
+ "offset": 115,
1253
+ },
1254
+ "start": Object {
1255
+ "column": 3,
1256
+ "line": 5,
1257
+ "offset": 86,
1258
+ },
1259
+ },
1260
+ "margin": "",
1261
+ "name": "table_cell",
1262
+ "type": "block",
1263
+ },
1264
+ Object {
1265
+ "content": Array [
1266
+ "Content in the second column",
1267
+ ],
1268
+ "id": "id",
1269
+ "location": Object {
1270
+ "end": Object {
1271
+ "column": 61,
1272
+ "line": 5,
1273
+ "offset": 144,
1274
+ },
1275
+ "start": Object {
1276
+ "column": 32,
1277
+ "line": 5,
1278
+ "offset": 115,
1279
+ },
1280
+ },
1281
+ "margin": "",
1282
+ "name": "table_cell",
1283
+ "type": "block",
1284
+ },
1285
+ ],
1286
+ "id": "id",
1287
+ "location": Object {
1288
+ "end": Object {
1289
+ "column": 61,
1290
+ "line": 5,
1291
+ "offset": 144,
1292
+ },
1293
+ "start": Object {
1294
+ "column": 3,
1295
+ "line": 5,
1296
+ "offset": 86,
1297
+ },
1298
+ },
1299
+ "margin": "",
1300
+ "name": "table_row",
1301
+ "type": "block",
1302
+ },
1303
+ ],
1304
+ "id": "id",
1305
+ "location": Object {
1306
+ "end": Object {
1307
+ "column": 61,
1308
+ "line": 5,
1309
+ "offset": 144,
1310
+ },
1311
+ "start": Object {
1312
+ "column": 3,
1313
+ "line": 2,
1314
+ "offset": 3,
1315
+ },
1316
+ },
1317
+ "margin": "",
1318
+ "name": "table",
1319
+ "type": "block",
1320
+ },
1321
+ ],
1322
+ "id": "id",
1323
+ "margin": "",
1324
+ "name": "root",
1325
+ "type": "block",
1326
+ }
1327
+ `)
1328
+ })
1329
+
1330
+ it('[markdown]: parse table with align', () => {
1331
+ const pod = `
1332
+ =markdown
1333
+ Left | Centered | Right
1334
+ :----------- | :--------------: | -------------------------:
1335
+ This is left | Text is centered | And this is right-aligned
1336
+ More text | Even more text | And even more to the right
1337
+ `
1338
+ const tree = process(pod)
1339
+ const r = validateAstTree([tree])
1340
+ expect(r).toEqual([])
1341
+ const errorDescribe = isValidateError(r, tree)
1342
+ expect(process(pod)).toMatchInlineSnapshot(`
1343
+ Object {
1344
+ "content": Array [
1345
+ Object {
1346
+ "content": Array [
1347
+ "=markdown",
1348
+ ],
1349
+ "id": "id",
1350
+ "location": Object {
1351
+ "end": Object {
1352
+ "column": 10,
1353
+ "line": 2,
1354
+ "offset": 10,
1355
+ },
1356
+ "start": Object {
1357
+ "column": 1,
1358
+ "line": 2,
1359
+ "offset": 1,
1360
+ },
1361
+ },
1362
+ "margin": "",
1363
+ "text": "text",
1364
+ "type": "para",
1365
+ },
1366
+ Object {
1367
+ "align": Array [
1368
+ "left",
1369
+ "center",
1370
+ "right",
1371
+ ],
1372
+ "content": Array [
1373
+ Object {
1374
+ "content": Array [
1375
+ Object {
1376
+ "content": Array [
1377
+ "Left",
1378
+ ],
1379
+ "id": "id",
1380
+ "location": Object {
1381
+ "end": Object {
1382
+ "column": 15,
1383
+ "line": 3,
1384
+ "offset": 25,
1385
+ },
1386
+ "start": Object {
1387
+ "column": 1,
1388
+ "line": 3,
1389
+ "offset": 11,
1390
+ },
1391
+ },
1392
+ "margin": "",
1393
+ "name": "table_cell",
1394
+ "type": "block",
1395
+ },
1396
+ Object {
1397
+ "content": Array [
1398
+ "Centered",
1399
+ ],
1400
+ "id": "id",
1401
+ "location": Object {
1402
+ "end": Object {
1403
+ "column": 34,
1404
+ "line": 3,
1405
+ "offset": 44,
1406
+ },
1407
+ "start": Object {
1408
+ "column": 15,
1409
+ "line": 3,
1410
+ "offset": 25,
1411
+ },
1412
+ },
1413
+ "margin": "",
1414
+ "name": "table_cell",
1415
+ "type": "block",
1416
+ },
1417
+ Object {
1418
+ "content": Array [
1419
+ "Right",
1420
+ ],
1421
+ "id": "id",
1422
+ "location": Object {
1423
+ "end": Object {
1424
+ "column": 40,
1425
+ "line": 3,
1426
+ "offset": 50,
1427
+ },
1428
+ "start": Object {
1429
+ "column": 34,
1430
+ "line": 3,
1431
+ "offset": 44,
1432
+ },
1433
+ },
1434
+ "margin": "",
1435
+ "name": "table_cell",
1436
+ "type": "block",
1437
+ },
1438
+ ],
1439
+ "id": "id",
1440
+ "location": Object {
1441
+ "end": Object {
1442
+ "column": 40,
1443
+ "line": 3,
1444
+ "offset": 50,
1445
+ },
1446
+ "start": Object {
1447
+ "column": 1,
1448
+ "line": 3,
1449
+ "offset": 11,
1450
+ },
1451
+ },
1452
+ "margin": "",
1453
+ "name": "table_head",
1454
+ "type": "block",
1455
+ },
1456
+ Object {
1457
+ "content": Array [
1458
+ Object {
1459
+ "content": Array [
1460
+ "This is left",
1461
+ ],
1462
+ "id": "id",
1463
+ "location": Object {
1464
+ "end": Object {
1465
+ "column": 15,
1466
+ "line": 5,
1467
+ "offset": 126,
1468
+ },
1469
+ "start": Object {
1470
+ "column": 1,
1471
+ "line": 5,
1472
+ "offset": 112,
1473
+ },
1474
+ },
1475
+ "margin": "",
1476
+ "name": "table_cell",
1477
+ "type": "block",
1478
+ },
1479
+ Object {
1480
+ "content": Array [
1481
+ "Text is centered",
1482
+ ],
1483
+ "id": "id",
1484
+ "location": Object {
1485
+ "end": Object {
1486
+ "column": 34,
1487
+ "line": 5,
1488
+ "offset": 145,
1489
+ },
1490
+ "start": Object {
1491
+ "column": 15,
1492
+ "line": 5,
1493
+ "offset": 126,
1494
+ },
1495
+ },
1496
+ "margin": "",
1497
+ "name": "table_cell",
1498
+ "type": "block",
1499
+ },
1500
+ Object {
1501
+ "content": Array [
1502
+ "And this is right-aligned",
1503
+ ],
1504
+ "id": "id",
1505
+ "location": Object {
1506
+ "end": Object {
1507
+ "column": 60,
1508
+ "line": 5,
1509
+ "offset": 171,
1510
+ },
1511
+ "start": Object {
1512
+ "column": 34,
1513
+ "line": 5,
1514
+ "offset": 145,
1515
+ },
1516
+ },
1517
+ "margin": "",
1518
+ "name": "table_cell",
1519
+ "type": "block",
1520
+ },
1521
+ ],
1522
+ "id": "id",
1523
+ "location": Object {
1524
+ "end": Object {
1525
+ "column": 60,
1526
+ "line": 5,
1527
+ "offset": 171,
1528
+ },
1529
+ "start": Object {
1530
+ "column": 1,
1531
+ "line": 5,
1532
+ "offset": 112,
1533
+ },
1534
+ },
1535
+ "margin": "",
1536
+ "name": "table_row",
1537
+ "type": "block",
1538
+ },
1539
+ Object {
1540
+ "content": Array [
1541
+ Object {
1542
+ "content": Array [
1543
+ "More text",
1544
+ ],
1545
+ "id": "id",
1546
+ "location": Object {
1547
+ "end": Object {
1548
+ "column": 15,
1549
+ "line": 6,
1550
+ "offset": 186,
1551
+ },
1552
+ "start": Object {
1553
+ "column": 1,
1554
+ "line": 6,
1555
+ "offset": 172,
1556
+ },
1557
+ },
1558
+ "margin": "",
1559
+ "name": "table_cell",
1560
+ "type": "block",
1561
+ },
1562
+ Object {
1563
+ "content": Array [
1564
+ "Even more text",
1565
+ ],
1566
+ "id": "id",
1567
+ "location": Object {
1568
+ "end": Object {
1569
+ "column": 34,
1570
+ "line": 6,
1571
+ "offset": 205,
1572
+ },
1573
+ "start": Object {
1574
+ "column": 15,
1575
+ "line": 6,
1576
+ "offset": 186,
1577
+ },
1578
+ },
1579
+ "margin": "",
1580
+ "name": "table_cell",
1581
+ "type": "block",
1582
+ },
1583
+ Object {
1584
+ "content": Array [
1585
+ "And even more to the right",
1586
+ ],
1587
+ "id": "id",
1588
+ "location": Object {
1589
+ "end": Object {
1590
+ "column": 61,
1591
+ "line": 6,
1592
+ "offset": 232,
1593
+ },
1594
+ "start": Object {
1595
+ "column": 34,
1596
+ "line": 6,
1597
+ "offset": 205,
1598
+ },
1599
+ },
1600
+ "margin": "",
1601
+ "name": "table_cell",
1602
+ "type": "block",
1603
+ },
1604
+ ],
1605
+ "id": "id",
1606
+ "location": Object {
1607
+ "end": Object {
1608
+ "column": 61,
1609
+ "line": 6,
1610
+ "offset": 232,
1611
+ },
1612
+ "start": Object {
1613
+ "column": 1,
1614
+ "line": 6,
1615
+ "offset": 172,
1616
+ },
1617
+ },
1618
+ "margin": "",
1619
+ "name": "table_row",
1620
+ "type": "block",
1621
+ },
1622
+ ],
1623
+ "id": "id",
1624
+ "location": Object {
1625
+ "end": Object {
1626
+ "column": 61,
1627
+ "line": 6,
1628
+ "offset": 232,
1629
+ },
1630
+ "start": Object {
1631
+ "column": 1,
1632
+ "line": 3,
1633
+ "offset": 11,
1634
+ },
1635
+ },
1636
+ "margin": "",
1637
+ "name": "table",
1638
+ "type": "block",
1639
+ },
1640
+ ],
1641
+ "id": "id",
1642
+ "margin": "",
1643
+ "name": "root",
1644
+ "type": "block",
1645
+ }
1646
+ `)
1647
+ })
1097
1648
  it('[markdown]: parse strikethrough', () => {
1098
1649
  const pod = `
1099
1650
  ~~this~~
package/t/plugin.test.tsx CHANGED
@@ -200,27 +200,27 @@ it('=markdown: table render', () => {
200
200
  <caption class="caption">
201
201
  </caption>
202
202
  <tbody>
203
- <tr id="id">
204
- <td id="id">
203
+ <tr>
204
+ <th>
205
205
  Syntax
206
- </td>
207
- <td id="id">
206
+ </th>
207
+ <th>
208
208
  Description
209
- </td>
209
+ </th>
210
210
  </tr>
211
- <tr id="id">
212
- <td id="id">
211
+ <tr>
212
+ <td>
213
213
  Header
214
214
  </td>
215
- <td id="id">
215
+ <td>
216
216
  Title
217
217
  </td>
218
218
  </tr>
219
- <tr id="id">
220
- <td id="id">
219
+ <tr>
220
+ <td>
221
221
  Paragraph
222
222
  </td>
223
- <td id="id">
223
+ <td>
224
224
  Text
225
225
  </td>
226
226
  </tr>