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
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
mod line_type;
pub mod utilities;

use line_type::{block_line_type, HtmlType, LineType};

use std::{
    collections::HashMap,
    fs::File,
    io::{BufRead, BufReader, Error},
    path::Path,
};

// for testing

// for converting
#[derive(Debug, Clone)]
struct NodeData {
    // h1/p/pre/etc
    // plain text is none
    tag: String,

    // any misc data, depends on teh tag
    misc: Option<String>,
    // the raw data inside this node
    text: Option<String>,

    contents: Vec<NodeData>,
}

#[derive(Debug, Clone)]
struct ReferenceLink {
    reference: String,
    url: String,
    title: Option<String>,
}

#[derive(Debug)]
pub struct Converter {
    html_void: Vec<String>,
    references: HashMap<String, ReferenceLink>,
    indentation: usize,
}
// takes the link provided, converts it
impl Converter {
    pub fn new(html_void: Vec<String>, indentation: usize) -> Self {
        Converter { html_void, references: Default::default(), indentation }
    }

    // this manages the conversion
    pub fn convert_file(&mut self, input: &Path, depth: usize) -> Result<String, Error> {
        // read file into memory
        let lines = self.file_read(input)?;

        // grab the reference lines out of it
        let lines_processed_references = self.reference_link_get(lines);

        // get teh block elements
        let blocks = self.block_process(lines_processed_references)?;

        // merge it all together
        let processed = self.block_merge(blocks, depth);

        // clean up references
        self.references = Default::default();

        Ok(processed)
    }

    // load the file into working memory
    fn file_read(&self, path: &Path) -> Result<Vec<String>, Error> {
        // read file into memory
        //println!("In file {}", path);
        // read the file into memory
        let input = File::open(path)?;
        let buffered = BufReader::new(input);

        let lines_all = buffered
            .lines()
            .map(|l| {
                let unwrapped = l.expect("Could not parse line");
                unwrapped.replace('\u{0000}', "\u{FFFD}")
            })
            .collect::<Vec<String>>();

        Ok(lines_all)
    }

    fn reference_link_get(&mut self, lines: Vec<String>) -> Vec<String> {
        let mut result: Vec<String> = vec![];

        // iterate through the lines
        // if one matches the format it is not added to the result and added to teh link hash, if its not already there

        let mut references: HashMap<String, ReferenceLink> = HashMap::new();

        'outer: for line in lines {
            // only lines that start with [ are considered reference, number of spaces is irrelevant
            if !line.trim_start().starts_with('[') {
                result.push(line);
                continue;
            }

            // now check of the rest of the line matches

            // form manging position
            let characters: Vec<char> = line.trim_start().chars().collect();
            // starts at 1 to skip the first [
            let mut index_char = 1;

            // for getting the identifier
            let mut reference_vec: Vec<char> = vec![];
            loop {
                if index_char >= characters.len() {
                    break;
                }

                let character = characters[index_char];

                match character {
                    ']' => {
                        // check if last character is a backslash
                        if characters[index_char - 1] == '\\' {
                            // remove teh slash
                            // add the bracket
                            reference_vec.pop();
                            reference_vec.push(character);
                        } else {
                            // increment to account for this
                            index_char += 1;
                            break;
                        }
                    }
                    _ => reference_vec.push(character),
                }
                index_char += 1;
            }

            // need to have an identifier
            if reference_vec.is_empty() {
                result.push(line);
                continue 'outer;
            }

            // check if next character is ':' (required)
            if index_char >= characters.len() {
                result.push(line);
                continue 'outer;
            }
            if characters[index_char] != ':' {
                // add to normal output
                result.push(line);
                continue 'outer;
            } else {
                // if ir is :
                index_char += 1;
            }

            // check if next character is whitespace, skip past these
            loop {
                if index_char >= characters.len() {
                    break;
                }
                let character = characters[index_char];

                if character == ' ' || character == '\t' {
                    index_char += 1;
                } else {
                    break;
                }
            }

            // now get teh url
            let mut url_vec: Vec<char> = vec![];
            // (start, end)
            let mut angle_brackets = (false, false);
            loop {
                if index_char >= characters.len() {
                    break;
                }
                let character = characters[index_char];

                match character {
                    '<' => {
                        // opening is only allowed on teh first chr
                        if !angle_brackets.0 {
                            angle_brackets = (true, false);
                        } else {
                            url_vec.push(character)
                        }
                    }
                    '>' => {
                        // check if it was opened
                        if angle_brackets.0 {
                            // then this closes it out

                            // check if its preceded by backslash, its action is ignored
                            if characters[index_char - 1] == '\\' {
                                // remove teh slash
                                url_vec.pop();
                                url_vec.push(character);
                            } else {
                                // actually closes it out
                                angle_brackets = (true, true);

                                index_char += 1;
                                break;
                            }
                        } else {
                            url_vec.push(character);
                        }
                    }
                    ' ' | '\t' => {
                        // space breaks the url, unless its in an angled bracket

                        if angle_brackets.0 {
                            url_vec.push(character)
                        } else {
                            break;
                        }
                    }

                    _ => url_vec.push(character),
                }

                index_char += 1;
            }

            if url_vec.is_empty() {
                // check if its angle brackets
                if !angle_brackets.1 {
                    result.push(line);
                    continue 'outer;
                }
            }

            // if angle brackets were opened but never closed
            if angle_brackets.0 && !angle_brackets.1 {
                result.push(line);
                continue 'outer;
            }

            // check for whitespace again, but this time it must be at least 1 if its followed by an open quotation
            let mut whitespace = 0;
            loop {
                if index_char >= characters.len() {
                    break;
                }
                let character = characters[index_char];

                match character {
                    ' ' | '\t' => {
                        index_char += 1;
                        whitespace += 1;
                    }
                    '\'' | '"' => {
                        if whitespace == 0 {
                            result.push(line);
                            continue 'outer;
                        } else {
                            break;
                        }
                    }
                    _ => break,
                }
            }

            // find the optional title next

            // first char must be either ' or "

            let mut title_quote: Option<char> = None;
            if index_char < characters.len() {
                let character = characters[index_char];
                match character {
                    '\'' | '"' => title_quote = Some(character),
                    _ => {}
                }
                index_char += 1;
            }

            let mut title_vec: Vec<char> = vec![];

            if let Some(delimiter) = title_quote {
                // starts off being opened
                let mut title_closed = false;

                loop {
                    if index_char >= characters.len() {
                        break;
                    }
                    let character = characters[index_char];

                    if character == delimiter {
                        // check if preceding was backslash

                        if characters[index_char - 1] == '\\' {
                            // remove teh slash
                            // add the bracket
                            title_vec.pop();
                            title_vec.push(character);
                        } else {
                            title_closed = true;

                            // increment to account for this
                            //index_char += 1;
                            break;
                        }
                    } else {
                        title_vec.push(character)
                    }

                    index_char += 1;
                }

                // check if it was closed properly
                if !title_closed {
                    // title is optional so just clear it instead of revoking teh line
                    title_vec = vec![];
                }
            }

            // tidy up
            let reference: String = reference_vec.iter().collect();
            let url: String = url_vec.iter().collect();

            let title: Option<String> = if title_vec.is_empty() { None } else { Some(title_vec.iter().collect()) };

            let reference_data = ReferenceLink { reference: reference.clone(), url, title };

            references.insert(reference, reference_data);
        }

        self.references = references;

