liepress 0.1.2

A Markdown to PDF/SVG/PNG converter with CSS styling support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
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
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
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
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
# LiePress ๆžถๆž„้‡ๆž„่ฎพ่ฎกๆ–นๆกˆ


## HTML ๅญ้›† + Lightning CSS ๆ ทๅผๅขžๅผบ


---

## ็›ฎๅฝ•


1. [ๆžถๆž„ๆ€ป่งˆ]#1-ๆžถๆž„ๆ€ป่งˆ
2. [HTML ๅญ้›†ๅฎšไน‰]#2-html-ๅญ้›†ๅฎšไน‰
3. [ๆจกๅ—่ฎพ่ฎก]#3-ๆจกๅ—่ฎพ่ฎก
4. [CSS ๆ ทๅผ็ณป็ปŸ]#4-css-ๆ ทๅผ็ณป็ปŸ
5. [ๆ•ฐๆฎๆตไธŽๅค„็†ๆต็จ‹]#5-ๆ•ฐๆฎๆตไธŽๅค„็†ๆต็จ‹
6. [ๅฎž็Žฐ่ง„ๅˆ’]#6-ๅฎž็Žฐ่ง„ๅˆ’

---

## 1. ๆžถๆž„ๆ€ป่งˆ


### 1.1 ๆ–ฐๆ—งๆžถๆž„ๅฏนๆฏ”


```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                              ๅฝ“ๅ‰ๆžถๆž„                                        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚  Markdown โ”€โ”€โ–ถ MDAST โ”€โ”€โ–ถ Styled AST โ”€โ”€โ–ถ Document โ”€โ”€โ–ถ PDF/SVG/PNG            โ”‚
โ”‚              (markdown)   (่‡ชๅฎšไน‰)      (generator)     (render)            โ”‚
โ”‚                                                                             โ”‚
โ”‚  ้—ฎ้ข˜๏ผš                                                                      โ”‚
โ”‚  - HTML ๆ ‡็ญพๅค„็†่–„ๅผฑ๏ผˆไป…ๆๅ– <style>๏ผ‰                                        โ”‚
โ”‚  - CSS ่งฃๆžๅ™จๅŠŸ่ƒฝๆœ‰้™๏ผˆๅŸบ็ก€้€‰ๆ‹ฉๅ™จ๏ผ‰                                           โ”‚
โ”‚  - ๆ ทๅผ็ณป็ปŸไธŽ HTML ๆ ‡ๅ‡†่„ฑ่Š‚                                                   โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                              ๆ–ฐๆžถๆž„                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Markdown โ”‚โ”€โ”€โ–ถโ”‚   HTML   โ”‚โ”€โ”€โ–ถโ”‚  Styled  โ”‚โ”€โ”€โ–ถโ”‚ Document โ”‚โ”€โ”€โ–ถโ”‚  Output  โ”‚  โ”‚
โ”‚  โ”‚  Source  โ”‚   โ”‚   AST    โ”‚   โ”‚   HTML   โ”‚   โ”‚  Layout  โ”‚   โ”‚ PDF/...  โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚       โ”‚              โ”‚               โ”‚              โ”‚                       โ”‚
โ”‚       โ–ผ              โ–ผ               โ–ผ              โ–ผ                       โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                  โ”‚
โ”‚  โ”‚ markdown โ”‚   โ”‚  html    โ”‚   โ”‚   css    โ”‚   โ”‚ generatorโ”‚                  โ”‚
โ”‚  โ”‚  crate   โ”‚   โ”‚  parser  โ”‚   โ”‚ (lightningโ”‚   โ”‚  module  โ”‚                  โ”‚
โ”‚  โ”‚          โ”‚   โ”‚  module  โ”‚   โ”‚   css)   โ”‚   โ”‚          โ”‚                  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                  โ”‚
โ”‚                                                                             โ”‚
โ”‚  ไผ˜ๅŠฟ๏ผš                                                                      โ”‚
โ”‚  - ๆ˜Ž็กฎ็š„ HTML ๅญ้›†ๆ”ฏๆŒ                                                       โ”‚
โ”‚  - ๆต่งˆๅ™จ็บง CSS ่งฃๆž๏ผˆLightning CSS๏ผ‰                                         โ”‚
โ”‚  - ๆ ‡ๅ‡† HTML + CSS ๅค„็†ๆต็จ‹                                                   โ”‚
โ”‚  - ๆ›ดๅฅฝ็š„ๅฏ็ปดๆŠคๆ€งๅ’Œๆ‰ฉๅฑ•ๆ€ง                                                     โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### 1.2 ๆจกๅ—ไพ่ต–ๅ…ณ็ณป


```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         ๆจกๅ—ไพ่ต–ๅ›พ                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                 โ”‚
โ”‚                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                             โ”‚
โ”‚                         โ”‚  lib.rs โ”‚  (ๅ…ฌๅ…ฑ API)                  โ”‚
โ”‚                         โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜                             โ”‚
โ”‚                              โ”‚                                  โ”‚
โ”‚        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚        โ”‚                     โ”‚                     โ”‚            โ”‚
โ”‚        โ–ผ                     โ–ผ                     โ–ผ            โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚   โ”‚  html   โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚   css   โ”‚           โ”‚ render  โ”‚        โ”‚
โ”‚   โ”‚ module  โ”‚          โ”‚ module  โ”‚           โ”‚ module  โ”‚        โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜          โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜           โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜        โ”‚
โ”‚        โ”‚                     โ”‚                     โ”‚            โ”‚
โ”‚        โ”‚              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”‚            โ”‚
โ”‚        โ”‚              โ”‚             โ”‚              โ”‚            โ”‚
โ”‚        โ”‚              โ–ผ             โ–ผ              โ”‚            โ”‚
โ”‚        โ”‚        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”‚            โ”‚
โ”‚        โ”‚        โ”‚lightningโ”‚   โ”‚ adapter โ”‚         โ”‚            โ”‚
โ”‚        โ”‚        โ”‚  css    โ”‚   โ”‚  layer  โ”‚         โ”‚            โ”‚
โ”‚        โ”‚        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚            โ”‚
โ”‚        โ”‚                                           โ”‚            โ”‚
โ”‚        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                           โ”‚                                     โ”‚
โ”‚                           โ–ผ                                     โ”‚
โ”‚                      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                โ”‚
โ”‚                      โ”‚generatorโ”‚                                โ”‚
โ”‚                      โ”‚ module  โ”‚                                โ”‚
โ”‚                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                โ”‚
โ”‚                                                                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

---

## 2. HTML ๅญ้›†ๅฎšไน‰


### 2.1 ๆ”ฏๆŒ็š„ HTML ๆ ‡็ญพๆธ…ๅ•


#### 2.1.1 ๆ–‡ๆกฃ็ป“ๆž„


| ๆ ‡็ญพ | ็ฑปๅž‹ | ๅฑžๆ€งๆ”ฏๆŒ | ่ฏดๆ˜Ž |
|------|------|---------|------|
| `<div>` | ๅ—็บง | `style`, `class`, `id` | ้€š็”จๅฎนๅ™จ |
| `<span>` | ่กŒๅ†… | `style`, `class`, `id` | ่กŒๅ†…ๅฎนๅ™จ |
| `<center>` | ๅ—็บง | `style`, `class` | ๅฑ…ไธญๅฎนๅ™จ๏ผˆๅ…ผๅฎนๆ—งๆ–‡ๆกฃ๏ผ‰ |

#### 2.1.2 ๆ ‡้ข˜


| ๆ ‡็ญพ | ็ฑปๅž‹ | ๅฑžๆ€งๆ”ฏๆŒ | ่ฏดๆ˜Ž |
|------|------|---------|------|
| `<h1>` - `<h6>` | ๅ—็บง | `style`, `class`, `id` | ๆ ‡้ข˜๏ผŒ1-6 ็บง |

#### 2.1.3 ๆฎต่ฝไธŽๆ–‡ๆœฌ


| ๆ ‡็ญพ | ็ฑปๅž‹ | ๅฑžๆ€งๆ”ฏๆŒ | ่ฏดๆ˜Ž |
|------|------|---------|------|
| `<p>` | ๅ—็บง | `style`, `class`, `id` | ๆฎต่ฝ |
| `<br/>` | ็ฉบ่กŒๅ†… | - | ๅผบๅˆถๆข่กŒ |
| ๆ–‡ๆœฌ่Š‚็‚น | - | - | ็บฏๆ–‡ๆœฌๅ†…ๅฎน |

#### 2.1.4 ๆ–‡ๆœฌๆ ทๅผ๏ผˆๅ†…่”๏ผ‰


| ๆ ‡็ญพ | ็ฑปๅž‹ | ๅฑžๆ€งๆ”ฏๆŒ | ่ฏดๆ˜Ž |
|------|------|---------|------|
| `<strong>`, `<b>` | ่กŒๅ†… | `style`, `class` | ๅŠ ็ฒ— |
| `<em>`, `<i>` | ่กŒๅ†… | `style`, `class` | ๆ–œไฝ“ |
| `<u>` | ่กŒๅ†… | `style`, `class` | ไธ‹ๅˆ’็บฟ |
| `<del>`, `<s>` | ่กŒๅ†… | `style`, `class` | ๅˆ ้™ค็บฟ |
| `<mark>` | ่กŒๅ†… | `style`, `class` | ้ซ˜ไบฎๆ ‡่ฎฐ |
| `<kbd>` | ่กŒๅ†… | `style`, `class` | ้”ฎ็›˜ๆŒ‰้”ฎ |
| `<sup>` | ่กŒๅ†… | `style`, `class` | ไธŠๆ ‡ |
| `<sub>` | ่กŒๅ†… | `style`, `class` | ไธ‹ๆ ‡ |

#### 2.1.5 ้“พๆŽฅไธŽๅ›พ็‰‡


| ๆ ‡็ญพ | ็ฑปๅž‹ | ๅฑžๆ€งๆ”ฏๆŒ | ่ฏดๆ˜Ž |
|------|------|---------|------|
| `<a>` | ่กŒๅ†… | `href`, `title`, `style`, `class` | ่ถ…้“พๆŽฅ |
| `<img>` | ็ฉบ่กŒๅ†… | `src`, `alt`, `title`, `width`, `height`, `style`, `class` | ๅ›พ็‰‡ |

#### 2.1.6 ๅˆ—่กจ


| ๆ ‡็ญพ | ็ฑปๅž‹ | ๅฑžๆ€งๆ”ฏๆŒ | ่ฏดๆ˜Ž |
|------|------|---------|------|
| `<ul>` | ๅ—็บง | `style`, `class` | ๆ— ๅบๅˆ—่กจ |
| `<ol>` | ๅ—็บง | `start`, `style`, `class` | ๆœ‰ๅบๅˆ—่กจ |
| `<li>` | ๅ—็บง | `style`, `class` | ๅˆ—่กจ้กน |

#### 2.1.7 ไปฃ็ 


| ๆ ‡็ญพ | ็ฑปๅž‹ | ๅฑžๆ€งๆ”ฏๆŒ | ่ฏดๆ˜Ž |
|------|------|---------|------|
| `<pre>` + `<code>` | ๅ—็บง | `class` (่ฏญ่จ€) | ไปฃ็ ๅ— |
| `<code>` | ่กŒๅ†… | `style`, `class` | ่กŒๅ†…ไปฃ็  |

#### 2.1.8 ๅ…ถไป–ๅ—็บงๅ…ƒ็ด 


| ๆ ‡็ญพ | ็ฑปๅž‹ | ๅฑžๆ€งๆ”ฏๆŒ | ่ฏดๆ˜Ž |
|------|------|---------|------|
| `<blockquote>` | ๅ—็บง | `style`, `class`, `id` | ๅผ•็”จๅ— |
| `<hr/>` | ็ฉบๅ—็บง | `style`, `class` | ๆฐดๅนณๅˆ†้š”็บฟ |

#### 2.1.9 ่กจๆ ผ


| ๆ ‡็ญพ | ็ฑปๅž‹ | ๅฑžๆ€งๆ”ฏๆŒ | ่ฏดๆ˜Ž |
|------|------|---------|------|
| `<table>` | ๅ—็บง | `style`, `class` | ่กจๆ ผ |
| `<thead>` | ๅ—็บง | `style`, `class` | ่กจๅคดๅŒบๅŸŸ |
| `<tbody>` | ๅ—็บง | `style`, `class` | ่กจไฝ“ๅŒบๅŸŸ |
| `<tr>` | ๅ—็บง | `style`, `class` | ่กจๆ ผ่กŒ |
| `<th>` | ๅ—็บง | `style`, `class`, `colspan`, `rowspan` | ่กจๅคดๅ•ๅ…ƒๆ ผ |
| `<td>` | ๅ—็บง | `style`, `class`, `colspan`, `rowspan` | ๆ•ฐๆฎๅ•ๅ…ƒๆ ผ |

### 2.2 ไธๆ”ฏๆŒ็š„ HTML ๆ ‡็ญพ


| ็ฑปๅˆซ | ๆ ‡็ญพ | ๅŽŸๅ›  |
|------|------|------|
| ่กจๅ• | `<form>`, `<input>`, `<button>` ็ญ‰ | PDF ้žไบคไบ’ๅผๆ–‡ๆกฃ |
| ๅคšๅช’ไฝ“ | `<video>`, `<audio>`, `<canvas>` | ้œ€่ฆๅคๆ‚ๆธฒๆŸ“ๆ”ฏๆŒ |
| ๆก†ๆžถ | `<iframe>`, `<frame>`, `<frameset>` | ๅฎ‰ๅ…จๆ€งๅ’Œๅคๆ‚ๆ€ง |
| ่„šๆœฌ | `<script>`, `<noscript>` | PDF ไธๆ”ฏๆŒ่„šๆœฌ |
| ๅ…ƒๆ•ฐๆฎ | `<meta>`, `<link>` (้™คๆ ทๅผ) | ๆ— ๆ„ไน‰ |
| ๅคๆ‚ๅธƒๅฑ€ | `<article>`, `<section>`, `<aside>` ็ญ‰่ฏญไน‰ๆ ‡็ญพ | ๅฏ็”จ `<div>` ๆ›ฟไปฃ |

### 2.3 HTML AST ๅฎšไน‰


```rust
// src/html/ast.rs

use std::collections::HashMap;

/// HTML ๆ–‡ๆกฃ
#[derive(Debug, Clone)]

pub struct HtmlDocument {
    pub root: HtmlElement,
    /// ไปŽ <style> ๆ ‡็ญพๆๅ–็š„ๆ ทๅผ่กจ
    pub style_sheets: Vec<String>,
}

/// HTML ๅ…ƒ็ด 
#[derive(Debug, Clone)]

pub struct HtmlElement {
    pub tag: HtmlTag,
    pub attrs: HashMap<String, String>,
    pub children: Vec<HtmlNode>,
}

/// HTML ่Š‚็‚น๏ผˆๅ…ƒ็ด ๆˆ–ๆ–‡ๆœฌ๏ผ‰
#[derive(Debug, Clone)]

pub enum HtmlNode {
    Element(HtmlElement),
    Text(String),
}

/// HTML ๆ ‡็ญพๆžšไธพ
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

pub enum HtmlTag {
    // ๆ–‡ๆกฃ็ป“ๆž„
    Div,
    Span,
    Center,
    
    // ๆ ‡้ข˜
    H1, H2, H3, H4, H5, H6,
    
    // ๆฎต่ฝ
    P,
    Br,
    
    // ๆ–‡ๆœฌๆ ทๅผ
    Strong, B,
    Em, I,
    U,
    Del, S,
    Mark,
    Kbd,
    Sup,
    Sub,
    
    // ้“พๆŽฅไธŽๅ›พ็‰‡
    A,
    Img,
    
    // ๅˆ—่กจ
    Ul, Ol, Li,
    
    // ไปฃ็ 
    Pre, Code,
    
    // ๅ…ถไป–ๅ—็บง
    Blockquote,
    Hr,
    
    // ่กจๆ ผ
    Table, Thead, Tbody, Tr, Th, Td,
}

impl HtmlTag {
    /// ่Žทๅ–ๆ ‡็ญพๅญ—็ฌฆไธฒ่กจ็คบ
    pub fn as_str(&self) -> &'static str {
        match self {
            HtmlTag::Div => "div",
            HtmlTag::Span => "span",
            HtmlTag::Center => "center",
            HtmlTag::H1 => "h1",
            HtmlTag::H2 => "h2",
            HtmlTag::H3 => "h3",
            HtmlTag::H4 => "h4",
            HtmlTag::H5 => "h5",
            HtmlTag::H6 => "h6",
            HtmlTag::P => "p",
            HtmlTag::Br => "br",
            HtmlTag::Strong => "strong",
            HtmlTag::B => "b",
            HtmlTag::Em => "em",
            HtmlTag::I => "i",
            HtmlTag::U => "u",
            HtmlTag::Del => "del",
            HtmlTag::S => "s",
            HtmlTag::Mark => "mark",
            HtmlTag::Kbd => "kbd",
            HtmlTag::Sup => "sup",
            HtmlTag::Sub => "sub",
            HtmlTag::A => "a",
            HtmlTag::Img => "img",
            HtmlTag::Ul => "ul",
            HtmlTag::Ol => "ol",
            HtmlTag::Li => "li",
            HtmlTag::Pre => "pre",
            HtmlTag::Code => "code",
            HtmlTag::Blockquote => "blockquote",
            HtmlTag::Hr => "hr",
            HtmlTag::Table => "table",
            HtmlTag::Thead => "thead",
            HtmlTag::Tbody => "tbody",
            HtmlTag::Tr => "tr",
            HtmlTag::Th => "th",
            HtmlTag::Td => "td",
        }
    }
    
    /// ไปŽๅญ—็ฌฆไธฒ่งฃๆžๆ ‡็ญพ
    pub fn from_str(s: &str) -> Option<Self> {
        match s.to_lowercase().as_str() {
            "div" => Some(HtmlTag::Div),
            "span" => Some(HtmlTag::Span),
            "center" => Some(HtmlTag::Center),
            "h1" => Some(HtmlTag::H1),
            "h2" => Some(HtmlTag::H2),
            "h3" => Some(HtmlTag::H3),
            "h4" => Some(HtmlTag::H4),
            "h5" => Some(HtmlTag::H5),
            "h6" => Some(HtmlTag::H6),
            "p" => Some(HtmlTag::P),
            "br" => Some(HtmlTag::Br),
            "strong" => Some(HtmlTag::Strong),
            "b" => Some(HtmlTag::B),
            "em" => Some(HtmlTag::Em),
            "i" => Some(HtmlTag::I),
            "u" => Some(HtmlTag::U),
            "del" => Some(HtmlTag::Del),
            "s" => Some(HtmlTag::S),
            "mark" => Some(HtmlTag::Mark),
            "kbd" => Some(HtmlTag::Kbd),
            "sup" => Some(HtmlTag::Sup),
            "sub" => Some(HtmlTag::Sub),
            "a" => Some(HtmlTag::A),
            "img" => Some(HtmlTag::Img),
            "ul" => Some(HtmlTag::Ul),
            "ol" => Some(HtmlTag::Ol),
            "li" => Some(HtmlTag::Li),
            "pre" => Some(HtmlTag::Pre),
            "code" => Some(HtmlTag::Code),
            "blockquote" => Some(HtmlTag::Blockquote),
            "hr" => Some(HtmlTag::Hr),
            "table" => Some(HtmlTag::Table),
            "thead" => Some(HtmlTag::Thead),
            "tbody" => Some(HtmlTag::Tbody),
            "tr" => Some(HtmlTag::Tr),
            "th" => Some(HtmlTag::Th),
            "td" => Some(HtmlTag::Td),
            _ => None,
        }
    }
    
    /// ๅˆคๆ–ญๆ˜ฏๅฆไธบๅ—็บงๅ…ƒ็ด 
    pub fn is_block(&self) -> bool {
        matches!(self,
            HtmlTag::Div | HtmlTag::Center |
            HtmlTag::H1 | HtmlTag::H2 | HtmlTag::H3 | 
            HtmlTag::H4 | HtmlTag::H5 | HtmlTag::H6 |
            HtmlTag::P | HtmlTag::Pre |
            HtmlTag::Ul | HtmlTag::Ol | HtmlTag::Li |
            HtmlTag::Blockquote | HtmlTag::Hr |
            HtmlTag::Table | HtmlTag::Thead | HtmlTag::Tbody | 
            HtmlTag::Tr | HtmlTag::Th | HtmlTag::Td
        )
    }
    
    /// ๅˆคๆ–ญๆ˜ฏๅฆไธบ่กŒๅ†…ๅ…ƒ็ด 
    pub fn is_inline(&self) -> bool {
        !self.is_block() && !self.is_void()
    }
    
    /// ๅˆคๆ–ญๆ˜ฏๅฆไธบ็ฉบๅ…ƒ็ด ๏ผˆๆ— ๅ†…ๅฎน๏ผ‰
    pub fn is_void(&self) -> bool {
        matches!(self, HtmlTag::Br | HtmlTag::Hr | HtmlTag::Img)
    }
}
```