        result
    }

    fn block_process(&self, lines: Vec<String>) -> Result<Vec<NodeData>, Error> {
        // this gets most of the structure done

        // what gets returned
        let mut node_data: Vec<NodeData> = vec![];

        // these handle dealing with teh current lines
        let mut row: isize = 0;

        // These keep track of info about the current block
        let mut block_excluded: Vec<String> = vec![];

        // (row, col)
        let mut html_end_col = 0;

        loop {
            // ensure that row is in bounds
            if row >= lines.len() as isize {
                break;
            }

            let line = if html_end_col != 0 { &lines[row as usize][html_end_col..] } else { lines[row as usize].as_str() };

            //println!("Start:  Top: {}. Row {} of {}. Block: {:?}, Current Line: {}. Line: {}. End?: {}", _top_layer, row, lines.len(), block_type, line_current_type.0, line, line_current_is_end);

            // an array of this line and all the remaining lines to be sent off to the sub functions
            let lines_remaining = &lines[(row as usize)..];

            // partial is for paragraphs and html
            let mut lines_remaining_partial = vec![line.to_string()];

            if ((row as usize) + 1) < lines.len() {
                let remainder = &lines[((row as usize) + 1)..];
                lines_remaining_partial.extend(remainder.to_vec());
            }

            let mut clean_up = false;
            // now process based on what type of line it is
            match block_line_type(line, &block_excluded) {
                LineType::Header => {
                    node_data.push(self.block_process_headers(line));

                    // go straight to the next row
                    row += 1;

                    clean_up = true;
                }
                LineType::HorizontalRule => {
                    /*
                        hr are simple, no content or anything.
                    */

                    node_data.push(NodeData { tag: "hr".to_string(), text: None, misc: None, contents: vec![] });

                    // go straight to the next row
                    row += 1;

                    clean_up = true;
                }

                // blocks from here on out
                LineType::Paragraph => {
                    if line.is_empty() {
                        row += 1;
                        continue;
                    }

                    if let Some((node, offset)) = self.block_process_paragraph(&lines_remaining_partial, 0, &block_excluded) {
                        node_data.push(node);

                        row += offset;

                        clean_up = true;
                    } else {
                        block_excluded.push("p".to_string());
                    }
                }
                LineType::Preformatted => {
                    if let Some((node, offset)) = self.block_process_pre(lines_remaining) {
                        node_data.push(node);

                        // +1 as to not include the closing fence
                        row += offset + 1;

                        clean_up = true;
                    } else {
                        block_excluded.push("pre".to_string());
                    }
                }

                LineType::BlockQuote => {
                    if let Some((node, offset)) = self.block_process_blockquote(lines_remaining) {
                        node_data.push(node);

                        row += offset;

                        clean_up = true;
                    } else {
                        block_excluded.push("blockquote".to_string());
                    }
                }

                LineType::UL(_, _) | LineType::OL(_, _) => {
                    if let Some((node, offset)) = self.block_process_lists(lines_remaining) {
                        node_data.push(node);

                        row += offset;

                        clean_up = true;
                    } else {
                        block_excluded.push("ul".to_string());
                    }
                }

                LineType::Html(html_type) => {
                    if let Some((node, offset, col)) = self.block_process_html(&lines_remaining_partial, html_type) {
                        node_data.push(node);

                        if col > 0 {
                            // repeat teh current line
                            row += offset - 1;
                            html_end_col = col;
                        } else {
                            row += offset;
                            html_end_col = 0;
                        }

                        // clear the excluded blocks because this completed successfully
                        block_excluded = vec![];
                    } else {
                        match html_type {
                            HtmlType::Normal => {
                                block_excluded.push("html".to_string());
                            }
                            HtmlType::Comment => {
                                block_excluded.push("html_comment".to_string());
                            }
                            HtmlType::CData => {
                                block_excluded.push("html_cdata".to_string());
                            }
                        }
                    }
                    // either way continue to the next/same row
                    continue;
                }

                LineType::Table => {
                    if let Some((node, offset)) = self.block_process_table(lines_remaining) {
                        node_data.push(node);

                        row += offset;

                        clean_up = true;
                    } else {
                        block_excluded.push("table".to_string());
                    }
                }
            }

            // this is the clean up for everything but html
            if clean_up {
                // clean up
                block_excluded = vec![];
                html_end_col = 0;

                continue;
            }

            // this is to catch anything that somehow slipped through
            row += 1;
        }
        Ok(node_data)
    }

    fn block_process_headers(&self, line: &str) -> NodeData {
        /*
            Headers are pretty easy to process.
            Strip leading whitespace.
            Count how many #'s there are at the start
            This either caps at 6 or when there is a non # character
            Anything after the last #] is counted as content
        */

        let mut count = 0;
        let mut broken = false;
        let mut content_array: Vec<char> = vec![];
        for character in line.trim().chars() {
            match character {
                '#' => {
                    if !broken && count < 6 {
                        count += 1
                    } else {
                        content_array.push(character);
                    }
                }
                _ => {
                    broken = true;
                    content_array.push(character);
                }
            }
        }

        // for this the tag is depending on the number of #'s at the beginning
        let tag = format!("h{}", &count);

        // content is everything after the break
        let content_string = content_array.to_vec().iter().collect::<String>();
        let text = Some(content_string.as_str().trim().to_string());

        NodeData { tag, text, misc: None, contents: vec![] }
    }

    fn block_process_pre(&self, lines: &[String]) -> Option<(NodeData, isize)> {
        /*
            All pre blocks are fenced.
            They start with at least 3 backticks (`)and an optional language identifier.
            They close out with an equal number of backticks as the opener

            Opening square brackets '<' are replaced with '&lt;'.

            Everything inside is preformatted text and no further processing is done.
        */

        let line_first = &lines[0];

        // get the language
        let mut pre_language_tmp: Vec<char> = vec![];
        let mut closer: Vec<char> = vec![];
        let mut space = false;
        for character in line_first.trim().chars() {
            match character {
                // skip this one
                '`' => {
                    if !space {
                        closer.push(character)
                    }

                    continue;
                }
                ' ' | '\t' => {
                    // first one mark it as a space
                    if !space {
                        space = true;
                    } else {
                        pre_language_tmp.push(character);
                    }
                }
                _ => {
                    pre_language_tmp.push(character);
                }
            }
        }

        let pre_language = if pre_language_tmp.is_empty() {
            None
        } else {
            let language = pre_language_tmp.iter().collect::<String>().trim().to_string();
            if language.is_empty() {
                None
            } else {
                Some(language)
            }
        };

        // set the closer it is looking for
        let pre_closer = closer.iter().collect::<String>().trim().to_string();

        // start on the second row
        let mut row = 1;

        let mut block_lines = vec![];
        let mut finished = false;
        loop {
            if row >= lines.len() as isize {
                break;
            }
            let line = &lines[row as usize];

            if line.trim() == pre_closer.as_str() {
                // end of block, now tidy up
                finished = true;
                break;
            } else {
                // add the lines to teh block
                block_lines.push(line.clone());

                // if its the last line then its caught alter down
            }
            row += 1;
        }

        // if successful it delivers teh NodeData and the offset, failure is None

        if finished {
            let text = block_lines.join("\n").replace('<', "&lt;").replace('>', "&gt;");
            let node = NodeData { tag: "pre".to_string(), text: Some(text), misc: pre_language, contents: vec![] };
            Some((node, row))
        } else {
            None
        }
    }

    fn block_process_blockquote(&self, lines: &[String]) -> Option<(NodeData, isize)> {
        /*
            Like Paragraphs, Blockquotes dont have a failure condition.
            Also it is one of the few blocks that can have other blocks inside itself
            This is because lazy continuation is not allowed each like starts with >

            The first > is stripped off of each line and the result is added to an array.
            On the final row with a > the contents are recursively added back into the block_process function.
        */

        let mut row = 0;

        let mut block_lines = vec![];
        loop {
            if row >= lines.len() as isize {
                break;
            }
            let line = &lines[row as usize];

            // > indicates that it is a blockquote, >! indicates a spoiler
            if line.starts_with('>') && !line.starts_with(">!") {
                let cleaned = line.replacen('>', "", 1).replacen(' ', "", 1);
                block_lines.push(cleaned);
            } else {
                break;
            }

            row += 1;
        }

        if !block_lines.is_empty() {
            let contents = self
                .block_process(block_lines)
                // if it errors then fail fairly gracefully
                .unwrap_or_default();

            let node = NodeData { tag: "blockquote".to_string(), text: None, misc: None, contents };

            Some((node, row))
        } else {
            None
        }
    }

    fn block_process_table(&self, lines: &[String]) -> Option<(NodeData, isize)> {
        /*
            Mostly taken from https://github.github.com/gfm/#tables-extension- with a few changes:
            First character on a line is always |, while a trailing | isn't explicitly required it can look better.

            The delimiter line can occur anywhere, even before the header.
            This is because it is used to set the alignment.
        */

        let mut table_rows = vec![];
        let mut table_alignment: HashMap<i32, String> = HashMap::new();
        let mut table_header_length = 0;

        let mut row = 0;
        loop {
            if row >= lines.len() as isize {
                break;
            }
            let line = &lines[row as usize];

            // break early if its not a table
            if !line.trim().starts_with('|') {
                break;
            }

            // deal with alignment rows first
            if line.replace('|', "").replace('-', "").replace(':', "").trim() == "" {
                // will use https://developer.mozilla.org/en-US/docs/Web/CSS/text-align as the way github does it is no longer valid

                // alignment will impact subsequent lines, unless overwritten
                table_alignment = self.block_process_table_alignment(line);

                row += 1;
                continue;
            }

            let mut row_contents: Vec<NodeData> = vec![];
            let mut content: Vec<char> = vec![];
            let mut last_character: Option<char> = None;
            let mut current_col = 0;

            // first row has cols with th, every other row is td
            let tag_col = if table_rows.is_empty() { "th".to_string() } else { "td".to_string() };

            let tag_row = "tr".to_string();

            for character in line.trim_start().trim_end_matches('|').chars() {
                match character {
                    '|' => {
                        if let Some(x) = last_character {
                            if x == '\\' {
                                // remove the backslash
                                content.pop();
                                content.push(character);
                                last_character = Some(character);
                                continue;
                            }
                        }

                        if current_col > 0 {
                            let text: String = content.iter().collect();
                            let alignment = table_alignment.get(&(current_col as i32)).cloned();

                            // add current
                            row_contents.push(NodeData { tag: tag_col.clone(), misc: alignment, text: Some(text), contents: vec![] });
                        }

                        // clear teh existing data (since its previously used
                        content = vec![];

                        // mark it as opening another col
                        current_col += 1;

                        if table_rows.is_empty() {
                            table_header_length = current_col;
                        } else if current_col > table_header_length {
                            // if it isn't the header check if the new number exceeds what teh header gave
                            break;
                        }
                    }
                    _ => content.push(character),
                }
                last_character = Some(character);
            }

            // tidy up any trailing content
            if !content.is_empty() {
                let text: String = content.iter().collect();
                let alignment = table_alignment.get(&(current_col as i32)).cloned();

                // add current
                row_contents.push(NodeData { tag: tag_col.clone(), misc: alignment, text: Some(text), contents: vec![] });
            }

            table_rows.push(NodeData { tag: tag_row, misc: None, text: None, contents: row_contents });

            row += 1;
        }

        if !table_rows.is_empty() {
            let table_header = vec![table_rows[0].clone()];

            let table_body = if table_rows.len() > 1 { table_rows[1..].to_vec() } else { vec![] };

            let table = NodeData {
                tag: "table".to_string(),
                misc: None,
                text: None,
                contents: vec![NodeData { tag: "thead".to_string(), misc: None, text: None, contents: table_header }, NodeData { tag: "tbody".to_string(), misc: None, text: None, contents: table_body }],
            };

            Some((table, row))
        } else {
            None
        }
    }

    fn block_process_lists(&self, lines: &[String]) -> Option<(NodeData, isize)> {
        /*
            All types of lists are comprised of li elements.
            These li can contain other blocks.
            Because of this it makes it a tad trickier to process compared to other blocks.

            Thankfully since there is no lazy continuation there are two ways to see if a line is part of a li.
                1. It is the first line of a li.
                2. It has an indent specified by the first line of the li.

            Like blockquotes the li contents are recursively proceed in the block_process function.

        */

        // manage teh current li
        let mut li_active = false;
        let mut li_number: Option<String> = None;
        let mut li_type = LineType::Paragraph;
        let mut li_indent = 0;
        // current lines in teh list item, list items can have other blocks inside them
        let mut li_lines = vec![];
        let mut li_finished = false;

        let mut li_array = vec![];

        let mut row = 0;
        loop {
            let mut finished = false;

            if row >= lines.len() as isize {
                break;
            }
            let line = &lines[row as usize];

            let list_type = block_line_type(line, &[]);

            if !li_active {
                // deal with first line of a li

                match list_type {
                    LineType::OL(indent, number) => {
                        li_indent = indent;
                        li_number = Some(number.to_string());
                    }
                    LineType::UL(indent, _) => {
                        li_indent = indent;
                    }
                    _ => {}
                };

                let vec_chars: Vec<char> = line.chars().collect();
                // remove lists_indent's worth ofd characters
                let trimmed = &vec_chars[li_indent..];
                let cleaned = trimmed.iter().collect::<String>();

                li_lines.push(cleaned);
                li_type = list_type;

                // next round will not be on this branch of the if
                li_active = true;
            } else {
                // second line of the lists

                let leading_spaces = String::from_utf8(vec![b' '; li_indent]).unwrap_or_default();

                if line.starts_with(&leading_spaces) {
                    // if it starts with lists_indent spaces its staying in teh same li
                    let trimmed = line.replacen(' ', "", li_indent);
                    li_lines.push(trimmed);
                } else if line.is_empty() {
                    // close out teh existing list item
                    li_finished = true;
                    finished = true;
                } else if list_type == li_type {
                    // a li of the same type
                    li_finished = true;

                    // repeat the current line next time
                    row -= 1;
                } else {
                    // line is not part of the ul or li
                    // close out teh li and ul
                    li_finished = true;
                    finished = true;
                }
            }

            if (row + 1) >= lines.len() as isize {
                li_finished = true;
            }

            if li_finished {
                if li_lines.len() == 1 {
                    li_array.push(NodeData { tag: "li".to_string(), text: Some(li_lines[0].clone()), misc: li_number.clone(), contents: vec![] });
                } else {
                    let contents = self
                        .block_process(li_lines.clone())
                        // if it errors then fail fairly gracefully
                        .unwrap_or_default();

                    li_array.push(NodeData { tag: "li".to_string(), text: None, misc: li_number.clone(), contents });
                }

                // reset for next round
                li_finished = false;
                li_active = false;
                li_lines = vec![];
            }

            if finished {
                break;
            }

            row += 1;
        }

        if !li_array.is_empty() {
            let list_type = match li_number {
                None => "ul".to_string(),
                Some(_) => "ol".to_string(),
            };
            let node = NodeData { tag: list_type, text: None, misc: None, contents: li_array };

            Some((node, row))
        } else {
            None
        }
    }

    fn block_process_paragraph(&self, lines: &[String], row_start: isize, block_excluded: &[String]) -> Option<(NodeData, isize)> {
        /*
            Paragraphs are the catch all.
            If something does not fit in anything else its a paragraph.

            A paragraph ends on a blank like or the start of a new block.

            The extra parameters is due to the fact that some html can be considered part of a paragraph and to facilitate passthroughs.
            For example:
                <a href="">link</a> in paragraph


            Paragraphs have the advantage of having no failure, they don't need to search for a closer
        */

        let mut block_lines = lines[..(row_start as usize)].to_vec();

        let mut row = row_start;
        let mut first_run = true;
        loop {
            if row >= lines.len() as isize {
                break;
            }

            let line = &lines[row as usize];

            // // a line gap is instant break
            if line.is_empty() {
                break;
            }

            if block_lines.is_empty() {
                let line_to_push = if block_excluded.contains(&"html".to_string()) || block_excluded.contains(&"html_comment".to_string()) || block_excluded.contains(&"html_cdata".to_string()) {
                    // strip first < from it, &gt;
                    line.replacen('<', "&gt;", 1).to_string()
                } else {
                    line.to_string()
                };

                // add it to the tmp array
                block_lines.push(line_to_push);
            } else {
                match block_line_type(line, &[]) {
                    LineType::Paragraph => {}
                    _ => {
                        // if its not a paragraph and if its not the first run

                        if !first_run {
                            break;
                        }
                    }
                }

                block_lines.push(line.to_string());
            }

            first_run = false;
            row += 1;
        }

        if !block_lines.is_empty() {
            let node = NodeData { tag: 'p'.to_string(), text: Some(block_lines.join("\n")), misc: None, contents: vec![] };

            Some((node, row))
        } else {
            None
        }
    }

    fn block_process_html(&self, lines: &[String], html_type: HtmlType) -> Option<(NodeData, isize, usize)> {
        /*
            HTML blocks are identified by a line starting with:
                * <!--
                * <![CDATA[
                * < followed by any alphanumeric character
            Based on the identifier an opener and a closer are set.

            Both are set in order to handle nestled html:
                <div><div>inner content</div></div>


            Blocks can also end mid way through a line so keeping track of the last col is important for them:
                <div>first</div><div>second</div>


        */

        let opener;
        let closer;
        let tag;

        if !lines.is_empty() {
            if let Some((inner_tag, inner_opener, inner_closer)) = self.block_process_html_tags(&lines[0], html_type) {
                tag = inner_tag;
                opener = inner_opener;
                closer = inner_closer;
            } else {
                return None;
            }
        } else {
            return None;
        };

        let mut block_lines = vec![];

        let mut html_depth = 0;

        let mut row = 0;
        let mut index = 0;
        let mut html_end_col = 0;
        let mut finished = false;
        loop {
            if row >= lines.len() as isize {
                break;
            }
            let line = &lines[row as usize];

            // to get html blocks each row has to be scanned for both openers and closers

            // set the flags for this line
            let mut valid_chars_closing = 0;
            let mut valid_chars_opening = 0;
            // reset the index
            index = 0;

            let line_chars: Vec<char> = line.chars().collect();

            loop {
                if closer.is_empty() {
                    break;
                }
                if opener.is_empty() {
                    break;
                }
                if index >= line_chars.len() {
                    break;
                }

                let character = line_chars[index];

                // set it to be used next round
                index += 1;

                if opener[valid_chars_opening] == character {
                    // character is valid,
                    valid_chars_opening += 1;

                    if valid_chars_opening == opener.len() {
                        html_depth += 1;
                        valid_chars_opening = 0;
                    }
                } else {
                    // reset
                    valid_chars_opening = 0;
                }

                if closer[valid_chars_closing] == character {
                    // character is valid,
                    valid_chars_closing += 1;

                    if valid_chars_closing == closer.len() {
                        html_depth -= 1;
                        if html_depth == 0 {
                            finished = true;
                            break;
                        }
                        // reset it
                        valid_chars_closing = 0;
                    }
                } else {
                    // reset
                    valid_chars_closing = 0;
                }
            }

            if finished {
                break;
            } else {
                block_lines.push(line.to_string())
            }

            row += 1;
        }

        // its marked finished if its closed out properly
        if finished {
            let mut partial_line = false;
            let mut permitted_in_p = false;
            let forbidden_tag = false; // how handling forbidden tags would be

            let line = &lines[row as usize];

            // check if there is anything left on teh line
            if line[index..].trim() != "" {
                partial_line = true;

                // check if the tag is permitted in paragraphs
                // https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#phrasing_content
                // https://www.w3.org/TR/html52/dom.html#phrasing-content
                let allowed_tags_p = vec![
                    // pure html stuff
                    "abbr",
                    "audio",
                    "b",
                    "button",
                    "canvas",
                    "cite",
                    "code",
                    "data",
                    "datalist",
                    "dfn",
                    "em",
                    "embed",
                    "i",
                    "iframe",
                    "img",
                    "input",
                    "label",
                    "mark",
                    "math",
                    "meter",
                    "noscript",
                    "object",
                    "output",
                    "picture",
                    "progress",
                    "q",
                    "ruby",
                    "samp",
                    "script",
                    "select",
                    "small",
                    "span",
                    "string",
                    "sub",
                    "sup",
                    "svg",
                    "textarea",
                    "time",
                    "u",
                    "var",
                    "video",
                    "wbr",
                    // according to dn these are not always applicable
                    "a",
                    "del",
                    "ins",
                    "map",
                    // these require an itemprop attribute, however not looking for these
                    // "link", "mata",

                    // these are the "custom" tags for misc html stuff
                    "custom_comment",
                    "custom_cdata",
                ];

                if allowed_tags_p.contains(&tag.as_str()) {
                    permitted_in_p = true;
                }
            }

            // add list of forbidden tags here
            if forbidden_tag {
                // forbidden
            }

            // tidy up the closing of html here
            if partial_line {
                if permitted_in_p {
                    // change the type to paragraph

                    // switch over to paragraph, return that result
                    return if let Some((node, offset)) = self.block_process_paragraph(lines, row, &[]) {
                        Some((node, offset, 0))
                    } else {
                        // was not a code block, exclude it and try the same line again
                        None
                    };
                } else {
                    // the first part is always added to teh tmp array
                    let tmp_line = &line[..index];
                    block_lines.push(tmp_line.to_string());

                    // decide what to do with teh rest

                    // get the type of the remaining line
                    // if its html then its processed
                    // else it is completely skipped
                    let remaining = &line[index..];

                    if let LineType::Html(_) = block_line_type(remaining, &[]) {
                        html_end_col = index;
                    }
                }
            } else {
                // add whole line to teh array
                block_lines.push(line.to_string());
            }

            // close up the html tag

            let node = NodeData {
                tag: "html".to_string(),
                // gonna do no more processing on this, just going to pass it straight through
                text: Some(block_lines.join("\n")),
                misc: None,
                contents: vec![],
            };

            // +1 to include the last row
            Some((node, row + 1, html_end_col))
        } else {
            None
        }
    }

    fn block_process_html_tags(&self, line: &str, html_type: HtmlType) -> Option<(String, Vec<char>, Vec<char>)> {
        let mut opener;
        let mut closer;
        let tag;

        match html_type {
            HtmlType::Normal => {
                // type of tag isn't known here

                // this first line is to find the tag name
                let mut tag_vec: Vec<char> = vec![];

                // 1 to skip the opening < in teh first run
                let mut index = 1;
                let line_chars: Vec<char> = line.chars().collect();
                loop {
                    if index >= line_chars.len() {
                        break;
                    }

                    let character = line_chars[index];

                    // set it to be used next round
                    index += 1;
                    match character {
                        'a'..='z' | 'A'..='Z' | '0'..='9' => {
                            tag_vec.push(character);
                        }
                        _ => {
                            // not a valid tag character
                            break;
                        }
                    }
                }

                // not a valid tag
                if tag_vec.is_empty() {
                    // repeat teh current line, but not as a html tag
                    return None;
                }

                // use html_void to see what type of closing it has
                // if its in html_void then its />
                // else its </tag>

                tag = tag_vec.iter().collect();

                // check for nestled html
                // <div>1<div>2</div></div>
                //html_depth += 1;

                opener = vec!['<'];
                opener.extend(&tag_vec);

                // these are the self-closing tags
                if self.html_void.contains(&tag) {
                    closer = vec!['/', '>'];
                } else {
                    closer = vec!['<', '/'];
                    closer.extend(&tag_vec);
                    closer.push('>');
                }
            }
            HtmlType::Comment => {
                // -->
                opener = vec!['<', '!', '-', '-'];
                closer = vec!['-', '-', '>'];
                tag = "custom_comment".to_string();
            }
            HtmlType::CData => {
                // ]]>
                opener = vec!['<', '!', '[', 'C', 'D', 'A', 'T', 'A', '['];
                closer = vec![']', ']', '>'];
                tag = "custom_cdata".to_string();
            }
        }

        Some((tag, opener, closer))
    }

    fn block_process_table_alignment(&self, line: &str) -> HashMap<i32, String> {
        let mut alignment: HashMap<i32, String> = HashMap::new();

        let mut last_character: Option<char> = None;
        let mut start = false;
        let mut end = false;
        let mut counter = 0;
        for character in line.trim_end_matches('|').chars() {
            match character {
                '|' => {
                    // skip first character
                    if last_character.is_none() {
                        // dont forget to set it here
                        last_character = Some(character);
                        continue;
                    }

                    counter += 1;

                    if start && end {
                        alignment.insert(counter, "center".to_string());
                    } else if start {
                        alignment.insert(counter, "left".to_string());
                    } else if end {
                        alignment.insert(counter, "right".to_string());
                    } else {
                        // dont insert
                    }

                    // reset for next one
                    start = false;
                    end = false;
                }
                ':' => {
                    // if preceded by a space or bar then its a start

                    // if preceded by - then its a end

                    if let Some(last) = last_character {
                        if last == ' ' || last == '|' {
                            start = true;
                        }
                        if last == '-' {
                            end = true;
                        }
                    }
                }
                _ => {
                    // nothing should happen here
                }
            }

            last_character = Some(character);
        }

        counter += 1;
        // tidy up the trailing
        if start && end {
            alignment.insert(counter, "center".to_string());
        } else if start {
            alignment.insert(counter, "left".to_string());
        } else if end {
            alignment.insert(counter, "right".to_string());
        } else {
            // dont insert
        }

        alignment
    }

    fn block_merge(&self, nodes: Vec<NodeData>, depth: usize) -> String {
        let mut result: Vec<String> = vec![];

        for node in nodes {
            let tag = node.tag.as_str();
            let (opening, content, closing) = match tag {
                // html just gets passed straight through
                "html" => {
                    if let Some(text) = node.text {
                        result.push(text);
                    }
                    (None, None, None)
                }
                // simple stuff first, no recursion

                "h1" | "h2" | "h3" | "h4" | "h5" | "h6" => {
                    if let Some(text) = node.text {
                        let processed = self.inline_process(text, 0);

                        // no attributes or anything
                        let formatted = format!("<{}>{}</{}>", tag, processed, tag);

                        (Some(formatted), None, None)
                    }else{
                        (None, None, None)
                    }
                }

                "p" => {
                    if let Some(text) = node.text {
                        let processed = self.inline_process(text, depth+1);

                        // no attributes or anything
                        let open = format!("<{}>", tag);
                        let close = format!("</{}>", tag);

                        (Some(open), Some(processed), Some(close))
                    }else{
                        (None, None, None)
                    }
                }

                "hr" => {
                    // simplest of them all
                    (Some("<hr />".to_string()), None, None)
                }

                "pre" => {
                    if let Some(contents) = node.text {

                        // misc for fenced code blocks is used for the language
                        let formatted = if let Some(language) = node.misc {
                            // using class="language-{language}" is a pseudo standard
                            format!("<pre><code class=\"language-{}\">\n{}\n</code></pre>", language, contents)
                        } else {
                            format!("<pre><code>\n{}\n</code></pre>", contents)
                        };

                        result.push(formatted);
                    }
                    (None, None, None)
                }

                ///////////////////////////
                // recursive beyond this //
                ///////////////////////////

                // table
                "table" | "thead" | "tbody"| "tr" |
                // blockquote always contains other stuff
                "blockquote" |
                // lists
                "ul" | "ol"
                => {
                    let processed = self.block_merge(node.contents, depth+1);
                    let open = format!("<{}>", tag);
                    let close = format!("</{}>", tag);
                    (Some(open), Some(processed), Some(close))
                }

                "th" | "td" => {
                    let processed = if let Some(text) = node.text {
                        self.inline_process(text, depth+1)
                    } else{
                        "".to_string()
                    };

                    let open = if let Some(alignment) = node.misc {
                        // text-align: alignment;
                        // https://developer.mozilla.org/en-US/docs/Web/CSS/text-align
                        format!("<{} style=\"text-align: {};\">", tag, alignment)
                    } else {
                        format!("<{}>", tag)
                    };

                    let close = format!("</{}>", tag);

                    (Some(open), Some(processed), Some(close))
                }

                "li" => {
                    // this handles the contents for both ordered and unordered lists

                    let processed = if !node.contents.is_empty() {
                        self.block_merge(node.contents, depth+1)
                    } else if let Some(text) = node.text{
                        text
                    } else {
                        "".to_string()
                    };


                    let open = if let Some(value) = node.misc {
                        format!("<{} value=\"{}\">", tag, value)
                    } else {
                        format!("<{}>", tag)
                    };

                    let close = format!("</{}>", tag);

                    (Some(open), Some(processed), Some(close))
                }

                _ =>{
                    (None, None, None)
                }
            };

            if let Some(x_opening) = opening {
                let indented = format!("{:indent$}{}", "", x_opening, indent = (depth * self.indentation));
                result.push(indented)
            }
            if let Some(x_content) = content {
                let indented = format!("{:indent$}{}", "", x_content, indent = 0);
                // already indented in its section, specifically text content
                result.push(indented)
            }
            if let Some(x_closing) = closing {
                let indented = format!("{:indent$}{}", "", x_closing, indent = (depth * self.indentation));
                result.push(indented)
            }
        }

        result.join("\n")
    }

    fn inline_process(&self, input: String, depth: usize) -> String {
        // convert it into nodes
        let nodes = self.inline_spans(input);

        // merge them together according to the type of node
        let merged = self.inline_merge(nodes);

        // add line breaks if they are required
        // replace "  \n" with "\n<br />\n"
        let line_breaks_added = merged.replace("  \n", "\n<br />\n");

        // add the appropriate indentation to make it readable as raw html
        self.inline_indention(line_breaks_added, depth)
    }

    // this breaks down teh spans
    fn inline_spans(&self, input: String) -> Vec<NodeData> {
        /*

            //em//
            **strong**
            __underline__
            ~~strikethrough~~
            >!spoiler text!< class=md-spoiler-text , hiding it is handled in css, using teh format from Reddit
            ``code``
            <<autolink>>

            yes these are breaking changes with commonmark right back to daringfireball's one.
            main reason is conformity.
            All of these have a specific opening and closing tag (em/strong from previous implementations is tricky)
            identifiers dont do multiple jobs, _ was used in place of * in previous versions


            contents of html are checked for markdown


            [link][]
            ![image]

            Valid:
                Normal:
                    []()
                    [](<>)
                    [text](url "title")
                    [text](<url with spaces>)

                Reference:
                    [identifier]: /url "title"
                    [text][identifier]

        text is subject to markdown
            ye some breaking changes here



            >! spoilered  **strong spoilered //emp strong spoilered// __not underlined** !< __
            >!![]!<

         */

        let mut node_data: Vec<NodeData> = vec![];

        let mut characters: Vec<char> = input.chars().collect();

        let mut index = 0;

        let mut span_closer: Vec<char> = vec![];
        let mut span_start = 0;

        /*
        normal = stuff created by the delimiters
        html is any html blocks
        url is anything that matches a url [
        image is like the url but starts with ![
        */

        // marks the start of a span
        let mut span_active = false;
        let mut span_finished = false;
        let mut span_reset = false;

        // for allocating where items go
        let mut span_text = true; // defaults to this,
        let mut span_normal = false;
        let mut span_html = false;

        let mut span_normal_type: Option<String> = None;

        let mut html_tag_vec = vec![];
        let mut html_tag_complete = false;

        loop {
            if index >= characters.len() {
                break;
            }

            let character = characters[index];
            let character_next = if (index + 1) < characters.len() { Some(characters[index + 1]) } else { None };
            let character_last_escape = if (index as isize - 1) > 0 { characters[index - 1] == '\\' } else { false };

            // this gets teh first section of a span
            if !span_active {
                match character {
                    // em
                    '/' => {
                        // /
                        if let Some(next) = character_next {
                            if next == '/' {
                                if character_last_escape {
                                    // remove the backslash
                                    characters.remove(index - 1);

                                    // since everything moved to the left so staying still is teh same as the normal +1 for the index
                                    // the -1 here will cancel out the +1 later
                                    index -= 1;
                                } else {
                                    span_normal_type = Some("em".to_string());
                                    span_closer = vec!['/', '/'];
                                    span_active = true;
                                    span_normal = true;
                                    span_text = false;
                                }
                            }
                        }
                    }
                    // strong
                    '*' => {
                        // *
                        if let Some(next) = character_next {
                            if next == '*' {
                                if character_last_escape {
                                    // remove the backslash
                                    characters.remove(index - 1);

                                    // since everything moved to the left so staying still is teh same as the normal +1 for the index
                                    // the -1 here will cancel out the +1 later
                                    index -= 1;
                                } else {
                                    span_normal_type = Some("strong".to_string());
                                    span_closer = vec!['*', '*'];
                                    span_active = true;
                                    span_normal = true;
                                    span_text = false;
                                }
                            }
                        }
                    }
                    // underline
                    '_' => {
                        // _
                        if let Some(next) = character_next {
                            if next == '_' {
                                if character_last_escape {
                                    // remove the backslash
                                    characters.remove(index - 1);

                                    // since everything moved to the left so staying still is teh same as the normal +1 for the index
                                    // the -1 here will cancel out the +1 later
                                    index -= 1;
                                } else {
                                    span_normal_type = Some("u".to_string());
                                    span_closer = vec!['_', '_'];
                                    span_active = true;
                                    span_normal = true;
                                    span_text = false;
                                }
                            }
                        }
                    }
                    // strikethrough
                    '~' => {
                        // ~
                        if let Some(next) = character_next {
                            if next == '~' {
                                if character_last_escape {
                                    // remove the backslash
                                    characters.remove(index - 1);

                                    // since everything moved to the left so staying still is teh same as the normal +1 for the index
                                    // the -1 here will cancel out the +1 later
                                    index -= 1;
                                } else {
                                    span_normal_type = Some("s".to_string());
                                    span_closer = vec!['~', '~'];
                                    span_active = true;
                                    span_normal = true;
                                    span_text = false;
                                }
                            }
                        }
                    }
                    // code
                    '`' => {
                        // `
                        if let Some(next) = character_next {
                            if next == '`' {
                                if character_last_escape {
                                    // remove the backslash
                                    characters.remove(index - 1);

                                    // since everything moved to the left so staying still is teh same as the normal +1 for the index
                                    // the -1 here will cancel out the +1 later
                                    index -= 1;
                                } else {
                                    span_normal_type = Some("code".to_string());
                                    span_closer = vec!['`', '`'];
                                    span_active = true;
                                    span_normal = true;
                                    span_text = false;
                                }
                            }
                        }
                    }
                    '>' => {
                        // >
                        // only one that breaks teh double mould
                        if let Some(next) = character_next {
                            if next == '!' {
                                if character_last_escape {
                                    // remove the backslash
                                    characters.remove(index - 1);

                                    // since everything moved to the left so staying still is teh same as the normal +1 for the index
                                    // the -1 here will cancel out the +1 later
                                    index -= 1;
                                } else {
                                    span_normal_type = Some("spoiler".to_string());
                                    span_closer = vec!['!', '<'];
                                    span_active = true;
                                    span_normal = true;
                                    span_text = false;
                                }
                            }
                        }
                    }
                    '<' => {
                        // set html first
                        span_active = true;
                        span_html = true;
                        span_text = false;

                        if let Some(next) = character_next {
                            // check if autolink
                            match next {
                                '<' => {
                                    // undo the html flag set above
                                    span_html = false;

                                    // set info for the closing
                                    span_normal_type = Some("autolink".to_string());
                                    span_closer = vec!['>', '>'];
                                    span_normal = true;
                                }
                                ' ' | '\t' | '/' | '>' => {
                                    // not a html tag
                                    span_active = false;
                                    span_html = false;
                                    span_text = true;
                                }
                                _ => {}
                            }
                        }

                        if span_active && character_last_escape {
                            // reset teh flags
                            span_active = false;
                            span_html = false;
                            span_text = true;
                            span_normal_type = None;
                            span_closer = vec![];
                            span_normal = false;

                            characters.remove(index - 1);

                            // since everything moved to the left so staying still is teh same as the normal +1 for the index
                            // the -1 here will cancel out the +1 later
                            index -= 1;
                        }
                    }
                    '[' => {
                        if character_last_escape {
                            // remove the backslash
                            characters.remove(index - 1);

                            // since everything moved to the left so staying still is teh same as the normal +1 for the index
                            // the -1 here will cancel out the +1 later
                            index -= 1;
                        } else if let Some((node, offset)) = self.inline_spans_links(&characters[index..], "a".to_string()) {
                            // set teh stuff before to be a text
                            let text: String = characters[span_start..index].iter().collect();
                            node_data.push(NodeData { tag: "text".to_string(), misc: None, text: Some(text), contents: vec![] });

                            // add the data to teh array
                            node_data.push(node);
                            index += offset;

                            // set the enw span start
                            span_start = index + 1;
                        }
                    }
                    '!' => {
                        if let Some(next) = character_next {
                            if next == '[' {
                                if character_last_escape {
                                    // remove the backslash
                                    characters.remove(index - 1);

                                    // since everything moved to the left so staying still is teh same as the normal +1 for the index
                                    // the -1 here will cancel out the +1 later
                                    index -= 1;
                                } else {
                                    // images require a +1 to the offsets to take into account teh !
                                    if let Some((node, offset)) = self.inline_spans_links(&characters[(index + 1)..], "img".to_string()) {
                                        // set teh stuff before to be a text
                                        let text: String = characters[span_start..index].iter().collect();
                                        node_data.push(NodeData { tag: "text".to_string(), misc: None, text: Some(text), contents: vec![] });

                                        // add the data to teh array
                                        node_data.push(node);
                                        index += offset + 1;

                                        // set the new span start
                                        span_start = index + 2;
                                    }
                                }
                            }
                        }
                    }

                    _ => {
                        // do nothing
                    }
                }

                if span_active {
                    // tidy up teh last text span here
                    // bundle up everything between span_start and index into a string
                    let text: String = characters[span_start..index].iter().collect();
                    node_data.push(NodeData { tag: "text".to_string(), misc: None, text: Some(text), contents: vec![] });

                    span_start = index;

                    // skip to the next character if html, two if its
                    if span_normal {
                        index += 2;
                    } else {
                        index += 1;
                    }

                    continue;
                }
            }

            // this captures the content of the spans
            if span_active {
                if span_normal {
                    // this aught to be pretty easy, just find the tail end of the span, bundle it up into NodeData

                    if span_closer[0] == character {
                        if character_last_escape {
                            characters.remove(index - 1);

                            // since everything moved to the left so staying still is teh same as the normal +1 for the index
                            // the -1 here will cancel out the +1 later
                            index -= 1;
                        } else if let Some(next) = character_next {
                            if span_closer[1] == next {
                                // mark it as finished
                                span_finished = true;
                            }
                        }
                    }
                }

                if span_html {
                    // of the tag isn't complete then we need to find it
                    if !html_tag_complete {
                        match character {
                            ' ' | '\t' => {
                                html_tag_complete = true;
                            }
                            '/' | '>' => {
                                // check last character, if it was a backslash then remove the backslash and add the current character
                                if characters[index - 1] == '\\' {
                                    // remove teh slash
                                    // add the bracket
                                    html_tag_vec.pop();
                                    html_tag_vec.push(character);
                                } else {
                                    html_tag_complete = true;
                                }
                            }
                            _ => {
                                // as long as there are no spaces
                                html_tag_vec.push(character);
                            }
                        }
                    }
                    if html_tag_complete {
                        if span_closer.is_empty() {
                            // sets teh
                            let tag: String = html_tag_vec.iter().collect();

                            if self.html_void.contains(&tag) {
                                span_closer = vec!['/', '>'];
                            } else {
                                span_closer = vec!['<', '/'];
                                span_closer.extend(&html_tag_vec);
                                span_closer.push('>');
                            }
                            // reverse it so it can be used easier down below
                            span_closer.reverse();
                        }
                        // using tag_closing find the end of the html span
                        // check if this is the

                        // starts off true
                        let mut matches = true;
                        for (position, closing_char) in span_closer.iter().enumerate() {
                            let index_new: isize = (index as isize) - (position as isize);
                            if index_new < 0 {
                                span_reset = true;
                                matches = false;
                                break;
                            }

                            if &characters[index_new as usize] != closing_char {
                                matches = false;
                                break;
                            }
                        }
                        if matches {
                            span_finished = true;
                        }
                    }
                }
            }

            if character_next.is_none() && !span_finished {
                if span_text {
                    span_finished = true;
                } else {
                    span_reset = true;
                }
            }

            if span_reset {
                // if the first character is < then replace it with &lt;
                if characters[span_start] == '<' {
                    let replacement_char = ['&', 'l', 't', ';'];
                    characters.splice(span_start..=span_start, replacement_char.iter().cloned());
                }

                span_closer = vec![];

                span_active = false;
                span_finished = false;
                span_reset = false; // reset this flag

                span_normal = false;
                span_html = false;
                span_text = true;

                span_normal_type = None;

                html_tag_vec = vec![];
                html_tag_complete = false;

                // reset back to the start of the span
                index = span_start;
                // skip to next character so it wont re-analyse the same set of characters
                index += 1;

                continue;
            }

            if span_finished {
                if span_text {
                    let text: String = characters[span_start..=index].iter().collect();
                    node_data.push(NodeData { tag: "text".to_string(), misc: None, text: Some(text), contents: vec![] });

                    span_start = index;

                    // skip to the next character if html, two if its
                    if span_normal {
                        index += 1;
                    } else {
                        index += 0;
                    }
                }

                if span_normal {
                    // the offset of 2 is to exclude teh delimiter
                    let text_raw: String = characters[(span_start + 2)..=(index - 1)].iter().collect();

                    let span_type = if let Some(span) = span_normal_type { span } else { "text".to_string() };

                    let (text, contents) = match span_type.as_str() {
                        "text" => (Some(text_raw), vec![]),
                        "code" => (Some(text_raw), vec![]),
                        "autolink" => (Some(text_raw), vec![]),
                        _ => (None, self.inline_spans(text_raw)),
                    };

                    node_data.push(NodeData { tag: span_type, misc: None, text, contents });

                    // skip to after the current delimiter
                    span_start = index + 2;

                    // skip to the next character if html, two if its

                    index += 1;
                }

                if span_html {
                    let text: String = characters[span_start..=index].iter().collect();

                    node_data.push(NodeData { tag: "html".to_string(), misc: None, text: Some(text), contents: vec![] });

                    span_start = index + 1;
                }

                span_closer = vec![];

                span_active = false;
                span_finished = false;

                span_normal = false;
                span_html = false;
                span_text = true;

                span_normal_type = None;

                html_tag_vec = vec![];
                html_tag_complete = false;
            }

            index += 1;
        }

        // catch anything at the end
        if span_start < (characters.len() - 1) {
            let text: String = characters[span_start..].iter().collect();
            node_data.push(NodeData { tag: "text".to_string(), misc: None, text: Some(text), contents: vec![] });
        }

        node_data
    }

    fn inline_spans_links(&self, characters: &[char], tag: String) -> Option<(NodeData, usize)> {
        let references = self.references.clone();

        // index starts at 1 as first character is always the opener [
        let mut index = 1;

        let mut block_first = vec![];

        let mut link_type = None;
        loop {
            if index >= characters.len() {
                break;
            }

            let character = characters[index];
            let character_next = if (index + 1) < characters.len() { Some(characters[index + 1]) } else { None };
            let character_last_escape = if (index as isize - 1) > 0 { characters[index - 1] == '\\' } else { false };

            match character {
                ']' => {
                    if character_last_escape {
                        block_first.pop();
                        block_first.push(character)
                    } else {
                        // find the type of link
                        if let Some(next) = character_next {
                            match next {
                                '(' => {
                                    link_type = Some("classic".to_string());
                                    // going to need to take a look at the contents
                                    index += 2;
                                }
                                '[' => {
                                    link_type = Some("reference_named".to_string());
                                    index += 2;
                                }
                                _ => {
                                    // check if the link_text is the same as the reference links in self.references
                                    link_type = Some("reference_anon".to_string());
                                }
                            }
                        } else {
                            // set up to test if its teh anon type
                            link_type = Some("reference_anon".to_string());
                        }

                        // regardless break it here
                        break;
                    }
                }

                _ => block_first.push(character),
            }

            index += 1;
        }

        // deal with teh anon references
        if let Some(type_) = &link_type {
            // only concerned with teh anon_test one this time
            if let "reference_anon" = type_.as_str() {
                let reference: String = block_first.iter().collect();

                return match references.get(&reference) {
                    Some(link_data) => {
                        let url = link_data.url.clone();

                        let contents = if let Some(title) = &link_data.title {
                            // if it has a title then it will override the reference for teh contents
                            self.inline_spans(title.clone())
                        } else {
                            // reference us used as the contents if its an anon one
                            self.inline_spans(reference)
                        };

                        let node = NodeData {
                            tag,
                            misc: link_data.title.clone(),
                            // text here is used as the url
                            text: Some(url),
                            contents,
                        };

                        Some((node, index))
                    }
                    None => {
                        // not a link
                        None
                    }
                };
            }
        }

        let mut block_second = vec![];
        let mut angle_brackets = false;
        loop {
            if index >= characters.len() {
                break;
            }

            let character = characters[index];
            let character_last_escape = if (index as isize - 1) > 0 { characters[index - 1] == '\\' } else { false };

            // do stuff here

            if let Some(type_) = &link_type {
                match type_.as_str() {
                    "classic" => {
                        match character {
                            '<' => {
                                if block_second.is_empty() {
                                    angle_brackets = true;
                                }

                                // add it regardless, can be easily removed later
                                block_second.push(character)
                            }
                            ' ' | '\t' => {
                                if angle_brackets {
                                    block_second.push(character)
                                } else if block_second.is_empty() {
                                    // do nothing,
                                } else {
                                    // next loop will start on the next character
                                    index += 1;
                                    // its teh end of the url
                                    break;
                                }
                            }
                            ')' => {
                                if angle_brackets {
                                    block_second.push(character)
                                } else if character_last_escape {
                                    block_second.pop();
                                    block_second.push(character);
                                } else {
                                    // this marks the classic link as finished
                                    // so make it and finish early

                                    let text_raw: String = block_first.iter().collect();
                                    let contents = self.inline_spans(text_raw);
                                    let url: String = block_second.iter().collect();
                                    let node = NodeData { tag, misc: None, text: Some(url), contents };

                                    return Some((node, index));
                                }
                            }
                            '\n' => {
                                // all inline links must be on the one line, not split over multiple
                                // saves a lot of complexity
                                return None;
                            }
                            '>' => {
                                if angle_brackets {
                                    // marks teh end of the span
                                    // however if last char is a backslash its ignored
                                    if character_last_escape {
                                        block_second.pop();
                                        block_second.push(character);
                                    } else {
                                        // remove the first char which is a <
                                        block_second.remove(0);
                                        break;
                                    }
                                } else {
                                    block_second.push(character)
                                }
                            }
                            _ => block_second.push(character),
                        }
                    }
                    "reference_named" => match character {
                        ']' => {
                            if character_last_escape {
                                block_second.pop();
                                block_second.push(character);
                            } else {
                                break;
                            }
                        }
                        _ => block_second.push(character),
                    },
                    _ => {
                        // only classic and reference_named should show up
                    }
                }
            }

            index += 1;
        }

        // tidy up the references
        if let Some(type_) = &link_type {
            // not for classic
            if let "reference_named" = type_.as_str() {
                let reference: String = block_second.iter().collect();

                return match references.get(&reference) {
                    Some(link_data) => {
                        let text_raw: String = block_first.iter().collect();
                        let contents = self.inline_spans(text_raw);

                        let node = NodeData {
                            tag,
                            misc: link_data.title.clone(),
                            // text here is used as the url
                            text: Some(link_data.url.clone()),
                            contents,
                        };

                        Some((node, index))
                    }
                    None => {
                        // not a link
                        None
                    }
                };
            }
        }

        //
        /*
        now just left with classic

        // these are the three general patterns to find
        [](<>)
        [](/url )
        [](/url "title")
         */

        // this handles the title
        let mut block_third = vec![];
        let mut delimiter = (' ', false, false);
        loop {
            if index >= characters.len() {
                break;
            }

            let character = characters[index];
            let character_last_escape = if (index as isize - 1) > 0 { characters[index - 1] == '\\' } else { false };

            match character {
                // manage delimiter
                '\'' | '"' => {
                    if !delimiter.1 {
                        // set the delimiter
                        delimiter = (character, true, false);
                    } else if delimiter.0 == character {
                        // check if last character was an escape
                        if character_last_escape {
                            block_third.pop();
                            block_third.push(character);
                        } else {
                            // mark it closed
                            delimiter = (character, true, true);
                        }
                    } else {
                        block_third.push(character);
                    }
                }

                //
                ')' => {
                    if delimiter.1 && !delimiter.2 {
                        // if delimiter is open then add it to teh array
                        block_third.push(character);
                    } else {
                        // else check if its escaped
                        if character_last_escape {
                            block_third.pop();
                            block_third.push(character);
                        } else {
                            // this marks the classic link as finished
                            // so make it and finish early

                            let text_raw: String = block_first.iter().collect();
                            let contents = self.inline_spans(text_raw);

                            let url: String = block_second.iter().collect();

                            let title = if block_third.is_empty() {
                                None
                            } else {
                                let title_tmp: String = block_third.iter().collect();
                                Some(title_tmp)
                            };

                            let node = NodeData { tag, misc: title, text: Some(url), contents };

                            return Some((node, index));
                        }
                    }
                }

                ' ' | '\t' => {
                    if delimiter.1 && !delimiter.2 {
                        // if delimiter is open then add it to teh array
                        block_third.push(character);
                    } else {
                        // do nothing
                    }
                }
                _ => {
                    block_third.push(character);
                }
            }

            index += 1;
        }

        // if its gone to teh end without being closed out then its invalid

        None
    }

    fn inline_merge(&self, nodes: Vec<NodeData>) -> String {
        let mut result: Vec<String> = vec![];

        for node in nodes {
            let tag = node.tag.as_str();
            let (opening, content, closing) = match tag {
                // html  and text just gets passed straight through
                "html" | "text" => {
                    if let Some(text) = node.text {
                        result.push(text);
                    }
                    (None, None, None)
                }
                // treat this basically the same as html above
                "autolink" => {
                    if let Some(text) = node.text {
                        let (cleaned, mail, tel) = if text.starts_with("mailto:") {
                            (text.replacen("mailto:", "", 1), true, false)
                        } else if text.starts_with("MAILTO:") {
                            (text.replacen("MAILTO:", "", 1), true, false)
                        } else if text.starts_with("tel:") {
                            (text.replacen("tel:", "", 1), false, true)
                        } else if text.starts_with("TEL:") {
                            (text.replacen("TEL:", "", 1), false, true)
                        } else {
                            (text, false, false)
                        };

                        // check if it contains @
                        let formatted = if cleaned.contains('@') || mail {
                            format!("<a target='_blank' rel='noopener noreferrer' href='mailto:{}'>{}</a>", &cleaned, &cleaned)
                        } else if tel {
                            format!("<a target='_blank' rel='noopener noreferrer' href='tel:{}'>{}</a>", &cleaned, &cleaned)
                        } else {
                            format!("<a target='_blank' rel='noopener noreferrer' href='{}'>{}</a>", &cleaned, &cleaned)
                        };

                        result.push(formatted);
                    }
                    (None, None, None)
                }

                // set tags and no recursion
                "code" => {
                    if let Some(text) = node.text {
                        // no attributes or anything recursive
                        let open = format!("<{}>", tag);
                        let close = format!("</{}>", tag);

                        let cleaned = text.replace('<', "&lt;").replace('>', "&gt;");

                        (Some(open), Some(cleaned), Some(close))
                    } else {
                        (None, None, None)
                    }
                }

                // recursive
                "em" | "strong" | "u" | "s" => {
                    let processed = self.inline_merge(node.contents);
                    let open = format!("<{}>", tag);
                    let close = format!("</{}>", tag);
                    (Some(open), Some(processed), Some(close))
                }

                // spoiler is a span with a class of class="md-spoiler" on it as there is no html element for spoilers and must be done using css
                "spoiler" => {
                    let processed = self.inline_merge(node.contents);
                    let open = "<span class='md-spoiler'>".to_string();
                    let close = "</span>".to_string();
                    (Some(open), Some(processed), Some(close))
                }

                "a" => {
                    let url = node.text.unwrap_or_default();
                    let open = if let Some(title) = node.misc {
                        format!("<a target='_blank' rel='noopener noreferrer' href='{}' title='{}'>", url, title)
                    } else {
                        format!("<a target='_blank' rel='noopener noreferrer' href='{}'>", url)
                    };

                    let processed = self.inline_merge(node.contents);
                    let close = "</a>".to_string();

                    (Some(open), Some(processed), Some(close))
                }

                "img" => {
                    let url = node.text.unwrap_or_default();
                    let alt = self.inline_merge(node.contents);
                    let open = if let Some(title) = node.misc {
                        format!("<img src='{}' alt='{}' title='{}' />", url, alt, title)
                    } else {
                        format!("<img src='{}' alt='{}' />", url, alt)
                    };

                    (Some(open), None, None)
                }

                _ => (None, None, None),
            };

            if let Some(data) = opening {
                result.push(data)
            }
            if let Some(data) = content {
                result.push(data)
            }
            if let Some(data) = closing {
                result.push(data)
            }
        }

        result.join("")
    }

    fn inline_indention(&self, input: String, depth: usize) -> String {
        let mut result: Vec<String> = vec![];

        let lines = input.split('\n').collect::<Vec<_>>();
        for line in lines {
            let indented = format!("{:indent$}{}", "", line, indent = (depth * self.indentation));
            result.push(indented);
        }

        result.join("\n")
    }
}
//