---

## 3. ๆจกๅ—่ฎพ่ฎก


### 3.1 ๆจกๅ—็ป“ๆž„


```
src/
โ”œโ”€โ”€ lib.rs                    # ๅ…ฌๅ…ฑ API
โ”œโ”€โ”€ error.rs                  # ้”™่ฏฏ็ฑปๅž‹
โ”œโ”€โ”€ html/                     # HTML ๅค„็†ๆจกๅ—๏ผˆๆ–ฐๅขž๏ผ‰
โ”‚   โ”œโ”€โ”€ mod.rs               # ๆจกๅ—ๅ…ฅๅฃ
โ”‚   โ”œโ”€โ”€ ast.rs               # HTML AST ๅฎšไน‰
โ”‚   โ”œโ”€โ”€ parser.rs            # HTML ่งฃๆžๅ™จ
โ”‚   โ”œโ”€โ”€ md_converter.rs      # Markdown โ†’ HTML ่ฝฌๆข
โ”‚   โ””โ”€โ”€ element.rs           # HTML ๅ…ƒ็ด ๅทฅๅ…ท
โ”œโ”€โ”€ css/                      # CSS ๆ ทๅผๆจกๅ—๏ผˆ้‡ๆž„๏ผ‰
โ”‚   โ”œโ”€โ”€ mod.rs               # ๆจกๅ—ๅ…ฅๅฃ
โ”‚   โ”œโ”€โ”€ engine.rs            # CSS ๅผ•ๆ“Ž๏ผˆๅŸบไบŽ Lightning CSS๏ผ‰
โ”‚   โ”œโ”€โ”€ adapter.rs           # Lightning CSS ้€‚้…ๅฑ‚
โ”‚   โ”œโ”€โ”€ computed.rs          # ่ฎก็ฎ—ๅŽๆ ทๅผๅฎšไน‰
โ”‚   โ”œโ”€โ”€ selector.rs          # ้€‰ๆ‹ฉๅ™จๅŒน้…
โ”‚   โ””โ”€โ”€ default.css          # ้ป˜่ฎคๆ ทๅผ่กจ
โ”œโ”€โ”€ layout/                   # ๅธƒๅฑ€ๅผ•ๆ“Ž๏ผˆไปŽ generator ้‡ๆž„๏ผ‰
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”œโ”€โ”€ context.rs           # ๅธƒๅฑ€ไธŠไธ‹ๆ–‡
โ”‚   โ”œโ”€โ”€ flow.rs              # ๆตๅผๅธƒๅฑ€
โ”‚   โ”œโ”€โ”€ text.rs              # ๆ–‡ๆœฌๅธƒๅฑ€
โ”‚   โ”œโ”€โ”€ table.rs             # ่กจๆ ผๅธƒๅฑ€
โ”‚   โ””โ”€โ”€ pagination.rs        # ๅˆ†้กตๅค„็†
โ”œโ”€โ”€ render/                   # ๆธฒๆŸ“ๆจกๅ—๏ผˆไฟๆŒ๏ผ‰
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”œโ”€โ”€ pdf.rs
โ”‚   โ”œโ”€โ”€ svg.rs
โ”‚   โ””โ”€โ”€ pixmap.rs
โ””โ”€โ”€ text.rs                   # ๆ–‡ๆœฌๅค„็†๏ผˆไฟๆŒ๏ผ‰
```

### 3.2 HTML ่งฃๆžๅ™จๆจกๅ—


```rust
// src/html/parser.rs

use super::ast::*;
use super::element::ElementBuilder;

/// HTML ่งฃๆžๅ™จ
pub struct HtmlParser;

impl HtmlParser {
    /// ่งฃๆž HTML ๅญ—็ฌฆไธฒ
    pub fn parse(html: &str) -> Result<HtmlDocument, HtmlParseError> {
        let mut parser = Self;
        parser.parse_document(html)
    }
    
    /// ่งฃๆžๅ†…่” HTML๏ผˆ็”จไบŽ Markdown ไธญ็š„ HTML ๆ ‡็ญพ๏ผ‰
    pub fn parse_inline(html: &str) -> Result<Vec<HtmlNode>, HtmlParseError> {
        // ๅค„็†็ฎ€ๅ•็š„ๅ†…่”ๆ ‡็ญพๅฆ‚ <br/>, <span>, <b> ็ญ‰
        let mut nodes = Vec::new();
        // ๅฎž็Žฐ่งฃๆž้€ป่พ‘...
        Ok(nodes)
    }
    
    fn parse_document(&mut self, html: &str) -> Result<HtmlDocument, HtmlParseError> {
        // ไฝฟ็”จ roxmltree ๆˆ–ๆ‰‹ๅŠจ่งฃๆž
        // ่ฟ™้‡Œ็ฎ€ๅŒ–ๅฑ•็คบๆ ธๅฟƒ้€ป่พ‘
        let root = self.parse_element(html)?;
        
        // ๆๅ– <style> ๆ ‡็ญพๅ†…ๅฎน
        let style_sheets = Self::extract_style_sheets(&root);
        
        Ok(HtmlDocument { root, style_sheets })
    }
    
    fn parse_element(&mut self, html: &str) -> Result<HtmlElement, HtmlParseError> {
        // ่งฃๆžๆ ‡็ญพใ€ๅฑžๆ€งใ€ๅญๅ…ƒ็ด 
        todo!()
    }
    
    /// ไปŽๆ–‡ๆกฃไธญๆๅ–ๆ‰€ๆœ‰ <style> ๆ ‡็ญพๅ†…ๅฎน
    fn extract_style_sheets(root: &HtmlElement) -> Vec<String> {
        let mut sheets = Vec::new();
        Self::collect_styles(root, &mut sheets);
        sheets
    }
    
    fn collect_styles(element: &HtmlElement, sheets: &mut Vec<String>) {
        if element.tag == HtmlTag::Style {
            // ๆๅ–ๆ ทๅผๅ†…ๅฎน
            for child in &element.children {
                if let HtmlNode::Text(text) = child {
                    sheets.push(text.clone());
                }
            }
        }
        
        for child in &element.children {
            if let HtmlNode::Element(el) = child {
                Self::collect_styles(el, sheets);
            }
        }
    }
}

#[derive(Debug, thiserror::Error)]

pub enum HtmlParseError {
    #[error("Invalid HTML: {0}")]
    InvalidHtml(String),
    #[error("Unsupported tag: {0}")]
    UnsupportedTag(String),
    #[error("Unclosed tag: {0}")]
    UnclosedTag(String),
}
```

### 3.3 Markdown ๅˆฐ HTML ่ฝฌๆขๅ™จ


```rust
// src/html/md_converter.rs

use markdown::mdast;
use super::ast::*;
use super::element::ElementBuilder;

/// Markdown ๅˆฐ HTML ่ฝฌๆขๅ™จ
pub struct MdToHtmlConverter;

impl MdToHtmlConverter {
    /// ๅฐ† Markdown ่ฝฌๆขไธบ HTML ๆ–‡ๆกฃ
    pub fn convert(mdast: &mdast::Node) -> Result<HtmlDocument, ConvertError> {
        let converter = Self;
        let root = converter.convert_node(mdast)?;
        
        // ๆๅ– <style> ๆ ‡็ญพ
        let style_sheets = Self::extract_styles_from_mdast(mdast);
        
        Ok(HtmlDocument {
            root: HtmlElement {
                tag: HtmlTag::Div, // ๅŒ…่ฃ…ๅœจ div ไธญ
                attrs: HashMap::new(),
                children: vec![HtmlNode::Element(root)],
            },
            style_sheets,
        })
    }
    
    /// ่ฝฌๆขๅ•ไธช MDAST ่Š‚็‚น
    fn convert_node(&self, node: &mdast::Node) -> Result<HtmlElement, ConvertError> {
        match node {
            mdast::Node::Root(root) => self.convert_root(root),
            mdast::Node::Heading(heading) => self.convert_heading(heading),
            mdast::Node::Paragraph(para) => self.convert_paragraph(para),
            mdast::Node::Text(text) => self.convert_text(&text.value),
            mdast::Node::Strong(strong) => self.convert_strong(strong),
            mdast::Node::Emphasis(em) => self.convert_emphasis(em),
            mdast::Node::List(list) => self.convert_list(list),
            mdast::Node::ListItem(item) => self.convert_list_item(item),
            mdast::Node::Code(code) => self.convert_code(code),
            mdast::Node::InlineCode(code) => self.convert_inline_code(code),
            mdast::Node::Link(link) => self.convert_link(link),
            mdast::Node::Image(image) => self.convert_image(image),
            mdast::Node::Blockquote(bq) => self.convert_blockquote(bq),
            mdast::Node::ThematicBreak(_) => self.convert_hr(),
            mdast::Node::Table(table) => self.convert_table(table),
            mdast::Node::Delete(del) => self.convert_delete(del),
            mdast::Node::Html(html) => self.convert_html(&html.value),
            _ => Err(ConvertError::UnsupportedNode(format!("{:?}", node))),
        }
    }
    
    fn convert_heading(&self, heading: &mdast::Heading) -> Result<HtmlElement, ConvertError> {
        let tag = match heading.depth {
            1 => HtmlTag::H1,
            2 => HtmlTag::H2,
            3 => HtmlTag::H3,
            4 => HtmlTag::H4,
            5 => HtmlTag::H5,
            6 => HtmlTag::H6,
            _ => HtmlTag::H6,
        };
        
        let children = self.convert_children(&heading.children)?;
        
        Ok(ElementBuilder::new(tag).children(children).build())
    }
    
    fn convert_paragraph(&self, para: &mdast::Paragraph) -> Result<HtmlElement, ConvertError> {
        let children = self.convert_children(&para.children)?;
        Ok(ElementBuilder::new(HtmlTag::P).children(children).build())
    }
    
    fn convert_strong(&self, strong: &mdast::Strong) -> Result<HtmlElement, ConvertError> {
        let children = self.convert_children(&strong.children)?;
        Ok(ElementBuilder::new(HtmlTag::Strong).children(children).build())
    }
    
    fn convert_html(&self, html: &str) -> Result<HtmlElement, ConvertError> {
        // ่งฃๆžๅ†…่” HTML ๅญ—็ฌฆไธฒ
        super::parser::HtmlParser::parse_inline(html)
            .map_err(|e| ConvertError::HtmlParseError(e.to_string()))
            .and_then(|nodes| {
                // ๅฆ‚ๆžœๅชๆœ‰ไธ€ไธชๅ…ƒ็ด ๏ผŒ่ฟ”ๅ›žๅฎƒ
                if nodes.len() == 1 {
                    if let HtmlNode::Element(el) = &nodes[0] {
                        return Ok(el.clone());
                    }
                }
                // ๅฆๅˆ™ๅŒ…่ฃ…ๅœจ div ไธญ
                Ok(ElementBuilder::new(HtmlTag::Div).children(nodes).build())
            })
    }
    
    // ... ๅ…ถไป–่ฝฌๆขๆ–นๆณ•
    
    /// ่ฝฌๆขๅญ่Š‚็‚นๅˆ—่กจ
    fn convert_children(&self, children: &[mdast::Node]) -> Result<Vec<HtmlNode>, ConvertError> {
        let mut result = Vec::new();
        for child in children {
            match self.convert_node(child)? {
                el if el.tag == HtmlTag::Div && el.attrs.is_empty() => {
                    // ๅฑ•ๅผ€็ฉบ็š„ div ๅŒ…่ฃ…
                    result.extend(el.children);
                }
                el => result.push(HtmlNode::Element(el)),
            }
        }
        Ok(result)
    }
}

/// ๅ…ƒ็ด ๆž„ๅปบๅ™จ๏ผˆ่พ…ๅŠฉ๏ผ‰
mod element {
    use super::*;
    
    pub struct ElementBuilder {
        tag: HtmlTag,
        attrs: HashMap<String, String>,
        children: Vec<HtmlNode>,
    }
    
    impl ElementBuilder {
        pub fn new(tag: HtmlTag) -> Self {
            Self {
                tag,
                attrs: HashMap::new(),
                children: Vec::new(),
            }
        }
        
        pub fn attr(mut self, key: &str, value: &str) -> Self {
            self.attrs.insert(key.to_string(), value.to_string());
            self
        }
        
        pub fn children(mut self, children: Vec<HtmlNode>) -> Self {
            self.children = children;
            self
        }
        
        pub fn build(self) -> HtmlElement {
            HtmlElement {
                tag: self.tag,
                attrs: self.attrs,
                children: self.children,
            }
        }
    }
}
```

---

## 4. CSS ๆ ทๅผ็ณป็ปŸ


### 4.1 ๆžถๆž„่ฎพ่ฎก


```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    CSS ๆ ทๅผ็ณป็ปŸๆžถๆž„                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚              Lightning CSS ๅฑ‚                            โ”‚   โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚  CSS ่งฃๆž   โ”‚  โ”‚ ้€‰ๆ‹ฉๅ™จๅŒน้…  โ”‚  โ”‚ ๅฑžๆ€งๅค„็†    โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚ - ๅฎŒๆ•ด CSS  โ”‚  โ”‚ - ID/็ฑป/ๆ ‡็ญพโ”‚  โ”‚ - ็ฑปๅž‹ๅฎ‰ๅ…จ  โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚ - ็ฎ€ๅ†™ๅฑ•ๅผ€  โ”‚  โ”‚ - ๅฑžๆ€ง้€‰ๆ‹ฉๅ™จโ”‚  โ”‚ - ๅ•ไฝ่ฝฌๆข  โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚ - ้ขœ่‰ฒๅค„็†  โ”‚  โ”‚ - ไผช็ฑป      โ”‚  โ”‚ - ่ฎก็ฎ—ๅ€ผ    โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                              โ”‚                                  โ”‚
โ”‚                              โ–ผ                                  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚              liepress ้€‚้…ๅฑ‚                             โ”‚   โ”‚
โ”‚  โ”‚                                                         โ”‚   โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚ ๆ ทๅผ่ฝฌๆข    โ”‚  โ”‚ PDF ๆ‰ฉๅฑ•    โ”‚  โ”‚ ๅ•ไฝๅค„็†    โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚             โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚ Lightning   โ”‚  โ”‚ - ๅˆ†้กตๆŽงๅˆถ  โ”‚  โ”‚ - pxโ†’pt     โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚ ๅฑžๆ€ง โ†’      โ”‚  โ”‚ - ้กต็œ‰้กต่„š  โ”‚  โ”‚ - em/rem    โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚ liepress    โ”‚  โ”‚ - ๆ‰“ๅฐไผ˜ๅŒ–  โ”‚  โ”‚ - ็™พๅˆ†ๆฏ”    โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ”‚ ๆ ทๅผ        โ”‚  โ”‚             โ”‚  โ”‚             โ”‚      โ”‚   โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                              โ”‚                                  โ”‚
โ”‚                              โ–ผ                                  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚              ComputedStyles                              โ”‚   โ”‚
โ”‚  โ”‚         ๏ผˆๅธƒๅฑ€ๅผ•ๆ“Žไฝฟ็”จ็š„ๆœ€็ปˆๆ ทๅผ๏ผ‰                        โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### 4.2 ไพ่ต–้…็ฝฎ


```toml
# Cargo.toml


[dependencies]
# ... ็Žฐๆœ‰ไพ่ต– ...


# CSS ๅค„็†

lightningcss = { version = "1.0.0-alpha.70", features = ["into_owned"] }

# HTML ่งฃๆž๏ผˆๅฏ้€‰๏ผŒ็”จไบŽๅค„็†ๅ†…่” HTML๏ผ‰

roxmltree = "0.20"

# ้€‰ๆ‹ฉๅ™จๅŒน้…๏ผˆLightning CSS ๅทฒๅŒ…ๅซ๏ผŒไฝ†ๅฏ่ƒฝ้œ€่ฆๅ•็‹ฌไฝฟ็”จ๏ผ‰

selectors = "0.25"
cssparser = "0.36"
```

### 4.3 CSS ๅผ•ๆ“Žๅฎž็Žฐ


```rust
// src/css/engine.rs

use lightningcss::stylesheet::{StyleSheet, ParserOptions, PrinterOptions};
use lightningcss::selector::Selector;
use lightningcss::properties::Property;
use lightningcss::values::length::Length;
use lightningcss::declaration::DeclarationBlock;

use super::computed::ComputedStyles;
use super::adapter::LightningCssAdapter;

/// CSS ๆ ทๅผๅผ•ๆ“Ž
pub struct CssEngine {
    /// ็”จๆˆทไปฃ็†ๆ ทๅผ่กจ๏ผˆๅ†…็ฝฎ้ป˜่ฎค๏ผ‰
    ua_stylesheet: StyleSheet<'static, 'static>,
    /// ็”จๆˆทๆ ทๅผ่กจ
    user_stylesheet: Option<StyleSheet<'static, 'static>>,
    /// ไฝœ่€…ๆ ทๅผ่กจ๏ผˆๆฅ่‡ช <style> ๆ ‡็ญพ๏ผ‰
    author_stylesheet: Option<StyleSheet<'static, 'static>>,
    /// ้€‚้…ๅ™จ
    adapter: LightningCssAdapter,
}

impl CssEngine {
    /// ๅˆ›ๅปบๆ–ฐ็š„ CSS ๅผ•ๆ“Ž
    pub fn new() -> Result<Self, CssError> {
        let default_css = include_str!("default.css");
        let ua_stylesheet = StyleSheet::parse(default_css, ParserOptions::default())
            .map_err(|e| CssError::ParseError(e.to_string()))?;
        
        Ok(Self {
            ua_stylesheet,
            user_stylesheet: None,
            author_stylesheet: None,
            adapter: LightningCssAdapter::new(),
        })
    }
    
    /// ๆทปๅŠ ็”จๆˆท CSS
    pub fn with_user_css(mut self, css: &str) -> Result<Self, CssError> {
        self.user_stylesheet = Some(
            StyleSheet::parse(css, ParserOptions::default())
                .map_err(|e| CssError::ParseError(e.to_string()))?
        );
        Ok(self)
    }
    
    /// ๆทปๅŠ ไฝœ่€… CSS๏ผˆๆฅ่‡ช <style> ๆ ‡็ญพ๏ผ‰
    pub fn with_author_css(mut self, css: &str) -> Result<Self, CssError> {
        self.author_stylesheet = Some(
            StyleSheet::parse(css, ParserOptions::default())
                .map_err(|e| CssError::ParseError(e.to_string()))?
        );
        Ok(self)
    }
    
    /// ่ฎก็ฎ—ๅ…ƒ็ด ็š„ๆ ทๅผ
    pub fn compute_styles(
        &self,
        element: &HtmlElement,
        parent_styles: Option<&ComputedStyles>,
    ) -> ComputedStyles {
        // 1. ๅˆ›ๅปบๆ ทๅผไธŠไธ‹ๆ–‡
        let mut context = StyleContext::new(parent_styles);
        
        // 2. ๆ”ถ้›†ๆ‰€ๆœ‰ๅŒน้…็š„่ง„ๅˆ™๏ผˆๆŒ‰ไผ˜ๅ…ˆ็บงๆŽ’ๅบ๏ผ‰
        let rules = self.collect_matching_rules(element);
        
        // 3. ๅบ”็”จๆ ทๅผ่ง„ๅˆ™
        for (specificity, declarations) in rules {
            context.apply_declarations(declarations, specificity);
        }
        
        // 4. ๅบ”็”จๅ†…่”ๆ ทๅผ๏ผˆๆœ€้ซ˜ไผ˜ๅ…ˆ็บง๏ผ‰
        if let Some(style_attr) = element.attrs.get("style") {
            if let Ok(inline_sheet) = StyleSheet::parse(
                &format!("{{ {style_attr} }}"),
                ParserOptions::default()
            ) {
                for rule in inline_sheet.rules.0 {
                    if let Some(declarations) = rule.declarations {
                        context.apply_declarations(declarations, SPECIFICITY_INLINE);
                    }
                }
            }
        }
        
        // 5. ่ฎก็ฎ—ๆœ€็ปˆๅ€ผ
        context.into_computed_styles(&self.adapter)
    }
    
    /// ๆ”ถ้›†ๅŒน้…็š„่ง„ๅˆ™
    fn collect_matching_rules(
        &self,
        element: &HtmlElement,
    ) -> Vec<(u32, DeclarationBlock<'static, 'static>)> {
        let mut rules = Vec::new();
        
        // UA ๆ ทๅผ๏ผˆๆœ€ไฝŽไผ˜ๅ…ˆ็บง๏ผ‰
        self.collect_from_stylesheet(&self.ua_stylesheet, element, &mut rules);
        
        // ็”จๆˆทๆ ทๅผ
        if let Some(sheet) = &self.user_stylesheet {
            self.collect_from_stylesheet(sheet, element, &mut rules);
        }
        
        // ไฝœ่€…ๆ ทๅผ
        if let Some(sheet) = &self.author_stylesheet {
            self.collect_from_stylesheet(sheet, element, &mut rules);
        }
        
        // ๆŒ‰็‰นๅผ‚ๆ€งๆŽ’ๅบ
        rules.sort_by_key(|(spec, _)| *spec);
        
        rules
    }
    
    fn collect_from_stylesheet(
        &self,
        sheet: &StyleSheet,
        element: &HtmlElement,
        rules: &mut Vec<(u32, DeclarationBlock<'static, 'static>)>,
    ) {
        for rule in &sheet.rules.0 {
            if let Some(selector) = &rule.selectors {
                if self.matches_selector(selector, element) {
                    let specificity = self.calculate_specificity(selector);
                    if let Some(declarations) = &rule.declarations {
                        rules.push((specificity, declarations.clone()));
                    }
                }
            }
        }
    }
    
    /// ๆฃ€ๆŸฅ้€‰ๆ‹ฉๅ™จๆ˜ฏๅฆๅŒน้…ๅ…ƒ็ด 
    fn matches_selector(&self, selector: &Selector, element: &HtmlElement) -> bool {
        // ็ฎ€ๅŒ–ๅฎž็Žฐ๏ผšๆฃ€ๆŸฅๆ ‡็ญพๅใ€็ฑปๅใ€ID
        // ๅฎž้™…ๅฎž็Žฐ้œ€่ฆไฝฟ็”จ Lightning CSS ็š„้€‰ๆ‹ฉๅ™จๅŒน้…
        todo!("ๅฎž็Žฐ้€‰ๆ‹ฉๅ™จๅŒน้…")
    }
    
    /// ่ฎก็ฎ—้€‰ๆ‹ฉๅ™จ็‰นๅผ‚ๆ€ง
    fn calculate_specificity(&self, selector: &Selector) -> u32 {
        // ID: 100, ็ฑป/ๅฑžๆ€ง/ไผช็ฑป: 10, ๆ ‡็ญพ: 1
        todo!("่ฎก็ฎ—็‰นๅผ‚ๆ€ง")
    }
}

const SPECIFICITY_INLINE: u32 = 10000;

/// ๆ ทๅผไธŠไธ‹ๆ–‡๏ผˆๆž„ๅปบไธญ๏ผ‰
struct StyleContext {
    parent: Option<ComputedStyles>,
    properties: HashMap<String, Property>,
}

impl StyleContext {
    fn new(parent: Option<&ComputedStyles>) -> Self {
        Self {
            parent: parent.cloned(),
            properties: HashMap::new(),
        }
    }
    
    fn apply_declarations(&mut self, declarations: DeclarationBlock, specificity: u32) {
        for decl in &declarations.declarations {
            // ๅญ˜ๅ‚จๅฑžๆ€ง๏ผŒๅŽ็ปญๅค„็†ๅฑ‚ๅ 
            self.properties.insert(
                decl.property_id().name().to_string(),
                decl.clone()
            );
        }
    }
    
    fn into_computed_styles(self, adapter: &LightningCssAdapter) -> ComputedStyles {
        let mut computed = self.parent.unwrap_or_default();
        
        for (_, property) in self.properties {
            adapter.apply_property(&mut computed, &property);
        }
        
        computed
    }
}
```

### 4.4 Lightning CSS ้€‚้…ๅฑ‚


```rust
// src/css/adapter.rs

use lightningcss::properties::Property;
use lightningcss::values::length::{Length, LengthValue};
use lightningcss::values::color::CssColor;
use lightningcss::values::percentage::Percentage;

use super::computed::{ComputedStyles, CssValue, LengthUnit};

/// Lightning CSS ๅˆฐ liepress ็š„้€‚้…ๅ™จ
pub struct LightningCssAdapter;

impl LightningCssAdapter {
    pub fn new() -> Self {
        Self
    }
    
    /// ๅฐ† Lightning CSS ๅฑžๆ€งๅบ”็”จๅˆฐ liepress ๆ ทๅผ
    pub fn apply_property(&self, computed: &mut ComputedStyles, property: &Property) {
        match property {
            // ๅญ—ไฝ“็›ธๅ…ณ
            Property::FontSize(size) => {
                computed.font_size = self.convert_length(size);
            }
            Property::FontFamily(families) => {
                computed.font_family = families.0.iter()
                    .map(|f| f.to_string())
                    .collect();
            }
            Property::FontWeight(weight) => {
                computed.font_weight = self.convert_font_weight(weight);
            }
            Property::FontStyle(style) => {
                computed.font_style = self.convert_font_style(style);
            }
            Property::LineHeight(height) => {
                computed.line_height = self.convert_line_height(height);
            }
            Property::LetterSpacing(spacing) => {
                computed.letter_spacing = self.convert_length(&spacing.0);
            }
            
            // ๆ–‡ๆœฌ็›ธๅ…ณ
            Property::Color(color) => {
                computed.color = self.convert_color(color);
            }
            Property::TextAlign(align) => {
                computed.text_align = self.convert_text_align(align);
            }
            Property::TextIndent(indent) => {
                computed.text_indent = self.convert_length(indent);
            }
            Property::TextDecoration(decoration) => {
                computed.text_decoration = self.convert_text_decoration(decoration);
            }
            
            // ๅธƒๅฑ€็›ธๅ…ณ
            Property::Display(display) => {
                computed.display = self.convert_display(display);
            }
            Property::Width(width) => {
                computed.width = Some(self.convert_length(&width.0));
            }
            Property::Height(height) => {
                computed.height = Some(self.convert_length(&height.0));
            }
            
            // ่พน่ท
            Property::Margin(margin) => {
                computed.margin_top = self.convert_length(&margin.top);
                computed.margin_right = self.convert_length(&margin.right);
                computed.margin_bottom = self.convert_length(&margin.bottom);
                computed.margin_left = self.convert_length(&margin.left);
            }
            Property::MarginTop(m) => computed.margin_top = self.convert_length(m),
            Property::MarginRight(m) => computed.margin_right = self.convert_length(m),
            Property::MarginBottom(m) => computed.margin_bottom = self.convert_length(m),
            Property::MarginLeft(m) => computed.margin_left = self.convert_length(m),
            
            // ๅกซๅ……
            Property::Padding(padding) => {
                computed.padding_top = self.convert_length(&padding.top);
                computed.padding_right = self.convert_length(&padding.right);
                computed.padding_bottom = self.convert_length(&padding.bottom);
                computed.padding_left = self.convert_length(&padding.left);
            }
            Property::PaddingTop(p) => computed.padding_top = self.convert_length(p),
            Property::PaddingRight(p) => computed.padding_right = self.convert_length(p),
            Property::PaddingBottom(p) => computed.padding_bottom = self.convert_length(p),
            Property::PaddingLeft(p) => computed.padding_left = self.convert_length(p),
            
            // ่พนๆก†
            Property::BorderTopWidth(w) => computed.border_top_width = self.convert_length(w),
            Property::BorderRightWidth(w) => computed.border_right_width = self.convert_length(w),
            Property::BorderBottomWidth(w) => computed.border_bottom_width = self.convert_length(w),
            Property::BorderLeftWidth(w) => computed.border_left_width = self.convert_length(w),
            
            Property::BorderTopColor(c) => computed.border_top_color = Some(self.convert_color(c)),
            Property::BorderRightColor(c) => computed.border_right_color = Some(self.convert_color(c)),
            Property::BorderBottomColor(c) => computed.border_bottom_color = Some(self.convert_color(c)),
            Property::BorderLeftColor(c) => computed.border_left_color = Some(self.convert_color(c)),
            
            // ่ƒŒๆ™ฏ
            Property::BackgroundColor(color) => {
                computed.background_color = Some(self.convert_color(color));
            }
            
            // ๅˆ†้กตๆŽงๅˆถ๏ผˆliepress ๆ‰ฉๅฑ•๏ผ‰
            Property::Custom(custom) if custom.name.as_ref() == "page-break-before" => {
                computed.page_break_before = self.convert_page_break(&custom.value);
            }
            Property::Custom(custom) if custom.name.as_ref() == "page-break-after" => {
                computed.page_break_after = self.convert_page_break(&custom.value);
            }
            
            // ๅฟฝ็•ฅไธๆ”ฏๆŒ็š„ๅฑžๆ€ง
            _ => {}
        }
    }
    
    /// ่ฝฌๆข้•ฟๅบฆๅ€ผ
    fn convert_length(&self, length: &Length) -> CssValue {
        match length {
            Length::Value(val) => match val {
                LengthValue::Px(v) => CssValue::Length(*v, LengthUnit::Px),
                LengthValue::Pt(v) => CssValue::Length(*v, LengthUnit::Pt),
                LengthValue::Em(v) => CssValue::Length(*v, LengthUnit::Em),
                LengthValue::Rem(v) => CssValue::Length(*v, LengthUnit::Rem),
                LengthValue::Percent(Percentage(v)) => CssValue::Percentage(*v),
                LengthValue::Mm(v) => CssValue::Length(*v, LengthUnit::Mm),
                LengthValue::Cm(v) => CssValue::Length(*v, LengthUnit::Cm),
                LengthValue::In(v) => CssValue::Length(*v, LengthUnit::In),
                _ => CssValue::Length(0.0, LengthUnit::Px),
            },
            _ => CssValue::Length(0.0, LengthUnit::Px),
        }
    }
    
    /// ่ฝฌๆข้ขœ่‰ฒ
    fn convert_color(&self, color: &CssColor) -> crate::visual::Color {
        match color {
            CssColor::RGB(rgb) => crate::visual::Color::new(
                rgb.red,
                rgb.green,
                rgb.blue,
            ),
            CssColor::RGBA(rgba) => crate::visual::Color::with_alpha(
                rgba.red,
                rgba.green,
                rgba.blue,
                (rgba.alpha * 255.0) as u8,
            ),
            CssColor::Hex(hex) => crate::visual::Color::new(
                ((hex >> 16) & 0xFF) as u8,
                ((hex >> 8) & 0xFF) as u8,
                (hex & 0xFF) as u8,
            ),
            _ => crate::visual::Color::new(0, 0, 0),
        }
    }
    
    // ... ๅ…ถไป–่ฝฌๆขๆ–นๆณ•
}
```

### 4.5 ่ฎก็ฎ—ๅŽๆ ทๅผๅฎšไน‰


```rust
// src/css/computed.rs

use crate::visual::Color;

/// CSS ๅ€ผ็ฑปๅž‹
#[derive(Debug, Clone)]

pub enum CssValue {
    Length(f32, LengthUnit),
    Percentage(f32),
    Color(Color),
    String(String),
    Ident(String),
    Number(f32),
    List(Vec<CssValue>),
    None,
}

/// ้•ฟๅบฆๅ•ไฝ
#[derive(Debug, Clone, Copy, PartialEq)]

pub enum LengthUnit {
    Px,
    Pt,
    Em,
    Rem,
    In,
    Cm,
    Mm,
    Percent,
}

/// ่ฎก็ฎ—ๅŽ็š„ๆ ทๅผ๏ผˆไพ›ๅธƒๅฑ€ๅผ•ๆ“Žไฝฟ็”จ๏ผ‰
#[derive(Debug, Clone)]

pub struct ComputedStyles {
    // ๅญ—ไฝ“
    pub font_family: Vec<String>,
    pub font_size: CssValue,
    pub font_weight: FontWeight,
    pub font_style: FontStyle,
    pub line_height: CssValue,
    pub letter_spacing: CssValue,
    pub color: Color,
    
    // ๆ–‡ๆœฌ
    pub text_align: TextAlign,
    pub text_indent: CssValue,
    pub text_decoration: TextDecoration,
    pub text_transform: TextTransform,
    pub white_space: WhiteSpace,
    
    // ๅธƒๅฑ€
    pub display: Display,
    pub width: Option<CssValue>,
    pub height: Option<CssValue>,
    
    // ็›’ๆจกๅž‹
    pub margin_top: CssValue,
    pub margin_right: CssValue,
    pub margin_bottom: CssValue,
    pub margin_left: CssValue,
    
    pub padding_top: CssValue,
    pub padding_right: CssValue,
    pub padding_bottom: CssValue,
    pub padding_left: CssValue,
    
    // ่พนๆก†
    pub border_top_width: CssValue,
    pub border_right_width: CssValue,
    pub border_bottom_width: CssValue,
    pub border_left_width: CssValue,
    
    pub border_top_color: Option<Color>,
    pub border_right_color: Option<Color>,
    pub border_bottom_color: Option<Color>,
    pub border_left_color: Option<Color>,
    
    pub border_top_style: BorderStyle,
    pub border_right_style: BorderStyle,
    pub border_bottom_style: BorderStyle,
    pub border_left_style: BorderStyle,
    
    // ่ƒŒๆ™ฏ
    pub background_color: Option<Color>,
    
    // ๅˆ†้กต
    pub page_break_before: PageBreak,
    pub page_break_after: PageBreak,
    
    // ่กจๆ ผ
    pub border_collapse: BorderCollapse,
    pub border_spacing: (CssValue, CssValue),
    
    // ๅˆ—่กจ
    pub list_style_type: ListStyleType,
    
    // ้“พๆŽฅ๏ผˆ็‰นๆฎŠ๏ผ‰
    pub link_url: Option<String>,
}

impl Default for ComputedStyles {
    fn default() -> Self {
        Self {
            font_family: vec!["serif".to_string()],
            font_size: CssValue::Length(10.5, LengthUnit::Pt),
            font_weight: FontWeight::Normal,
            font_style: FontStyle::Normal,
            line_height: CssValue::Number(1.5),
            letter_spacing: CssValue::Length(0.0, LengthUnit::Px),
            color: Color::new(0, 0, 0),
            text_align: TextAlign::Left,
            text_indent: CssValue::Length(0.0, LengthUnit::Pt),
            text_decoration: TextDecoration::None,
            text_transform: TextTransform::None,
            white_space: WhiteSpace::Normal,
            display: Display::Block,
            width: None,
            height: None,
            margin_top: CssValue::Length(0.0, LengthUnit::Pt),
            margin_right: CssValue::Length(0.0, LengthUnit::Pt),
            margin_bottom: CssValue::Length(12.0, LengthUnit::Pt),
            margin_left: CssValue::Length(0.0, LengthUnit::Pt),
            padding_top: CssValue::Length(0.0, LengthUnit::Pt),
            padding_right: CssValue::Length(0.0, LengthUnit::Pt),
            padding_bottom: CssValue::Length(0.0, LengthUnit::Pt),
            padding_left: CssValue::Length(0.0, LengthUnit::Pt),
            border_top_width: CssValue::Length(0.0, LengthUnit::Pt),
            border_right_width: CssValue::Length(0.0, LengthUnit::Pt),
            border_bottom_width: CssValue::Length(0.0, LengthUnit::Pt),
            border_left_width: CssValue::Length(0.0, LengthUnit::Pt),
            border_top_color: None,
            border_right_color: None,
            border_bottom_color: None,
            border_left_color: None,
            border_top_style: BorderStyle::None,
            border_right_style: BorderStyle::None,
            border_bottom_style: BorderStyle::None,
            border_left_style: BorderStyle::None,
            background_color: None,
            page_break_before: PageBreak::Auto,
            page_break_after: PageBreak::Auto,
            border_collapse: BorderCollapse::Collapse,
            border_spacing: (CssValue::Length(0.0, LengthUnit::Pt), CssValue::Length(0.0, LengthUnit::Pt)),
            list_style_type: ListStyleType::Disc,
            link_url: None,
        }
    }
}

impl ComputedStyles {
    /// ไปŽ็ˆถๆ ทๅผ็ปงๆ‰ฟ
    pub fn inherit_from(&mut self, parent: &Self) {
        // ๅฏ็ปงๆ‰ฟๅฑžๆ€ง
        self.font_family = parent.font_family.clone();
        self.font_size = parent.font_size.clone();
        self.font_weight = parent.font_weight;
        self.font_style = parent.font_style;
        self.line_height = parent.line_height.clone();
        self.letter_spacing = parent.letter_spacing.clone();
        self.color = parent.color;
        self.text_align = parent.text_align;
        self.text_transform = parent.text_transform;
        self.white_space = parent.white_space;
        self.page_break_before = parent.page_break_before;
        self.page_break_after = parent.page_break_after;
        self.list_style_type = parent.list_style_type;
        
        // ไธๅฏ็ปงๆ‰ฟๅฑžๆ€งไฟๆŒ้ป˜่ฎคๅ€ผ
    }
    
    /// ่งฃๆž้•ฟๅบฆๅ€ผไธบ pt
    pub fn length_to_pt(&self, value: &CssValue, parent_size: f32) -> f32 {
        match value {
            CssValue::Length(v, LengthUnit::Pt) => *v,
            CssValue::Length(v, LengthUnit::Px) => *v * 0.75, // ๅ‡่ฎพ 96 DPI
            CssValue::Length(v, LengthUnit::Em) => *v * self.font_size_pt(),
            CssValue::Length(v, LengthUnit::Rem) => *v * 10.5, // ๆ นๅญ—ไฝ“ๅคงๅฐ
            CssValue::Length(v, LengthUnit::In) => *v * 72.0,
            CssValue::Length(v, LengthUnit::Cm) => *v * 28.35,
            CssValue::Length(v, LengthUnit::Mm) => *v * 2.835,
            CssValue::Percentage(v) => *v * parent_size / 100.0,
            _ => 0.0,
        }
    }
    
    fn font_size_pt(&self) -> f32 {
        match &self.font_size {
            CssValue::Length(v, LengthUnit::Pt) => *v,
            CssValue::Length(v, LengthUnit::Px) => *v * 0.75,
            _ => 10.5,
        }
    }
}

// ๆžšไธพๅฎšไน‰
#[derive(Debug, Clone, Copy, PartialEq)]

pub enum FontWeight {
    Normal,
    Bold,
    W100, W200, W300, W400, W500, W600, W700, W800, W900,
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum FontStyle {
    Normal,
    Italic,
    Oblique,
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum TextAlign {
    Left,
    Center,
    Right,
    Justify,
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum TextDecoration {
    None,
    Underline,
    LineThrough,
    Overline,
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum TextTransform {
    None,
    Uppercase,
    Lowercase,
    Capitalize,
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum WhiteSpace {
    Normal,
    Nowrap,
    Pre,
    PreWrap,
    PreLine,
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum Display {
    Block,
    Inline,
    InlineBlock,
    None,
    Table,
    TableRow,
    TableCell,
    Flex, // ๆœชๆฅๆ”ฏๆŒ
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum BorderStyle {
    None,
    Solid,
    Dashed,
    Dotted,
    Double,
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum PageBreak {
    Auto,
    Always,
    Avoid,
    Left,
    Right,
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum BorderCollapse {
    Collapse,
    Separate,
}

#[derive(Debug, Clone, Copy, PartialEq)]

pub enum ListStyleType {
    None,
    Disc,
    Circle,
    Square,
    Decimal,
    DecimalLeadingZero,
    LowerRoman,
    UpperRoman,
    LowerAlpha,
    UpperAlpha,
}
```

---

## 5. ๆ•ฐๆฎๆตไธŽๅค„็†ๆต็จ‹


### 5.1 ๅฎŒๆ•ดๅค„็†ๆต็จ‹


```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                          ๅฎŒๆ•ดๅค„็†ๆต็จ‹                                        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚  1. ่พ“ๅ…ฅ้˜ถๆฎต                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                            โ”‚
โ”‚  โ”‚  Markdown   โ”‚  ็”จๆˆท่พ“ๅ…ฅ็š„ Markdown ๆ–‡ๆœฌ๏ผˆๅฏ่ƒฝๅŒ…ๅซ HTML ๆ ‡็ญพ๏ผ‰              โ”‚
โ”‚  โ”‚   Source    โ”‚                                                            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                                            โ”‚
โ”‚         โ”‚                                                                   โ”‚
โ”‚         โ–ผ                                                                   โ”‚
โ”‚  2. ่งฃๆž้˜ถๆฎต                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚                    Markdown Parser                           โ”‚            โ”‚
โ”‚  โ”‚  - ไฝฟ็”จ markdown crate ่งฃๆžไธบ MDAST                          โ”‚            โ”‚
โ”‚  โ”‚  - ไฟ็•™ HTML ๆ ‡็ญพไธบ Html ่Š‚็‚น                                โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚                    MDAST ๆ ‘                                  โ”‚            โ”‚
โ”‚  โ”‚  Root                                                       โ”‚            โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ Heading(1, "ๆ ‡้ข˜")                                      โ”‚            โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ Paragraph                                               โ”‚            โ”‚
โ”‚  โ”‚  โ”‚   โ””โ”€โ”€ Text("ๆฎต่ฝๅ†…ๅฎน")                                    โ”‚            โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ Html("<div style='...'>")                               โ”‚            โ”‚
โ”‚  โ”‚  โ”‚   โ””โ”€โ”€ Paragraph                                           โ”‚            โ”‚
โ”‚  โ”‚  โ”‚       โ””โ”€โ”€ Text("HTML ๅ†…ๅฎน")                               โ”‚            โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ Html("</div>")                                          โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚  3. ่ฝฌๆข้˜ถๆฎต                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚                 Markdown โ†’ HTML Converter                    โ”‚            โ”‚
โ”‚  โ”‚  - ้ๅކ MDAST ๆ ‘                                             โ”‚            โ”‚
โ”‚  โ”‚  - ๅฐ† Markdown ่Š‚็‚น่ฝฌๆขไธบ HTML AST ่Š‚็‚น                       โ”‚            โ”‚
โ”‚  โ”‚  - ่งฃๆžๅ†…่” HTML ๅญ—็ฌฆไธฒ                                       โ”‚            โ”‚
โ”‚  โ”‚  - ๆๅ– <style> ๆ ‡็ญพๅ†…ๅฎน                                      โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚  4. HTML ๅค„็†้˜ถๆฎต                                                            โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚                    HTML AST                                  โ”‚            โ”‚
โ”‚  โ”‚  Element(div)                                               โ”‚            โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ Element(h1)                                            โ”‚            โ”‚
โ”‚  โ”‚  โ”‚   โ””โ”€โ”€ Text("ๆ ‡้ข˜")                                        โ”‚            โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ Element(p)                                             โ”‚            โ”‚
โ”‚  โ”‚  โ”‚   โ””โ”€โ”€ Text("ๆฎต่ฝๅ†…ๅฎน")                                    โ”‚            โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ Element(div, style="...")                              โ”‚            โ”‚
โ”‚  โ”‚      โ””โ”€โ”€ Element(p)                                         โ”‚            โ”‚
โ”‚  โ”‚          โ””โ”€โ”€ Text("HTML ๅ†…ๅฎน")                               โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚  5. ๆ ทๅผ่ฎก็ฎ—้˜ถๆฎต                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚                    CSS Engine                                โ”‚            โ”‚
โ”‚  โ”‚  - ่งฃๆžๅ†…็ฝฎ้ป˜่ฎค CSS                                          โ”‚            โ”‚
โ”‚  โ”‚  - ่งฃๆž็”จๆˆทๆไพ›็š„ CSS                                        โ”‚            โ”‚
โ”‚  โ”‚  - ่งฃๆž <style> ๆ ‡็ญพไธญ็š„ CSS                                  โ”‚            โ”‚
โ”‚  โ”‚  - ้€’ๅฝ’่ฎก็ฎ—ๆฏไธชๅ…ƒ็ด ็š„ ComputedStyles                          โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚  6. ๆ ทๅผๅŒ– HTML                                                              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚                 Styled HTML Document                         โ”‚            โ”‚
โ”‚  โ”‚  Element(div, styles={...})                                 โ”‚            โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ Element(h1, styles={font_size: 24pt, ...})             โ”‚            โ”‚
โ”‚  โ”‚  โ”‚   โ””โ”€โ”€ Text("ๆ ‡้ข˜")                                        โ”‚            โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ ...                                                    โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚  7. ๅธƒๅฑ€้˜ถๆฎต                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚                    Layout Engine                             โ”‚            โ”‚
โ”‚  โ”‚  - ๆตๅผๅธƒๅฑ€่ฎก็ฎ—                                              โ”‚            โ”‚
โ”‚  โ”‚  - ๅˆ†้กตๅค„็†                                                  โ”‚            โ”‚
โ”‚  โ”‚  - ็”Ÿๆˆ Document ๅฏน่ฑก                                        โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚  8. ๆธฒๆŸ“้˜ถๆฎต                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚                    Document                                  โ”‚            โ”‚
โ”‚  โ”‚  - ้กต้ขๅˆ—่กจ                                                  โ”‚            โ”‚
โ”‚  โ”‚  - ่ง†่ง‰ๅ…ƒ็ด ๅˆ—่กจ                                              โ”‚            โ”‚
โ”‚  โ”‚  - ๅธƒๅฑ€ไฟกๆฏ                                                  โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚  9. ่พ“ๅ‡บ้˜ถๆฎต                                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚                    Renderer                                  โ”‚            โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ PDF Renderer (krilla)                                   โ”‚            โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ SVG Renderer (vello_cpu)                                โ”‚            โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ Pixmap Renderer (vello_cpu)                             โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### 5.2 ๆ ธๅฟƒ API ่ฎพ่ฎก


```rust
// src/lib.rs

pub mod html;
pub mod css;
pub mod layout;
pub mod render;

use html::{HtmlDocument, HtmlParser, MdToHtmlConverter};
use css::CssEngine;
use layout::LayoutEngine;
use render::{PdfRenderer, SvgRenderer, PixmapRenderer};

/// ไธป่ฝฌๆขๅ™จ
pub struct Liepress {
    css_engine: CssEngine,
    layout_engine: LayoutEngine,
}

impl Liepress {
    /// ๅˆ›ๅปบๆ–ฐ็š„่ฝฌๆขๅ™จๅฎžไพ‹
    pub fn new() -> Result<Self, LiepressError> {
        Ok(Self {
            css_engine: CssEngine::new()?,
            layout_engine: LayoutEngine::new(),
        })
    }
    
    /// ๆทปๅŠ ็”จๆˆท CSS
    pub fn with_css(mut self, css: &str) -> Result<Self, LiepressError> {
        self.css_engine = self.css_engine.with_user_css(css)?;
        Ok(self)
    }
    
    /// ๅฐ† Markdown ่ฝฌๆขไธบ PDF
    pub fn markdown_to_pdf(&self, markdown: &str) -> Result<PdfDocument, LiepressError> {
        // 1. ่งฃๆž Markdown
        let mdast = markdown::to_mdast(markdown, &ParseOptions::gfm())?;
        
        // 2. ่ฝฌๆขไธบ HTML
        let html_doc = MdToHtmlConverter::convert(&mdast)?;
        
        // 3. ๆทปๅŠ  <style> ๆ ‡็ญพไธญ็š„ CSS
        for style in &html_doc.style_sheets {
            self.css_engine.add_author_css(style)?;
        }
        
        // 4. ่ฎก็ฎ—ๆ ทๅผ
        let styled_doc = self.apply_styles(html_doc)?;
        
        // 5. ๅธƒๅฑ€
        let document = self.layout_engine.layout(styled_doc)?;
        
        // 6. ๆธฒๆŸ“
        PdfRenderer::render(&document)
    }
    
    /// ๅฐ† Markdown ่ฝฌๆขไธบ SVG
    pub fn markdown_to_svg(&self, markdown: &str) -> Result<SvgDocument, LiepressError> {
        // ็ฑปไผผๅฎž็Žฐ...
        todo!()
    }
    
    /// ๅบ”็”จๆ ทๅผๅˆฐ HTML ๆ–‡ๆกฃ
    fn apply_styles(&self, doc: HtmlDocument) -> Result<StyledDocument, LiepressError> {
        let mut styled_root = StyledElement::from(doc.root);
        self.style_element_recursive(&mut styled_root, None)?;
        Ok(StyledDocument::new(styled_root))
    }
    
    fn style_element_recursive(
        &self,
        element: &mut StyledElement,
        parent_styles: Option<&ComputedStyles>,
    ) -> Result<(), LiepressError> {
        // ่ฎก็ฎ—ๅฝ“ๅ‰ๅ…ƒ็ด ๆ ทๅผ
        let computed = self.css_engine.compute_styles(&element.element, parent_styles);
        
        // ๅบ”็”จๆ ทๅผ
        element.styles = computed.clone();
        
        // ้€’ๅฝ’ๅค„็†ๅญๅ…ƒ็ด 
        for child in &mut element.children {
            if let Some(el) = child.as_element_mut() {
                self.style_element_recursive(el, Some(&computed))?;
            }
        }
        
        Ok(())
    }
}
```

---

## 6. ๅฎž็Žฐ่ง„ๅˆ’


### 6.1 ้˜ถๆฎตๅˆ’ๅˆ†


```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                          ๅฎž็Žฐ้˜ถๆฎต่ง„ๅˆ’                                        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚  ้˜ถๆฎต 1๏ผšๅŸบ็ก€ๆžถๆž„๏ผˆ2-3 ๅ‘จ๏ผ‰                                                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  โœ“ ๅˆ›ๅปบ src/html/ ๆจกๅ—                                               โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๅฎšไน‰ HTML AST ็ป“ๆž„๏ผˆast.rs๏ผ‰                                      โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๅฎž็Žฐ HTML ๆ ‡็ญพๆžšไธพๅ’Œๅทฅๅ…ทๆ–นๆณ•                                       โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๅˆ›ๅปบ src/css/ ๆจกๅ—็ป“ๆž„                                            โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆทปๅŠ  lightningcss ไพ่ต–                                            โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๅฎšไน‰ ComputedStyles ็ป“ๆž„                                          โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                    โ”‚                                        โ”‚
โ”‚                                    โ–ผ                                        โ”‚
โ”‚  ้˜ถๆฎต 2๏ผšMarkdown โ†’ HTML ่ฝฌๆข๏ผˆ2 ๅ‘จ๏ผ‰                                        โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  โœ“ ๅฎž็Žฐ MdToHtmlConverter                                            โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆ”ฏๆŒๆ‰€ๆœ‰ Markdown ๅŸบ็ก€่ฏญๆณ•่ฝฌๆข                                     โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๅฎž็Žฐๅ†…่” HTML ่งฃๆž                                                โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆๅ– <style> ๆ ‡็ญพๅ†…ๅฎน                                             โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ็ผ–ๅ†™่ฝฌๆขๆต‹่ฏ•                                                      โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                    โ”‚                                        โ”‚
โ”‚                                    โ–ผ                                        โ”‚
โ”‚  ้˜ถๆฎต 3๏ผšCSS ๆ ทๅผ็ณป็ปŸ๏ผˆ3 ๅ‘จ๏ผ‰                                                โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  โœ“ ๅฎž็Žฐ CssEngine๏ผˆๅŸบไบŽ Lightning CSS๏ผ‰                              โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๅฎž็Žฐ LightningCssAdapter                                          โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆ”ฏๆŒๅŸบ็ก€้€‰ๆ‹ฉๅ™จ๏ผˆๆ ‡็ญพใ€็ฑปใ€ID๏ผ‰                                     โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆ”ฏๆŒๅธธ็”จ CSS ๅฑžๆ€ง                                                 โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๅฎž็Žฐๆ ทๅผ็ปงๆ‰ฟๅ’Œๅฑ‚ๅ                                                 โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๅ•ไฝ่ฝฌๆข๏ผˆpxโ†’pt, em, rem, %๏ผ‰                                     โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ็ผ–ๅ†™ๆ ทๅผๆต‹่ฏ•                                                      โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                    โ”‚                                        โ”‚
โ”‚                                    โ–ผ                                        โ”‚
โ”‚  ้˜ถๆฎต 4๏ผšๅธƒๅฑ€ๅผ•ๆ“Ž้‡ๆž„๏ผˆ2 ๅ‘จ๏ผ‰                                                โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  โœ“ ้€‚้…ๆ–ฐ็š„ StyledDocument ็ป“ๆž„                                      โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ้‡ๆž„ๆ–‡ๆœฌๅธƒๅฑ€๏ผˆๆ”ฏๆŒๆ–ฐ็š„ ComputedStyles๏ผ‰                           โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ้‡ๆž„ๅ—็บงๅ…ƒ็ด ๅธƒๅฑ€                                                  โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ไฟๆŒ็Žฐๆœ‰ๅˆ†้กต้€ป่พ‘                                                  โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ไฟๆŒ่กจๆ ผๅธƒๅฑ€                                                      โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                    โ”‚                                        โ”‚
โ”‚                                    โ–ผ                                        โ”‚
โ”‚  ้˜ถๆฎต 5๏ผšHTML ๆ ‡็ญพๆ”ฏๆŒ๏ผˆ2 ๅ‘จ๏ผ‰                                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  โœ“ ๅฎž็Žฐ HTML ่งฃๆžๅ™จ๏ผˆๆ”ฏๆŒ HTML ๅญ้›†๏ผ‰                                  โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆ”ฏๆŒๆ‰€ๆœ‰ๅฎšไน‰็š„ HTML ๆ ‡็ญพ                                            โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆ”ฏๆŒๆ ‡็ญพๅฑžๆ€ง๏ผˆclass, id, style๏ผ‰                                    โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆ”ฏๆŒๅตŒๅฅ— HTML ็ป“ๆž„                                                  โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ็ผ–ๅ†™ HTML ่งฃๆžๆต‹่ฏ•                                                  โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                    โ”‚                                        โ”‚
โ”‚                                    โ–ผ                                        โ”‚
โ”‚  ้˜ถๆฎต 6๏ผš้›†ๆˆไธŽไผ˜ๅŒ–๏ผˆ2-3 ๅ‘จ๏ผ‰                                                โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  โœ“ ๆ•ดๅˆๆ‰€ๆœ‰ๆจกๅ—                                                        โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆ€ง่ƒฝไผ˜ๅŒ–                                                            โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๅฎŒๆ•ด้›†ๆˆๆต‹่ฏ•                                                        โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ๆ–‡ๆกฃๆ›ดๆ–ฐ                                                            โ”‚   โ”‚
โ”‚  โ”‚  โœ“ ่ฟ็งปๆŒ‡ๅ—                                                            โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                                             โ”‚
โ”‚  ้ข„่ฎกๆ€ปๅทฅๆœŸ๏ผš11-13 ๅ‘จ                                                       โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

### 6.2 ่ฟ็งป็ญ–็•ฅ


#### 6.2.1 ๅ‘ๅŽๅ…ผๅฎนๆ€ง


```rust
// src/lib.rs

/// ๆธฒๆŸ“ Markdown๏ผˆๅ…ผๅฎนๆ—ง API๏ผ‰
pub fn render_markdown(input: &str, options: &RenderOptions) -> Result<Document, Error> {
    // ไฝฟ็”จๆ–ฐ็š„ HTML ๅญ้›†ๆžถๆž„
    let html_doc = MarkdownToHtmlConverter::convert(input)?;
    let styled_doc = CssEngine::compute_styles(html_doc, &options.css)?;
    Document::from_styled_html(styled_doc, options)
}

/// ๆธฒๆŸ“ Markdown๏ผˆๆ–ฐ API๏ผŒๆ”ฏๆŒๆ›ดๅคšๆŽงๅˆถ๏ผ‰
pub fn render_html(html: &str, options: &HtmlRenderOptions) -> Result<Document, Error> {
    let html_doc = HtmlParser::parse(html)?;
    let styled_doc = CssEngine::compute_styles(html_doc, &options.css)?;
    Document::from_styled_html(styled_doc, &options.into())
}
```

#### 6.2.2 ็‰นๆ€งๅผ€ๅ…ณ


```toml
# Cargo.toml


[features]
default = ["html-subset"]
html-subset = ["lightningcss"]
legacy-mode = []  # ไฟ็•™ๆ—งๆžถๆž„็”จไบŽๅ›ž้€€
```

#### 6.2.3 ๆธ่ฟ›ๅผ่ฟ็งปๆญฅ้ชค


1. **้˜ถๆฎต 1**๏ผšๆ–ฐๆžถๆž„ไฝœไธบ็‹ฌ็ซ‹ๆจกๅ—ๅผ€ๅ‘๏ผŒไธๅฝฑๅ“็Žฐๆœ‰ไปฃ็ 
2. **้˜ถๆฎต 2**๏ผšๆทปๅŠ  `render_html` ๆ–ฐ API๏ผŒๆ—ง API ไฟๆŒไธๅ˜
3. **้˜ถๆฎต 3**๏ผšๅ†…้ƒจๅฎž็Žฐๅˆ‡ๆขๅˆฐๆ–ฐๆžถๆž„๏ผŒไฟๆŒ API ๅ…ผๅฎน
4. **้˜ถๆฎต 4**๏ผšๅบŸๅผƒๆ—ง API๏ผŒๆไพ›่ฟ็งปๆŒ‡ๅ—
5. **้˜ถๆฎต 5**๏ผšๅฎŒๅ…จ็งป้™คๆ—งๆžถๆž„ไปฃ็ 

### 6.3 ้ฃŽ้™ฉ่ฏ„ไผฐ


| ้ฃŽ้™ฉ | ๅฏ่ƒฝๆ€ง | ๅฝฑๅ“ | ็ผ“่งฃๆŽชๆ–ฝ |
|------|--------|------|----------|
| Lightning CSS ไพ่ต–้—ฎ้ข˜ | ไฝŽ | ้ซ˜ | ๅ‡†ๅค‡ๅค‡็”จ CSS ่งฃๆžๆ–นๆกˆ |
| ๆ€ง่ƒฝไธ‹้™ | ไธญ | ไธญ | ๆ—ฉๆœŸๆ€ง่ƒฝๅŸบๅ‡†ๆต‹่ฏ•๏ผŒๅฟ…่ฆๆ—ถไผ˜ๅŒ– |
| ๅ…ผๅฎนๆ€ง้—ฎ้ข˜ | ไธญ | ้ซ˜ | ๅฎŒๆ•ด็š„ๅ›žๅฝ’ๆต‹่ฏ•ๅฅ—ไปถ |
| ๅผ€ๅ‘ๅปถๆœŸ | ไธญ | ไธญ | ๅˆ†้˜ถๆฎตไบคไป˜๏ผŒไผ˜ๅ…ˆๆ ธๅฟƒๅŠŸ่ƒฝ |

### 6.4 ๆˆๅŠŸๆ ‡ๅ‡†


1. **ๅŠŸ่ƒฝๅฎŒๆ•ดๆ€ง**
   - ๆ”ฏๆŒๆ‰€ๆœ‰ๅฎšไน‰็š„ HTML ๅญ้›†ๆ ‡็ญพ
   - ๆ”ฏๆŒๆ‰€ๆœ‰ๅฎšไน‰็š„ CSS ๅฑžๆ€ง
   - 100% ๅ‘ๅŽๅ…ผๅฎน็Žฐๆœ‰ Markdown ๅŠŸ่ƒฝ

2. **ๆ€ง่ƒฝๆŒ‡ๆ ‡**
   - ๆธฒๆŸ“้€ŸๅบฆไธไฝŽไบŽๅฝ“ๅ‰็‰ˆๆœฌ
   - ๅ†…ๅญ˜ไฝฟ็”จๅขž้•ฟไธ่ถ…่ฟ‡ 20%

3. **ไปฃ็ ่ดจ้‡**
   - ๆต‹่ฏ•่ฆ†็›–็އ > 80%
   - ๆ—  Clippy ่ญฆๅ‘Š
   - ๆ–‡ๆกฃๅฎŒๆ•ด

---

## ้™„ๅฝ•


### A. ๅ‚่€ƒ่ต„ๆบ


- [Lightning CSS ๆ–‡ๆกฃ]https://lightningcss.dev/
- [CommonMark ่ง„่Œƒ]https://spec.commonmark.org/
- [CSS Selectors Level 4]https://www.w3.org/TR/selectors-4/
- [CSS Box Model]https://www.w3.org/TR/CSS22/box.html

### B. ็›ธๅ…ณ crate


- `markdown` - Markdown ่งฃๆž
- `lightningcss` - CSS ่งฃๆžๅ’Œๅค„็†
- `roxmltree` - XML/HTML ่งฃๆž๏ผˆๅฏ้€‰๏ผ‰
- `selectors` - CSS ้€‰ๆ‹ฉๅ™จๅŒน้…๏ผˆๅฆ‚ Lightning CSS ไธๆปก่ถณ้œ€ๆฑ‚๏ผ‰

### C. ็คบไพ‹ Markdown + HTML


```markdown
# ๆ–‡ๆกฃๆ ‡้ข˜


<div style="text-align: center; color: #666;">

## ๅฑ…ไธญๅ‰ฏๆ ‡้ข˜


่ฟ™ๆ˜ฏๅฑ…ไธญๆ˜พ็คบ็š„ๅ†…ๅฎนใ€‚

</div>

ๆ™ฎ้€šๆฎต่ฝใ€‚<span style="color: red;">็บข่‰ฒๆ–‡ๅญ—</span> ๅ’Œ **ๅŠ ็ฒ—ๆ–‡ๅญ—**ใ€‚

<br/>

ๅผบๅˆถๆข่กŒๅŽ็š„ๅ†…ๅฎนใ€‚

<div class="warning-box" style="background: #fff3cd; padding: 10px; border-left: 4px solid #ffc107;">
โš ๏ธ ่ญฆๅ‘Š๏ผš่ฟ™ๆ˜ฏไธ€ไธช่ญฆๅ‘Šๆก†
</div>
```

---

*ๆ–‡ๆกฃ็‰ˆๆœฌ๏ผš1.0*
*ๆœ€ๅŽๆ›ดๆ–ฐ๏ผš2026-06-01*
โ”‚  โ”‚