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 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745
|
###############################################################################
#
# Package: NaturalDocs::Builder::HTMLBase
#
###############################################################################
#
# A base package for all the shared functionality in <NaturalDocs::Builder::HTML> and
# <NaturalDocs::Builder::FramedHTML>.
#
###############################################################################
# This file is part of Natural Docs, which is Copyright 2003-2010 Greg Valure
# Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
# Refer to License.txt for the complete details
use Tie::RefHash;
use strict;
use integer;
package NaturalDocs::Builder::HTMLBase;
use base 'NaturalDocs::Builder::Base';
use NaturalDocs::DefineMembers 'MADE_EMPTY_SEARCH_RESULTS_PAGE', 'MadeEmptySearchResultsPage()',
'SetMadeEmptySearchResultsPage()';
###############################################################################
# Group: Object Variables
#
# Constants: Members
#
# The object is implemented as a blessed arrayref, with the follow constants as indexes.
#
# MADE_EMPTY_SEARCH_RESULTS_PAGE - Whether the search results page for searches with no results was generated.
#
#
# Constants: NDMarkupToHTML Styles
#
# These are the styles used with <NDMarkupToHTML()>.
#
# NDMARKUPTOHTML_GENERAL - General style.
# NDMARKUPTOHTML_SUMMARY - For summaries.
# NDMARKUPTOHTML_TOOLTIP - For tooltips.
#
use constant NDMARKUPTOHTML_GENERAL => undef;
use constant NDMARKUPTOHTML_SUMMARY => 1;
use constant NDMARKUPTOHTML_TOOLTIP => 2;
###############################################################################
# Group: Package Variables
# These variables are shared by all instances of the package so don't change them.
#
# handle: FH_CSS_FILE
#
# The file handle to use when updating CSS files.
#
#
# Hash: abbreviations
#
# An existence hash of acceptable abbreviations. These are words that <AddDoubleSpaces()> won't put a second space
# after when followed by period-whitespace-capital letter. Yes, this is seriously over-engineered.
#
my %abbreviations = ( mr => 1, mrs => 1, ms => 1, dr => 1,
rev => 1, fr => 1, 'i.e' => 1,
maj => 1, gen => 1, pres => 1, sen => 1, rep => 1,
n => 1, s => 1, e => 1, w => 1, ne => 1, se => 1, nw => 1, sw => 1 );
#
# array: indexHeadings
#
# An array of the headings of all the index sections. First is for symbols, second for numbers, and the rest for each letter.
#
my @indexHeadings = ( '$#!', '0-9', 'A' .. 'Z' );
#
# array: indexAnchors
#
# An array of the HTML anchors of all the index sections. First is for symbols, second for numbers, and the rest for each letter.
#
my @indexAnchors = ( 'Symbols', 'Numbers', 'A' .. 'Z' );
#
# array: searchExtensions
#
# An array of the search file name extensions for all the index sections. First is for symbols, second for numbers, and the rest
# for each letter.
#
my @searchExtensions = ( 'Symbols', 'Numbers', 'A' .. 'Z' );
#
# bool: saidUpdatingCSSFile
#
# Whether the status message "Updating CSS file..." has been displayed. We only want to print it once, no matter how many
# HTML-based targets we are building.
#
my $saidUpdatingCSSFile;
#
# constant: ADD_HIDDEN_BREAKS
#
# Just a synonym for "1" so that setting the flag on <StringToHTML()> is clearer in the calling code.
#
use constant ADD_HIDDEN_BREAKS => 1;
###############################################################################
# Group: ToolTip Package Variables
#
# These variables are for the tooltip generation functions only. Since they're reset on every call to <BuildContent()> and
# <BuildIndexSections()>, and are only used by them and their support functions, they can be shared by all instances of the
# package.
#
# int: tooltipLinkNumber
#
# A number used as part of the ID for each link that has a tooltip. Should be incremented whenever one is made.
#
my $tooltipLinkNumber;
#
# int: tooltipNumber
#
# A number used as part of the ID for each tooltip. Should be incremented whenever one is made.
#
my $tooltipNumber;
#
# hash: tooltipSymbolsToNumbers
#
# A hash that maps the tooltip symbols to their assigned numbers.
#
my %tooltipSymbolsToNumbers;
#
# string: tooltipHTML
#
# The generated tooltip HTML.
#
my $tooltipHTML;
###############################################################################
# Group: Menu Package Variables
#
# These variables are for the menu generation functions only. Since they're reset on every call to <BuildMenu()> and are
# only used by it and its support functions, they can be shared by all instances of the package.
#
#
# hash: prebuiltMenus
#
# A hash that maps output directonies to menu HTML already built for it. There will be no selection or JavaScript in the menus.
#
my %prebuiltMenus;
#
# bool: menuNumbersAndLengthsDone
#
# Set when the variables that only need to be calculated for the menu once are done. This includes <menuGroupNumber>,
# <menuLength>, <menuGroupLengths>, and <menuGroupNumbers>, and <menuRootLength>.
#
my $menuNumbersAndLengthsDone;
#
# int: menuGroupNumber
#
# The current menu group number. Each time a group is created, this is incremented so that each one will be unique.
#
my $menuGroupNumber;
#
# int: menuLength
#
# The length of the entire menu, fully expanded. The value is computed from the <Menu Length Constants>.
#
my $menuLength;
#
# hash: menuGroupLengths
#
# A hash of the length of each group, *not* including any subgroup contents. The keys are references to each groups'
# <NaturalDocs::Menu::Entry> object, and the values are their lengths computed from the <Menu Length Constants>.
#
my %menuGroupLengths;
tie %menuGroupLengths, 'Tie::RefHash';
#
# hash: menuGroupNumbers
#
# A hash of the number of each group, as managed by <menuGroupNumber>. The keys are references to each groups'
# <NaturalDocs::Menu::Entry> object, and the values are the number.
#
my %menuGroupNumbers;
tie %menuGroupNumbers, 'Tie::RefHash';
#
# int: menuRootLength
#
# The length of the top-level menu entries without expansion. The value is computed from the <Menu Length Constants>.
#
my $menuRootLength;
#
# constants: Menu Length Constants
#
# Constants used to approximate the lengths of the menu or its groups.
#
# MENU_TITLE_LENGTH - The length of the title.
# MENU_SUBTITLE_LENGTH - The length of the subtitle.
# MENU_FILE_LENGTH - The length of one file entry.
# MENU_GROUP_LENGTH - The length of one group entry.
# MENU_TEXT_LENGTH - The length of one text entry.
# MENU_LINK_LENGTH - The length of one link entry.
#
# MENU_LENGTH_LIMIT - The limit of the menu's length. If the total length surpasses this limit, groups that aren't required
# to be open to show the selection will default to closed on browsers that support it.
#
use constant MENU_TITLE_LENGTH => 3;
use constant MENU_SUBTITLE_LENGTH => 1;
use constant MENU_FILE_LENGTH => 1;
use constant MENU_GROUP_LENGTH => 2; # because it's a line and a blank space
use constant MENU_TEXT_LENGTH => 1;
use constant MENU_LINK_LENGTH => 1;
use constant MENU_INDEX_LENGTH => 1;
use constant MENU_LENGTH_LIMIT => 35;
###############################################################################
# Group: Image Package Variables
#
# These variables are for the image generation functions only. Since they're reset on every call to <BuildContent()>,
# and are only used by it and its support functions, they can be shared by all instances of thepackage.
#
# var: imageAnchorNumber
# Incremented for each image link in the file that requires an anchor.
#
my $imageAnchorNumber;
#
# var: imageContent
#
# The actual embedded image HTML for all image links. When generating an image link, the link HTML is returned and
# the HTML for the target image is added here. Periodically, such as after the end of the paragraph, this content should
# be added to the page and the variable set to undef.
#
my $imageContent;
###############################################################################
# Group: Search Package Variables
#
# These variables are for the search generation functions only. Since they're reset on every call to <BuildIndexSections()> and
# are only used by them and their support functions, they can be shared by all instances of the package.
#
# hash: searchResultIDs
#
# A hash mapping lowercase-only search result IDs to the number of times they've been used. This is to work around an IE
# bug where it won't correctly reference IDs if they differ only in case.
#
my %searchResultIDs;
###############################################################################
# Group: Object Functions
#
# Function: New
# Creates and returns a new object.
#
sub New
{
my $class = shift;
my $object = $class->SUPER::New();
$object->SetMadeEmptySearchResultsPage(0);
return $object;
};
# Function: MadeEmptySearchResultsPage
# Returns whether the empty search results page was created or not.
# Function: SetMadeEmptySearchResultsPage
# Sets whether the empty search results page was created or not.
###############################################################################
# Group: Implemented Interface Functions
#
# The behavior of these functions is shared between HTML output formats.
#
#
# Function: UpdateImage
#
# Define this function to add or update the passed image in the output.
#
# Parameters:
#
# file - The image <FileName>
#
sub UpdateImage #(file)
{
my ($self, $file) = @_;
my $outputFile = $self->OutputImageOf($file);
my $outputDirectory = NaturalDocs::File->NoFileName($outputFile);
if (!-d $outputDirectory)
{ NaturalDocs::File->CreatePath($outputDirectory); };
NaturalDocs::File->Copy($file, $outputFile);
};
#
# Function: PurgeFiles
#
# Deletes the output files associated with the purged source files.
#
sub PurgeFiles #(filesToPurge)
{
my ($self, $filesToPurge) = @_;
# Combine directories into a hash to remove duplicate work.
my %directoriesToPurge;
foreach my $file (keys %$filesToPurge)
{
# It's possible that there may be files there that aren't in a valid input directory anymore. They won't generate an output
# file name so we need to check for undef.
my $outputFile = $self->OutputFileOf($file);
if (defined $outputFile)
{
unlink($outputFile);
$directoriesToPurge{ NaturalDocs::File->NoFileName($outputFile) } = 1;
};
};
foreach my $directory (keys %directoriesToPurge)
{
NaturalDocs::File->RemoveEmptyTree($directory, NaturalDocs::Settings->OutputDirectoryOf($self));
};
};
#
# Function: PurgeIndexes
#
# Deletes the output files associated with the purged source files.
#
# Parameters:
#
# indexes - An existence hashref of the index types to purge. The keys are the <TopicTypes> or * for the general index.
#
sub PurgeIndexes #(indexes)
{
my ($self, $indexes) = @_;
foreach my $index (keys %$indexes)
{
$self->PurgeIndexFiles($index, undef, undef);
};
};
#
# Function: PurgeImages
#
# Define this function to make the package remove all output related to the passed image files. These files are no longer used
# by the documentation.
#
# Parameters:
#
# files - An existence hashref of the image <FileNames> to purge.
#
sub PurgeImages #(files)
{
my ($self, $filesToPurge) = @_;
# Combine directories into a hash to remove duplicate work.
my %directoriesToPurge;
foreach my $file (keys %$filesToPurge)
{
# It's possible that there may be files there that aren't in a valid input directory anymore. They won't generate an output
# file name so we need to check for undef.
my $outputFile = $self->OutputImageOf($file);
if (defined $outputFile)
{
unlink($outputFile);
$directoriesToPurge{ NaturalDocs::File->NoFileName($outputFile) } = 1;
};
};
foreach my $directory (keys %directoriesToPurge)
{
NaturalDocs::File->RemoveEmptyTree($directory, NaturalDocs::Settings->OutputDirectoryOf($self));
};
};
#
# Function: BeginBuild
#
# Creates the necessary subdirectories in the output directory.
#
sub BeginBuild #(hasChanged)
{
my ($self, $hasChanged) = @_;
foreach my $directory ( $self->JavaScriptDirectory(), $self->CSSDirectory(), $self->IndexDirectory(),
$self->SearchResultsDirectory() )
{
if (!-d $directory)
{ NaturalDocs::File->CreatePath($directory); };
};
};
#
# Function: EndBuild
#
# Synchronizes the projects CSS and JavaScript files. Also generates the search data JavaScript file.
#
sub EndBuild #(hasChanged)
{
my ($self, $hasChanged) = @_;
# Update the style sheets.
my $styles = NaturalDocs::Settings->Styles();
my $changed;
my $cssDirectory = $self->CSSDirectory();
my $mainCSSFile = $self->MainCSSFile();
for (my $i = 0; $i < scalar @$styles; $i++)
{
my $outputCSSFile;
if (scalar @$styles == 1)
{ $outputCSSFile = $mainCSSFile; }
else
{ $outputCSSFile = NaturalDocs::File->JoinPaths($cssDirectory, ($i + 1) . '.css'); };
my $masterCSSFile = NaturalDocs::File->JoinPaths( NaturalDocs::Settings->ProjectDirectory(), $styles->[$i] . '.css' );
if (! -e $masterCSSFile)
{ $masterCSSFile = NaturalDocs::File->JoinPaths( NaturalDocs::Settings->StyleDirectory(), $styles->[$i] . '.css' ); };
# We check both the date and the size in case the user switches between two styles which just happen to have the same
# date. Should rarely happen, but it might.
if (! -e $outputCSSFile ||
(stat($masterCSSFile))[9] != (stat($outputCSSFile))[9] ||
-s $masterCSSFile != -s $outputCSSFile)
{
if (!NaturalDocs::Settings->IsQuiet() && !$saidUpdatingCSSFile)
{
print "Updating CSS file...\n";
$saidUpdatingCSSFile = 1;
};
NaturalDocs::File->Copy($masterCSSFile, $outputCSSFile);
$changed = 1;
};
};
my $deleteFrom;
if (scalar @$styles == 1)
{ $deleteFrom = 1; }
else
{ $deleteFrom = scalar @$styles + 1; };
for (;;)
{
my $file = NaturalDocs::File->JoinPaths($cssDirectory, $deleteFrom . '.css');
if (! -e $file)
{ last; };
unlink ($file);
$deleteFrom++;
$changed = 1;
};
if ($changed)
{
if (scalar @$styles > 1)
{
open(FH_CSS_FILE, '>' . $mainCSSFile);
binmode(FH_CSS_FILE, ':encoding(UTF-8)');
for (my $i = 0; $i < scalar @$styles; $i++)
{
print FH_CSS_FILE '@import URL("' . ($i + 1) . '.css");' . "\n";
};
close(FH_CSS_FILE);
};
};
# Update the JavaScript files
my $jsMaster = NaturalDocs::File->JoinPaths( NaturalDocs::Settings->JavaScriptDirectory(), 'NaturalDocs.js' );
my $jsOutput = $self->MainJavaScriptFile();
# We check both the date and the size in case the user switches between two styles which just happen to have the same
# date. Should rarely happen, but it might.
if (! -e $jsOutput ||
(stat($jsMaster))[9] != (stat($jsOutput))[9] ||
-s $jsMaster != -s $jsOutput)
{
NaturalDocs::File->Copy($jsMaster, $jsOutput);
};
my $prettifyOutput = $self->PrettifyJavaScriptFile();
if (NaturalDocs::Settings->HighlightCode() || NaturalDocs::Settings->HighlightAnonymous())
{
my $prettifyMaster = NaturalDocs::File->JoinPaths( NaturalDocs::Settings->JavaScriptDirectory(), 'GooglePrettify.js' );
# We check both the date and the size in case the user switches between two styles which just happen to have the same
# date. Should rarely happen, but it might.
if (! -e $prettifyOutput ||
(stat($prettifyMaster))[9] != (stat($prettifyOutput))[9] ||
-s $prettifyMaster != -s $prettifyOutput)
{
NaturalDocs::File->Copy($prettifyMaster, $prettifyOutput);
};
}
elsif (-e $prettifyOutput)
{
unlink $prettifyOutput;
}
my @indexes = sort keys %{NaturalDocs::Menu->Indexes()};
open(FH_INDEXINFOJS, '>' . NaturalDocs::File->JoinPaths( $self->JavaScriptDirectory(), 'searchdata.js'));
binmode(FH_INDEXINFOJS, ':encoding(UTF-8)');
print FH_INDEXINFOJS
"var indexSectionsWithContent = {\n";
for (my $i = 0; $i < scalar @indexes; $i++)
{
if ($i != 0)
{ print FH_INDEXINFOJS ",\n"; };
print FH_INDEXINFOJS ' "' . NaturalDocs::Topics->NameOfType($indexes[$i], 1, 1) . "\": {\n";
my $content = NaturalDocs::SymbolTable->IndexSectionsWithContent($indexes[$i]);
for (my $contentIndex = 0; $contentIndex < 28; $contentIndex++)
{
if ($contentIndex != 0)
{ print FH_INDEXINFOJS ",\n"; };
print FH_INDEXINFOJS ' "' . $searchExtensions[$contentIndex] . '": ' . ($content->[$contentIndex] ? 'true' : 'false');
};
print FH_INDEXINFOJS "\n }";
};
print FH_INDEXINFOJS
"\n }";
close(FH_INDEXINFOJS);
};
###############################################################################
# Group: Section Functions
#
# Function: BuildTitle
#
# Builds and returns the HTML page title of a file.
#
# Parameters:
#
# sourceFile - The source <FileName> to build the title of.
#
# Returns:
#
# The source file's title in HTML.
#
sub BuildTitle #(sourceFile)
{
my ($self, $sourceFile) = @_;
# If we have a menu title, the page title is [menu title] - [file title]. Otherwise it is just [file title].
my $title = NaturalDocs::Project->DefaultMenuTitleOf($sourceFile);
my $menuTitle = NaturalDocs::Menu->Title();
if (defined $menuTitle && $menuTitle ne $title)
{ $title .= ' - ' . $menuTitle; };
$title = $self->StringToHTML($title);
return $title;
};
#
# Function: BuildMenu
#
# Builds and returns the side menu of a file.
#
# Parameters:
#
# sourceFile - The source <FileName> to use if you're looking for a source file.
# indexType - The index <TopicType> to use if you're looking for an index.
#
# Both sourceFile and indexType may be undef.
#
# Returns:
#
# The side menu in HTML.
#
# Dependencies:
#
# - <Builder::HTML::UpdateFile()> and <Builder::HTML::UpdateIndex()> require this section to be surrounded with the exact
# strings "<div id=Menu>" and "</div><!--Menu-->".
# - This function depends on the way <BuildMenuSegment()> formats file and index entries.
#
sub BuildMenu #(FileName sourceFile, TopicType indexType) -> string htmlMenu
{
my ($self, $sourceFile, $indexType) = @_;
if (!$menuNumbersAndLengthsDone)
{
$menuGroupNumber = 1;
$menuLength = 0;
%menuGroupLengths = ( );
%menuGroupNumbers = ( );
$menuRootLength = 0;
};
my $outputDirectory;
if ($sourceFile)
{ $outputDirectory = NaturalDocs::File->NoFileName( $self->OutputFileOf($sourceFile) ); }
elsif ($indexType)
{ $outputDirectory = NaturalDocs::File->NoFileName( $self->IndexFileOf($indexType) ); }
else
{ $outputDirectory = NaturalDocs::Settings->OutputDirectoryOf($self); };
# Comment needed for UpdateFile().
my $output = '<div id=Menu>';
if (!exists $prebuiltMenus{$outputDirectory})
{
my $segmentOutput;
($segmentOutput, $menuRootLength) =
$self->BuildMenuSegment($outputDirectory, NaturalDocs::Menu->Content(), 1);
my $titleOutput;
my $menuTitle = NaturalDocs::Menu->Title();
if (defined $menuTitle)
{
if (!$menuNumbersAndLengthsDone)
{ $menuLength += MENU_TITLE_LENGTH; };
$menuRootLength += MENU_TITLE_LENGTH;
$titleOutput .=
'<div class=MTitle>'
. $self->StringToHTML($menuTitle);
my $menuSubTitle = NaturalDocs::Menu->SubTitle();
if (defined $menuSubTitle)
{
if (!$menuNumbersAndLengthsDone)
{ $menuLength += MENU_SUBTITLE_LENGTH; };
$menuRootLength += MENU_SUBTITLE_LENGTH;
$titleOutput .=
'<div class=MSubTitle>'
. $self->StringToHTML($menuSubTitle)
. '</div>';
};
$titleOutput .=
'</div>';
};
my $searchOutput;
if (scalar keys %{NaturalDocs::Menu->Indexes()})
{
$searchOutput =
'<script type="text/javascript"><!--' . "\n"
. 'var searchPanel = new SearchPanel("searchPanel", "' . $self->CommandLineOption() . '", '
. '"' . $self->MakeRelativeURL($outputDirectory, $self->SearchResultsDirectory()) . '");' . "\n"
. '--></script>'
. '<div id=MSearchPanel class=MSearchPanelInactive>'
. '<input type=text id=MSearchField value=Search '
. 'onFocus="searchPanel.OnSearchFieldFocus(true)" onBlur="searchPanel.OnSearchFieldFocus(false)" '
. 'onKeyUp="searchPanel.OnSearchFieldChange()">'
. '<select id=MSearchType '
. 'onFocus="searchPanel.OnSearchTypeFocus(true)" onBlur="searchPanel.OnSearchTypeFocus(false)" '
. 'onChange="searchPanel.OnSearchTypeChange()">';
my @indexes = keys %{NaturalDocs::Menu->Indexes()};
@indexes = sort
{
if ($a eq ::TOPIC_GENERAL()) { return -1; }
elsif ($b eq ::TOPIC_GENERAL()) { return 1; }
else { return (NaturalDocs::Topics->NameOfType($a, 1) cmp NaturalDocs::Topics->NameOfType($b, 1)) };
} @indexes;
foreach my $index (@indexes)
{
my ($name, $extra);
if ($index eq ::TOPIC_GENERAL())
{
$name = 'Everything';
$extra = ' id=MSearchEverything selected ';
}
else
{ $name = $self->ConvertAmpChars(NaturalDocs::Topics->NameOfType($index, 1)); }
$searchOutput .=
'<option ' . $extra . 'value="' . NaturalDocs::Topics->NameOfType($index, 1, 1) . '">'
. $name
. '</option>';
};
$searchOutput .=
'</select>'
. '</div>';
};
$prebuiltMenus{$outputDirectory} = $titleOutput . $segmentOutput . $searchOutput;
$output .= $titleOutput . $segmentOutput . $searchOutput;
}
else
{ $output .= $prebuiltMenus{$outputDirectory}; };
# Highlight the menu selection.
if ($sourceFile)
{
# Dependency: This depends on how BuildMenuSegment() formats file entries.
my $outputFile = $self->OutputFileOf($sourceFile);
my $tag = '<div class=MFile><a href="' . $self->MakeRelativeURL($outputDirectory, $outputFile) . '">';
my $tagIndex = index($output, $tag);
if ($tagIndex != -1)
{
my $endIndex = index($output, '</a>', $tagIndex);
substr($output, $endIndex, 4, '');
substr($output, $tagIndex, length($tag), '<div class=MFile id=MSelected>');
};
}
elsif ($indexType)
{
# Dependency: This depends on how BuildMenuSegment() formats index entries.
my $outputFile = $self->IndexFileOf($indexType);
my $tag = '<div class=MIndex><a href="' . $self->MakeRelativeURL($outputDirectory, $outputFile) . '">';
my $tagIndex = index($output, $tag);
if ($tagIndex != -1)
{
my $endIndex = index($output, '</a>', $tagIndex);
substr($output, $endIndex, 4, '');
substr($output, $tagIndex, length($tag), '<div class=MIndex id=MSelected>');
};
};
# If the completely expanded menu is too long, collapse all the groups that aren't in the selection hierarchy or near the
# selection. By doing this instead of having them default to closed via CSS, any browser that doesn't support changing this at
# runtime will keep the menu entirely open so that its still usable.
if ($menuLength > MENU_LENGTH_LIMIT())
{
my $menuSelectionHierarchy = $self->GetMenuSelectionHierarchy($sourceFile, $indexType);
my $toExpand = $self->ExpandMenu($sourceFile, $indexType, $menuSelectionHierarchy, $menuRootLength);
$output .=
'<script language=JavaScript><!--' . "\n"
. 'HideAllBut([' . join(', ', @$toExpand) . '], ' . $menuGroupNumber . ');'
. '// --></script>';
};
$output .= '</div><!--Menu-->';
$menuNumbersAndLengthsDone = 1;
return $output;
};
#
# Function: BuildMenuSegment
#
# A recursive function to build a segment of the menu. *Remember to reset the <Menu Package Variables> before calling this
# for the first time.*
#
# Parameters:
#
# outputDirectory - The output directory the menu is being built for.
# menuSegment - An arrayref specifying the segment of the menu to build. Either pass the menu itself or the contents
# of a group.
# topLevel - Whether the passed segment is the top level segment or not.
#
# Returns:
#
# The array ( menuHTML, length ).
#
# menuHTML - The menu segment in HTML.
# groupLength - The length of the group, *not* including the contents of any subgroups, as computed from the
# <Menu Length Constants>.
#
# Dependencies:
#
# - <BuildMenu()> depends on the way this function formats file and index entries.
#
sub BuildMenuSegment #(outputDirectory, menuSegment, topLevel)
{
my ($self, $outputDirectory, $menuSegment, $topLevel) = @_;
my $output;
my $groupLength = 0;
foreach my $entry (@$menuSegment)
{
if ($entry->Type() == ::MENU_GROUP())
{
my ($entryOutput, $entryLength) =
$self->BuildMenuSegment($outputDirectory, $entry->GroupContent());
my $entryNumber;
if (!$menuNumbersAndLengthsDone)
{
$entryNumber = $menuGroupNumber;
$menuGroupNumber++;
$menuGroupLengths{$entry} = $entryLength;
$menuGroupNumbers{$entry} = $entryNumber;
}
else
{ $entryNumber = $menuGroupNumbers{$entry}; };
$output .=
'<div class=MEntry>'
. '<div class=MGroup>'
. '<a href="javascript:ToggleMenu(\'MGroupContent' . $entryNumber . '\')"'
. ($self->CommandLineOption() eq 'FramedHTML' ? ' target="_self"' : '') . '>'
. $self->StringToHTML($entry->Title())
. '</a>'
. '<div class=MGroupContent id=MGroupContent' . $entryNumber . '>'
. $entryOutput
. '</div>'
. '</div>'
. '</div>';
$groupLength += MENU_GROUP_LENGTH;
}
elsif ($entry->Type() == ::MENU_FILE())
{
my $targetOutputFile = $self->OutputFileOf($entry->Target());
# Dependency: BuildMenu() depends on how this formats file entries.
$output .=
'<div class=MEntry>'
. '<div class=MFile>'
. '<a href="' . $self->MakeRelativeURL($outputDirectory, $targetOutputFile) . '">'
. $self->StringToHTML( $entry->Title(), ADD_HIDDEN_BREAKS)
. '</a>'
. '</div>'
. '</div>';
$groupLength += MENU_FILE_LENGTH;
}
elsif ($entry->Type() == ::MENU_TEXT())
{
$output .=
'<div class=MEntry>'
. '<div class=MText>'
. $self->StringToHTML( $entry->Title() )
. '</div>'
. '</div>';
$groupLength += MENU_TEXT_LENGTH;
}
elsif ($entry->Type() == ::MENU_LINK())
{
$output .=
'<div class=MEntry>'
. '<div class=MLink>'
. '<a href="' . $entry->Target() . '"' . ($self->CommandLineOption() eq 'FramedHTML' ? ' target="_top"' : '') . '>'
. $self->StringToHTML( $entry->Title() )
. '</a>'
. '</div>'
. '</div>';
$groupLength += MENU_LINK_LENGTH;
}
elsif ($entry->Type() == ::MENU_INDEX())
{
my $indexFile = $self->IndexFileOf($entry->Target);
# Dependency: BuildMenu() depends on how this formats index entries.
$output .=
'<div class=MEntry>'
. '<div class=MIndex>'
. '<a href="' . $self->MakeRelativeURL( $outputDirectory, $self->IndexFileOf($entry->Target()) ) . '">'
. $self->StringToHTML( $entry->Title() )
. '</a>'
. '</div>'
. '</div>';
$groupLength += MENU_INDEX_LENGTH;
};
};
if (!$menuNumbersAndLengthsDone)
{ $menuLength += $groupLength; };
return ($output, $groupLength);
};
#
# Function: BuildContent
#
# Builds and returns the main page content.
#
# Parameters:
#
# sourceFile - The source <FileName>.
# parsedFile - The parsed source file as an arrayref of <NaturalDocs::Parser::ParsedTopic> objects.
#
# Returns:
#
# The page content in HTML.
#
sub BuildContent #(sourceFile, parsedFile)
{
my ($self, $sourceFile, $parsedFile) = @_;
$self->ResetToolTips();
$imageAnchorNumber = 1;
$imageContent = undef;
my $output = '<div id=Content>';
my $i = 0;
while ($i < scalar @$parsedFile)
{
my $anchor = $self->SymbolToHTMLSymbol($parsedFile->[$i]->Symbol());
my $scope = NaturalDocs::Topics->TypeInfo($parsedFile->[$i]->Type())->Scope();
# The anchors are closed, but not around the text, so the :hover CSS style won't accidentally kick in.
my $headerType;
if ($i == 0)
{ $headerType = 'h1'; }
elsif ($scope == ::SCOPE_START() || $scope == ::SCOPE_END())
{ $headerType = 'h2'; }
else
{ $headerType = 'h3'; };
$output .=
'<div class="C' . NaturalDocs::Topics->NameOfType($parsedFile->[$i]->Type(), 0, 1) . '">'
. '<div class=CTopic' . ($i == 0 ? ' id=MainTopic' : '') . '>'
. '<' . $headerType . ' class=CTitle>'
. '<a name="' . $anchor . '"></a>'
. $self->StringToHTML( $parsedFile->[$i]->Title(), ADD_HIDDEN_BREAKS)
. '</' . $headerType . '>';
my $hierarchy;
if (NaturalDocs::Topics->TypeInfo( $parsedFile->[$i]->Type() )->ClassHierarchy())
{
$hierarchy = $self->BuildClassHierarchy($sourceFile, $parsedFile->[$i]->Symbol());
};
my $summary;
if ($i == 0 || $scope == ::SCOPE_START() || $scope == ::SCOPE_END())
{
$summary .= $self->BuildSummary($sourceFile, $parsedFile, $i);
};
my $hasBody;
if (defined $hierarchy || defined $summary ||
defined $parsedFile->[$i]->Prototype() || defined $parsedFile->[$i]->Body())
{
$output .= '<div class=CBody>';
$hasBody = 1;
};
$output .= $hierarchy;
if (defined $parsedFile->[$i]->Prototype())
{
$output .= $self->BuildPrototype($parsedFile->[$i]->Type(), $parsedFile->[$i]->Prototype(), $sourceFile);
};
if (defined $parsedFile->[$i]->Body())
{
$output .= $self->NDMarkupToHTML( $sourceFile, $parsedFile->[$i]->Body(), $parsedFile->[$i]->Symbol(),
$parsedFile->[$i]->Package(), $parsedFile->[$i]->Type(),
$parsedFile->[$i]->Using() );
};
$output .= $summary;
if ($hasBody)
{ $output .= '</div>'; };
$output .=
'</div>' # CTopic
. '</div>' # CType
. "\n\n";
$i++;
};
$output .= '</div><!--Content-->';
return $output;
};
#
# Function: BuildSummary
#
# Builds a summary, either for the entire file or the current class/section.
#
# Parameters:
#
# sourceFile - The source <FileName> the summary appears in.
#
# parsedFile - A reference to the parsed source file.
#
# index - The index into the parsed file to start at. If undef or zero, it builds a summary for the entire file. If it's the
# index of a <TopicType> that starts or ends a scope, it builds a summary for that scope
#
# Returns:
#
# The summary in HTML.
#
sub BuildSummary #(sourceFile, parsedFile, index)
{
my ($self, $sourceFile, $parsedFile, $index) = @_;
my $completeSummary;
if (!defined $index || $index == 0)
{
$index = 0;
$completeSummary = 1;
}
else
{
# Skip the scope entry.
$index++;
};
if ($index + 1 >= scalar @$parsedFile)
{ return undef; };
my $scope = NaturalDocs::Topics->TypeInfo($parsedFile->[$index]->Type())->Scope();
# Return nothing if there's only one entry.
if (!$completeSummary && ($scope == ::SCOPE_START() || $scope == ::SCOPE_END()) )
{ return undef; };
my $indent = 0;
my $inGroup;
my $isMarked = 0;
my $output =
'<!--START_ND_SUMMARY-->'
. '<div class=Summary><div class=STitle>Summary</div>'
# Not all browsers get table padding right, so we need a div to apply the border.
. '<div class=SBorder>'
. '<table border=0 cellspacing=0 cellpadding=0 class=STable>';
while ($index < scalar @$parsedFile)
{
my $topic = $parsedFile->[$index];
my $scope = NaturalDocs::Topics->TypeInfo($topic->Type())->Scope();
if (!$completeSummary && ($scope == ::SCOPE_START() || $scope == ::SCOPE_END()) )
{ last; };
# Remove modifiers as appropriate for the current entry.
if ($scope == ::SCOPE_START() || $scope == ::SCOPE_END())
{
$indent = 0;
$inGroup = 0;
$isMarked = 0;
}
elsif ($topic->Type() eq ::TOPIC_GROUP())
{
if ($inGroup)
{ $indent--; };
$inGroup = 0;
$isMarked = 0;
};
$output .=
'<tr class="S' . ($index == 0 ? 'Main' : NaturalDocs::Topics->NameOfType($topic->Type(), 0, 1))
. ($indent ? ' SIndent' . $indent : '') . ($isMarked ? ' SMarked' : '') .'">'
. '<td class=SEntry>';
# Add the entry itself.
my $toolTipProperties;
# We only want a tooltip here if there's a protoype. Otherwise it's redundant.
if (defined $topic->Prototype())
{
my $tooltipID = $self->BuildToolTip($topic->Symbol(), $sourceFile, $topic->Type(),
$topic->Prototype(), $topic->Summary());
$toolTipProperties = $self->BuildToolTipLinkProperties($tooltipID);
};
$output .=
'<a href="#' . $self->SymbolToHTMLSymbol($parsedFile->[$index]->Symbol()) . '" ' . $toolTipProperties . '>'
. $self->StringToHTML( $parsedFile->[$index]->Title(), ADD_HIDDEN_BREAKS)
. '</a>';
$output .=
'</td><td class=SDescription>';
if (defined $parsedFile->[$index]->Body())
{
$output .= $self->NDMarkupToHTML($sourceFile, $parsedFile->[$index]->Summary(),
$parsedFile->[$index]->Symbol(), $parsedFile->[$index]->Package(),
$parsedFile->[$index]->Type(), $parsedFile->[$index]->Using(),
NDMARKUPTOHTML_SUMMARY);
};
$output .=
'</td></tr>';
# Prepare the modifiers for the next entry.
if ($scope == ::SCOPE_START() || $scope == ::SCOPE_END())
{
$indent = 1;
$inGroup = 0;
}
elsif ($topic->Type() eq ::TOPIC_GROUP())
{
if (!$inGroup)
{
$indent++;
$inGroup = 1;
};
};
$isMarked ^= 1;
$index++;
};
$output .=
'</table>'
. '</div>' # Body
. '</div>' # Summary
. "<!--END_ND_SUMMARY-->";
return $output;
};
#
# Function: BuildPrototype
#
# Builds and returns the prototype as HTML.
#
# Parameters:
#
# type - The <TopicType> the prototype is from.
# prototype - The prototype to format.
# file - The <FileName> the prototype was defined in.
#
# Returns:
#
# The prototype in HTML.
#
sub BuildPrototype #(type, prototype, file)
{
my ($self, $type, $prototype, $file) = @_;
my $language = NaturalDocs::Languages->LanguageOf($file);
my $prototypeObject = $language->ParsePrototype($type, $prototype);
my $output;
if ($prototypeObject->OnlyBeforeParameters())
{
$output =
# A blockquote to scroll it if it's too long.
'<blockquote>'
# A surrounding table as a hack to make the div form-fit.
. '<table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr>'
. '<td' . (NaturalDocs::Settings->HighlightCode() ? ' class="prettyprint"' : '') . '>'
. $self->ConvertAmpChars($prototypeObject->BeforeParameters())
. '</td>'
. '</tr></table>'
. '</blockquote>';
}
else
{
my $params = $prototypeObject->Parameters();
my $beforeParams = $prototypeObject->BeforeParameters();
my $afterParams = $prototypeObject->AfterParameters();
my $highlightClass = (NaturalDocs::Settings->HighlightCode() ? ' prettyprint ' : '');
# Determine what features the prototype has and its length.
my ($hasType, $hasTypePrefix, $hasNamePrefix, $hasDefaultValue, $hasDefaultValuePrefix);
my $maxParamLength = 0;
foreach my $param (@$params)
{
my $paramLength = length($param->Name());
if ($param->Type())
{
$hasType = 1;
$paramLength += length($param->Type()) + 1;
};
if ($param->TypePrefix())
{
$hasTypePrefix = 1;
$paramLength += length($param->TypePrefix()) + 1;
};
if ($param->NamePrefix())
{
$hasNamePrefix = 1;
$paramLength += length($param->NamePrefix());
};
if ($param->DefaultValue())
{
$hasDefaultValue = 1;
# The length of the default value part is either the longest word, or 1/3 the total, whichever is longer. We do this
# because we don't want parameter lines wrapping to more than three lines, and there's no guarantee that the line will
# wrap at all. There's a small possibility that it could still wrap to four lines with this code, but we don't need to go
# crazy(er) here.
my $thirdLength = length($param->DefaultValue()) / 3;
my @words = split(/ +/, $param->DefaultValue());
my $maxWordLength = 0;
foreach my $word (@words)
{
if (length($word) > $maxWordLength)
{ $maxWordLength = length($word); };
};
$paramLength += ($maxWordLength > $thirdLength ? $maxWordLength : $thirdLength) + 1;
};
if ($param->DefaultValuePrefix())
{
$hasDefaultValuePrefix = 1;
$paramLength += length($param->DefaultValuePrefix()) + 1;
};
if ($paramLength > $maxParamLength)
{ $maxParamLength = $paramLength; };
};
my $useCondensed = (length($beforeParams) + $maxParamLength + length($afterParams) > 80 ? 1 : 0);
my $parameterColumns = 1 + $hasType + $hasTypePrefix + $hasNamePrefix +
$hasDefaultValue + $hasDefaultValuePrefix + $useCondensed;
$output =
'<blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td>'
# Stupid hack to get it to work right in IE.
. '<table border=0 cellspacing=0 cellpadding=0><tr>'
. '<td class="PBeforeParameters ' . $highlightClass . '"' . ($useCondensed ? 'colspan=' . $parameterColumns : 'nowrap') . '>'
. $self->ConvertAmpChars($beforeParams);
if ($beforeParams && $beforeParams !~ /[\(\[\{\<]$/)
{ $output .= ' '; };
$output .=
'</td>';
for (my $i = 0; $i < scalar @$params; $i++)
{
if ($useCondensed)
{
$output .= '</tr><tr><td> </td>';
}
elsif ($i > 0)
{
# Go to the next row and and skip the BeforeParameters cell.
$output .= '</tr><tr><td></td>';
};
if ($language->TypeBeforeParameter())
{
if ($hasTypePrefix)
{
my $htmlTypePrefix = $self->ConvertAmpChars($params->[$i]->TypePrefix());
$htmlTypePrefix =~ s/ $/ /;
$output .=
'<td class="PTypePrefix ' . $highlightClass . '" nowrap>'
. $htmlTypePrefix
. '</td>';
};
if ($hasType)
{
$output .=
'<td class="PType ' . $highlightClass . '" nowrap>'
. $self->ConvertAmpChars($params->[$i]->Type()) . ' '
. '</td>';
};
if ($hasNamePrefix)
{
$output .=
'<td class="PParameterPrefix ' . $highlightClass . '" nowrap>'
. $self->ConvertAmpChars($params->[$i]->NamePrefix())
. '</td>';
};
$output .=
'<td class="PParameter ' . $highlightClass . '" nowrap' . ($useCondensed && !$hasDefaultValue ? ' width=100%' : '') . '>'
. $self->ConvertAmpChars($params->[$i]->Name())
. '</td>';
}
else # !$language->TypeBeforeParameter()
{
$output .=
'<td class="PParameter ' . $highlightClass . '" nowrap>'
. $self->ConvertAmpChars( $params->[$i]->NamePrefix() . $params->[$i]->Name() )
. '</td>';
if ($hasType || $hasTypePrefix)
{
my $typePrefix = $params->[$i]->TypePrefix();
if ($typePrefix)
{ $typePrefix .= ' '; };
$output .=
'<td class="PType ' . $highlightClass . '" nowrap' . ($useCondensed && !$hasDefaultValue ? ' width=100%' : '') . '>'
. ' ' . $self->ConvertAmpChars( $typePrefix . $params->[$i]->Type() )
. '</td>';
};
};
if ($hasDefaultValuePrefix)
{
$output .=
'<td class="PDefaultValuePrefix ' . $highlightClass . '">'
. ' ' . $self->ConvertAmpChars( $params->[$i]->DefaultValuePrefix() ) . ' '
. '</td>';
};
if ($hasDefaultValue)
{
$output .=
'<td class="PDefaultValue ' . $highlightClass . '" width=100%>'
. ($hasDefaultValuePrefix ? '' : ' ') . $self->ConvertAmpChars( $params->[$i]->DefaultValue() )
. '</td>';
};
};
if ($useCondensed)
{ $output .= '</tr><tr>'; };
$output .=
'<td class="PAfterParameters ' . $highlightClass . '"' . ($useCondensed ? 'colspan=' . $parameterColumns : 'nowrap') . '>'
. $self->ConvertAmpChars($afterParams);
if ($afterParams && $afterParams !~ /^[\)\]\}\>]/)
{ $output .= ' '; };
$output .=
'</td>'
. '</tr></table>'
# Hack.
. '</td></tr></table></blockquote>';
};
return $output;
};
#
# Function: BuildFooter
#
# Builds and returns the HTML footer for the page.
#
# Parameters:
#
# multiline - Whether it should be formatted on multiple lines or not.
#
# Dependencies:
#
# <Builder::HTML::UpdateFile()> and <Builder::HTML::UpdateIndex()> require this section to be surrounded with the exact
# strings "<div id=Footer>" and "</div><!--Footer-->".
#
sub BuildFooter #(bool multiline)
{
my ($self, $multiline) = @_;
my $footer = NaturalDocs::Menu->Footer();
my $timestamp = NaturalDocs::Menu->TimeStamp();
my $divider;
if ($multiline)
{ $divider = '</p><p>'; }
else
{ $divider = ' · '; };
my $output = '<div id=Footer>';
if ($multiline)
{ $output .= '<p>'; };
if (defined $footer)
{
$footer =~ s/\(c\)/©/gi;
$footer =~ s/\(tm\)/™/gi;
$footer =~ s/\(r\)/®/gi;
$output .= $footer . $divider;
};
if (defined $timestamp)
{
$output .= $timestamp . $divider;
};
$output .=
'<a href="' . NaturalDocs::Settings->AppURL() . '">'
. 'Generated by Natural Docs'
. '</a>';
if ($multiline)
{ $output .= '</p>'; };
$output .=
'</div><!--Footer-->';
return $output;
};
#
# Function: BuildToolTip
#
# Builds the HTML for a symbol's tooltip and stores it in <tooltipHTML>.
#
# Parameters:
#
# symbol - The target <SymbolString>.
# file - The <FileName> the target's defined in.
# type - The symbol <TopicType>.
# prototype - The target prototype, or undef for none.
# summary - The target summary, or undef for none.
#
# Returns:
#
# If a tooltip is necessary for the link, returns the tooltip ID. If not, returns undef.
#
sub BuildToolTip #(symbol, file, type, prototype, summary)
{
my ($self, $symbol, $file, $type, $prototype, $summary) = @_;
if (defined $prototype || defined $summary)
{
my $htmlSymbol = $self->SymbolToHTMLSymbol($symbol);
my $number = $tooltipSymbolsToNumbers{$htmlSymbol};
if (!defined $number)
{
$number = $tooltipNumber;
$tooltipNumber++;
$tooltipSymbolsToNumbers{$htmlSymbol} = $number;
$tooltipHTML .=
'<div class=CToolTip id="tt' . $number . '">'
. '<div class=C' . NaturalDocs::Topics->NameOfType($type, 0, 1) . '>';
if (defined $prototype)
{
$tooltipHTML .= $self->BuildPrototype($type, $prototype, $file);
};
if (defined $summary)
{
# The fact that we don't have scope or using shouldn't matter because links shouldn't be included in the style anyway.
$summary = $self->NDMarkupToHTML($file, $summary, undef, undef, $type, undef, NDMARKUPTOHTML_TOOLTIP);
$tooltipHTML .= $summary;
};
$tooltipHTML .=
'</div>'
. '</div>';
};
return 'tt' . $number;
}
else
{ return undef; };
};
#
# Function: BuildToolTips
#
# Builds and returns the tooltips for the page in HTML.
#
sub BuildToolTips
{
my $self = shift;
return "\n<!--START_ND_TOOLTIPS-->\n" . $tooltipHTML . "<!--END_ND_TOOLTIPS-->\n\n";
};
#
# Function: BuildClassHierarchy
#
# Builds and returns a class hierarchy diagram for the passed class, if applicable.
#
# Parameters:
#
# file - The source <FileName>.
# class - The class <SymbolString> to build the hierarchy of.
#
sub BuildClassHierarchy #(file, symbol)
{
my ($self, $file, $symbol) = @_;
my @parents = NaturalDocs::ClassHierarchy->ParentsOf($symbol);
@parents = sort { ::StringCompare($a, $b) } @parents;
my @children = NaturalDocs::ClassHierarchy->ChildrenOf($symbol);
@children = sort { ::StringCompare($a, $b) } @children;
if (!scalar @parents && !scalar @children)
{ return undef; };
my $output =
'<div class=ClassHierarchy>';
if (scalar @parents)
{
$output .='<table border=0 cellspacing=0 cellpadding=0><tr><td>';
foreach my $parent (@parents)
{
$output .= $self->BuildClassHierarchyEntry($file, $parent, 'CHParent', 1);
};
$output .= '</td></tr></table><div class=CHIndent>';
};
$output .=
'<table border=0 cellspacing=0 cellpadding=0><tr><td>'
. $self->BuildClassHierarchyEntry($file, $symbol, 'CHCurrent', undef)
. '</td></tr></table>';
if (scalar @children)
{
$output .=
'<div class=CHIndent>'
. '<table border=0 cellspacing=0 cellpadding=0><tr><td>';
if (scalar @children <= 5)
{
for (my $i = 0; $i < scalar @children; $i++)
{ $output .= $self->BuildClassHierarchyEntry($file, $children[$i], 'CHChild', 1); };
}
else
{
for (my $i = 0; $i < 4; $i++)
{ $output .= $self->BuildClassHierarchyEntry($file, $children[$i], 'CHChild', 1); };
$output .= '<div class=CHChildNote><div class=CHEntry>' . (scalar @children - 4) . ' other children</div></div>';
};
$output .=
'</td></tr></table>'
. '</div>';
};
if (scalar @parents)
{ $output .= '</div>'; };
$output .=
'</div>';
return $output;
};
#
# Function: BuildClassHierarchyEntry
#
# Builds and returns a single class hierarchy entry.
#
# Parameters:
#
# file - The source <FileName>.
# symbol - The class <SymbolString> whose entry is getting built.
# style - The style to apply to the entry, such as <CHParent>.
# link - Whether to build a link for this class or not. When building the selected class' entry, this should be false. It will
# automatically handle whether the symbol is defined or not.
#
sub BuildClassHierarchyEntry #(file, symbol, style, link)
{
my ($self, $file, $symbol, $style, $link) = @_;
my @identifiers = NaturalDocs::SymbolString->IdentifiersOf($symbol);
my $name = join(NaturalDocs::Languages->LanguageOf($file)->PackageSeparator(), @identifiers);
$name = $self->StringToHTML($name);
my $output = '<div class=' . $style . '><div class=CHEntry>';
if ($link)
{
my $target = NaturalDocs::SymbolTable->Lookup($symbol, $file);
if (defined $target)
{
my $targetFile;
if ($target->File() ne $file)
{ $targetFile = $self->MakeRelativeURL( $self->OutputFileOf($file), $self->OutputFileOf($target->File()), 1 ); };
# else leave it undef
my $targetTooltipID = $self->BuildToolTip($symbol, $target->File(), $target->Type(),
$target->Prototype(), $target->Summary());
my $toolTipProperties = $self->BuildToolTipLinkProperties($targetTooltipID);
$output .= '<a href="' . $targetFile . '#' . $self->SymbolToHTMLSymbol($symbol) . '" '
. 'class=L' . NaturalDocs::Topics->NameOfType($target->Type(), 0, 1) . ' ' . $toolTipProperties . '>'
. $name . '</a>';
}
else
{ $output .= $name; };
}
else
{ $output .= $name; };
$output .= '</div></div>';
return $output;
};
#
# Function: OpeningBrowserStyles
#
# Returns the JavaScript that will add opening browser styles if necessary.
#
sub OpeningBrowserStyles
{
my $self = shift;
return
'<script language=JavaScript><!--' . "\n"
# IE 4 and 5 don't understand 'undefined', so you can't say '!= undefined'.
. 'if (browserType) {'
. 'document.write("<div class=" + browserType + ">");'
. 'if (browserVer) {'
. 'document.write("<div class=" + browserVer + ">"); }'
. '}'
. '// --></script>';
};
#
# Function: ClosingBrowserStyles
#
# Returns the JavaScript that will close browser styles if necessary.
#
sub ClosingBrowserStyles
{
my $self = shift;
return
'<script language=JavaScript><!--' . "\n"
. 'if (browserType) {'
. 'if (browserVer) {'
. 'document.write("</div>"); }'
. 'document.write("</div>");'
. '}'
. '// --></script>';
};
#
# Function: StandardComments
#
# Returns the standard HTML comments that should be included in every generated file. This includes <IEWebMark()>, so this
# really is required for proper functionality.
#
sub StandardComments
{
my $self = shift;
return "\n\n"
. '<!-- Generated by Natural Docs, version ' . NaturalDocs::Settings->TextAppVersion() . ' -->' . "\n"
. '<!-- ' . NaturalDocs::Settings->AppURL() . ' -->' . "\n\n"
. $self->IEWebMark() . "\n\n";
};
#
# Function: IEWebMark
#
# Returns the HTML comment necessary to get around the security warnings in IE starting with Windows XP Service Pack 2.
#
# With this mark, the HTML page is treated as if it were in the Internet security zone instead of the Local Machine zone. This
# prevents the lockdown on scripting that causes an error message to appear with each page.
#
# More Information:
#
# - http://www.microsoft.com/technet/prodtechnol/winxppro/maintain/sp2brows.mspx#EHAA
# - http://www.phdcc.com/xpsp2.htm#markoftheweb
#
sub IEWebMark
{
my $self = shift;
return '<!-- saved from url=(0026)http://www.naturaldocs.org -->';
};
###############################################################################
# Group: Index Functions
#
# Function: BuildIndexPages
#
# Builds an index file or files.
#
# Parameters:
#
# type - The <TopicType> the index is limited to, or undef for none.
# indexSections - An arrayref of sections, each section being an arrayref <NaturalDocs::SymbolTable::IndexElement>
# objects. The first section is for symbols, the second for numbers, and the rest for A through Z.
# beginIndexPage - All the content of the HTML page up to where the index content should appear.
# endIndexPage - All the content of the HTML page past where the index should appear.
# beginSearchResultsPage - All the content of the HTML page up to where the search results content should appear.
# endSearchResultsPage - All the content of the HTML page past where the search results content should appear.
#
# Returns:
#
# The number of pages in the index.
#
sub BuildIndexPages #(TopicType type, NaturalDocs::SymbolTable::IndexElement[] indexSections, string beginIndexPage, string endIndexPage, string beginSearchResultsPage, string endSearchResultsPage) => int
{
my ($self, $type, $indexSections, $beginIndexPage, $endIndexPage, $beginSearchResultsPage, $endSearchResultsPage) = @_;
# Build the content.
my ($indexHTMLSections, $tooltipHTMLSections, $searchResultsHTMLSections) = $self->BuildIndexSections($indexSections);
# Generate the search result pages.
for (my $i = 0; $i < 28; $i++)
{
if ($searchResultsHTMLSections->[$i])
{
my $searchResultsFileName = $self->SearchResultsFileOf($type, $searchExtensions[$i]);
open(INDEXFILEHANDLE, '>' . $searchResultsFileName)
or die "Couldn't create output file " . $searchResultsFileName . ".\n";
binmode(INDEXFILEHANDLE, ':encoding(UTF-8)');
print INDEXFILEHANDLE
$beginSearchResultsPage
. '<div class=SRStatus id=Loading>Loading...</div>'
. '<table border=0 cellspacing=0 cellpadding=0>'
. $searchResultsHTMLSections->[$i]
. '</table>'
. '<div class=SRStatus id=Searching>Searching...</div>'
. '<div class=SRStatus id=NoMatches>No Matches</div>'
. '<script type="text/javascript"><!--' . "\n"
. 'document.getElementById("Loading").style.display="none";' . "\n"
. 'document.getElementById("NoMatches").style.display="none";' . "\n"
. 'var searchResults = new SearchResults("searchResults", "' . $self->CommandLineOption() . '");' . "\n"
. 'searchResults.Search();' . "\n"
. '--></script>'
. $endSearchResultsPage;
close(INDEXFILEHANDLE);
};
};
if (!$self->MadeEmptySearchResultsPage())
{
my $emptySearchResultsFileName = NaturalDocs::File->JoinPaths( $self->SearchResultsDirectory(), 'NoResults.html' );
open(INDEXFILEHANDLE, '>' . $emptySearchResultsFileName)
or die "Couldn't create output file " . $emptySearchResultsFileName . ".\n";
binmode(INDEXFILEHANDLE, ':encoding(UTF-8)');
print INDEXFILEHANDLE
$beginSearchResultsPage
. '<div class=SRStatus id=NoMatches>No Matches</div>'
. $endSearchResultsPage;
close(INDEXFILEHANDLE);
$self->SetMadeEmptySearchResultsPage(1);
};
# Generate the index pages.
my $page = 1;
my $pageSize = 0;
my @pageLocations;
# The maximum page size acceptable before starting a new page. Note that this doesn't include beginPage and endPage,
# because we don't want something like a large menu screwing up the calculations.
use constant PAGESIZE_LIMIT => 50000;
# File the pages.
for (my $i = 0; $i < scalar @$indexHTMLSections; $i++)
{
if (!defined $indexHTMLSections->[$i])
{ next; };
$pageSize += length($indexHTMLSections->[$i]) + length($tooltipHTMLSections->[$i]);
$pageLocations[$i] = $page;
if ($pageSize + length($indexHTMLSections->[$i+1]) + length($tooltipHTMLSections->[$i+1]) > PAGESIZE_LIMIT)
{
$page++;
$pageSize = 0;
};
};
# Build the pages.
my $indexFileName;
$page = -1;
my $oldPage = -1;
my $tooltips;
my $firstHeading;
for (my $i = 0; $i < scalar @$indexHTMLSections; $i++)
{
if (!defined $indexHTMLSections->[$i])
{ next; };
$page = $pageLocations[$i];
# Switch files if we need to.
if ($page != $oldPage)
{
if ($oldPage != -1)
{
print INDEXFILEHANDLE '</table>' . $tooltips . $endIndexPage;
close(INDEXFILEHANDLE);
$tooltips = undef;
};
$indexFileName = $self->IndexFileOf($type, $page);
open(INDEXFILEHANDLE, '>' . $indexFileName)
or die "Couldn't create output file " . $indexFileName . ".\n";
binmode(INDEXFILEHANDLE, ':encoding(UTF-8)');
print INDEXFILEHANDLE $beginIndexPage . $self->BuildIndexNavigationBar($type, $page, \@pageLocations)
. '<table border=0 cellspacing=0 cellpadding=0>';
$oldPage = $page;
$firstHeading = 1;
};
print INDEXFILEHANDLE
'<tr>'
. '<td class=IHeading' . ($firstHeading ? ' id=IFirstHeading' : '') . '>'
. '<a name="' . $indexAnchors[$i] . '"></a>'
. $indexHeadings[$i]
. '</td>'
. '<td></td>'
. '</tr>'
. $indexHTMLSections->[$i];
$firstHeading = 0;
$tooltips .= $tooltipHTMLSections->[$i];
};
if ($page != -1)
{
print INDEXFILEHANDLE '</table>' . $tooltips . $endIndexPage;
close(INDEXFILEHANDLE);
}
# Build a dummy page so there's something at least.
else
{
$indexFileName = $self->IndexFileOf($type, 1);
open(INDEXFILEHANDLE, '>' . $indexFileName)
or die "Couldn't create output file " . $indexFileName . ".\n";
binmode(INDEXFILEHANDLE, ':encoding(UTF-8)');
print INDEXFILEHANDLE
$beginIndexPage
. $self->BuildIndexNavigationBar($type, 1, \@pageLocations)
. 'There are no entries in the ' . lc( NaturalDocs::Topics->NameOfType($type) ) . ' index.'
. $endIndexPage;
close(INDEXFILEHANDLE);
};
return $page;
};
#
# Function: BuildIndexSections
#
# Builds and returns the index and search results sections in HTML.
#
# Parameters:
#
# index - An arrayref of sections, each section being an arrayref <NaturalDocs::SymbolTable::IndexElement> objects.
# The first section is for symbols, the second for numbers, and the rest for A through Z.
#
# Returns:
#
# The arrayref ( indexSections, tooltipSections, searchResultsSections ).
#
# Index 0 is the symbols, index 1 is the numbers, and each following index is A through Z. The content of each section
# is its HTML, or undef if there is nothing for that section.
#
sub BuildIndexSections #(NaturalDocs::SymbolTable::IndexElement[] index) => ( string[], string[], string[] )
{
my ($self, $indexSections) = @_;
$self->ResetToolTips();
%searchResultIDs = ( );
my $contentSections = [ ];
my $tooltipSections = [ ];
my $searchResultsSections = [ ];
for (my $section = 0; $section < scalar @$indexSections; $section++)
{
if (defined $indexSections->[$section])
{
my $total = scalar @{$indexSections->[$section]};
for (my $i = 0; $i < $total; $i++)
{
my $id;
if ($i == 0)
{
if ($total == 1)
{ $id = 'IOnlySymbolPrefix'; }
else
{ $id = 'IFirstSymbolPrefix'; };
}
elsif ($i == $total - 1)
{ $id = 'ILastSymbolPrefix'; };
my ($content, $searchResult) = $self->BuildIndexElement($indexSections->[$section]->[$i], $id);
$contentSections->[$section] .= $content;
$searchResultsSections->[$section] .= $searchResult;
};
$tooltipSections->[$section] .= $self->BuildToolTips();
$self->ResetToolTips(1);
};
};
return ( $contentSections, $tooltipSections, $searchResultsSections );
};
#
# Function: BuildIndexElement
#
# Converts a <NaturalDocs::SymbolTable::IndexElement> to HTML and returns it. It will handle all sub-elements automatically.
#
# Parameters:
#
# element - The <NaturalDocs::SymbolTable::IndexElement> to build.
# cssID - The CSS ID to apply to the prefix.
#
# Recursion-Only Parameters:
#
# These parameters are used internally for recursion, and should not be set.
#
# symbol - If the element is below symbol level, the <SymbolString> to use.
# package - If the element is below package level, the package <SymbolString> to use.
# hasPackage - Whether the element is below package level. Is necessary because package may need to be undef.
#
# Returns:
#
# The array ( indexHTML, searchResultHTML ) which is the element in the respective HTML forms.
#
sub BuildIndexElement #(NaturalDocs::SymbolTable::IndexElement element, string cssID, SymbolString symbol, SymbolString package, bool hasPackage) => ( string, string )
{
my ($self, $element, $cssID, $symbol, $package, $hasPackage) = @_;
# If we're doing a file sub-index entry...
if ($hasPackage)
{
my ($inputDirectory, $relativePath) = NaturalDocs::Settings->SplitFromInputDirectory($element->File());
return $self->BuildIndexLink($self->StringToHTML($relativePath, ADD_HIDDEN_BREAKS), $symbol,
$package, $element->File(), $element->Type(),
$element->Prototype(), $element->Summary(), 'IFile');
}
# If we're doing a package sub-index entry...
elsif (defined $symbol)
{
my $text;
if ($element->Package())
{
$text = NaturalDocs::SymbolString->ToText($element->Package(), $element->PackageSeparator());
$text = $self->StringToHTML($text, ADD_HIDDEN_BREAKS);
}
else
{ $text = 'Global'; };
if (!$element->HasMultipleFiles())
{
return $self->BuildIndexLink($text, $symbol, $element->Package(), $element->File(), $element->Type(),
$element->Prototype(), $element->Summary(), 'IParent');
}
else
{
my $indexHTML =
'<span class=IParent>'
. $text
. '</span>'
. '<div class=ISubIndex>';
my $searchResultHTML = $indexHTML;
my $fileElements = $element->File();
foreach my $fileElement (@$fileElements)
{
my ($i, $s) = $self->BuildIndexElement($fileElement, $cssID, $symbol, $element->Package(), 1);
$indexHTML .= $i;
$searchResultHTML .= $s;
};
$indexHTML .= '</div>';
$searchResultHTML .= '</div>';
return ($indexHTML, $searchResultHTML);
};
}
# If we're doing a top-level symbol entry...
else
{
my $symbolText = $self->StringToHTML($element->SortableSymbol(), ADD_HIDDEN_BREAKS);
my $symbolPrefix = $self->StringToHTML($element->IgnoredPrefix());
my $searchResultID = $self->StringToSearchResultID($element->SortableSymbol());
my $indexHTML =
'<tr>'
. '<td class=ISymbolPrefix' . ($cssID ? ' id=' . $cssID : '') . '>'
. ($symbolPrefix || ' ')
. '</td><td class=IEntry>';
my $searchResultsHTML =
'<div class=SRResult id=' . $searchResultID . '><div class=IEntry>';
if ($symbolPrefix)
{ $searchResultsHTML .= '<span class=ISymbolPrefix>' . $symbolPrefix . '</span>'; };
if (!$element->HasMultiplePackages())
{
my $packageText;
if (defined $element->Package())
{
$packageText = NaturalDocs::SymbolString->ToText($element->Package(), $element->PackageSeparator());
$packageText = $self->StringToHTML($packageText, ADD_HIDDEN_BREAKS);
};
if (!$element->HasMultipleFiles())
{
my ($i, $s) =
$self->BuildIndexLink($symbolText, $element->Symbol(), $element->Package(), $element->File(),
$element->Type(), $element->Prototype(), $element->Summary(), 'ISymbol');
$indexHTML .= $i;
$searchResultsHTML .= $s;
if (defined $packageText)
{
$indexHTML .=
', <span class=IParent>'
. $packageText
. '</span>';
$searchResultsHTML .=
', <span class=IParent>'
. $packageText
. '</span>';
};
}
else # hasMultipleFiles but not multiplePackages
{
$indexHTML .=
'<span class=ISymbol>'
. $symbolText
. '</span>';
$searchResultsHTML .=
q{<a href="javascript:searchResults.Toggle('} . $searchResultID . q{')" class=ISymbol>}
. $symbolText
. '</a>';
my $output;
if (defined $packageText)
{
$output .=
', <span class=IParent>'
. $packageText
. '</span>';
};
$output .=
'<div class=ISubIndex>';
$indexHTML .= $output;
$searchResultsHTML .= $output;
my $fileElements = $element->File();
foreach my $fileElement (@$fileElements)
{
my ($i, $s) = $self->BuildIndexElement($fileElement, $cssID, $element->Symbol(), $element->Package(), 1);
$indexHTML .= $i;
$searchResultsHTML .= $s;
};
$indexHTML .= '</div>';
$searchResultsHTML .= '</div>';
};
}
else # hasMultiplePackages
{
$indexHTML .=
'<span class=ISymbol>'
. $symbolText
. '</span>'
. '<div class=ISubIndex>';
$searchResultsHTML .=
q{<a href="javascript:searchResults.Toggle('} . $searchResultID . q{')" class=ISymbol>}
. $symbolText
. '</a>'
. '<div class=ISubIndex>';
my $packageElements = $element->Package();
foreach my $packageElement (@$packageElements)
{
my ($i, $s) = $self->BuildIndexElement($packageElement, $cssID, $element->Symbol());
$indexHTML .= $i;
$searchResultsHTML .= $s;
};
$indexHTML .= '</div>';
$searchResultsHTML .= '</div>';
};
$indexHTML .= '</td></tr>';
$searchResultsHTML .= '</div></div>';
return ($indexHTML, $searchResultsHTML);
};
};
#
# Function: BuildIndexLink
#
# Builds and returns the HTML associated with an index link. The HTML will be the a href tag, the text, and the closing tag.
#
# Parameters:
#
# text - The text of the link *in HTML*. Use <IndexSymbolToHTML()> if necessary.
# symbol - The partial <SymbolString> to link to.
# package - The package <SymbolString> of the symbol.
# file - The <FileName> the symbol is defined in.
# type - The <TopicType> of the symbol.
# prototype - The prototype of the symbol, or undef if none.
# summary - The summary of the symbol, or undef if none.
# style - The CSS style to apply to the link.
#
# Returns:
#
# The array ( indexHTML, searchResultHTML ) which is the link in the respective forms.
#
sub BuildIndexLink #(string text, SymbolString symbol, SymbolString package, FileName file, TopicType type, string prototype, string summary, string style) => ( string, string )
{
my ($self, $text, $symbol, $package, $file, $type, $prototype, $summary, $style) = @_;
$symbol = NaturalDocs::SymbolString->Join($package, $symbol);
my $targetTooltipID = $self->BuildToolTip($symbol, $file, $type, $prototype, $summary);
my $toolTipProperties = $self->BuildToolTipLinkProperties($targetTooltipID);
my $indexHTML = '<a href="' . $self->MakeRelativeURL( $self->IndexDirectory(), $self->OutputFileOf($file) )
. '#' . $self->SymbolToHTMLSymbol($symbol) . '" ' . $toolTipProperties . ' '
. 'class=' . $style . '>' . $text . '</a>';
my $searchResultHTML = '<a href="' . $self->MakeRelativeURL( $self->SearchResultsDirectory(), $self->OutputFileOf($file) )
. '#' . $self->SymbolToHTMLSymbol($symbol) . '" '
. ($self->CommandLineOption eq 'HTML' ? 'target=_parent ' : '')
. 'class=' . $style . '>' . $text . '</a>';
return ($indexHTML, $searchResultHTML);
};
#
# Function: BuildIndexNavigationBar
#
# Builds a navigation bar for a page of the index.
#
# Parameters:
#
# type - The <TopicType> of the index, or undef for general.
# page - The page of the index the navigation bar is for.
# locations - An arrayref of the locations of each section. Index 0 is for the symbols, index 1 for the numbers, and the rest
# for each letter. The values are the page numbers where the sections are located.
#
sub BuildIndexNavigationBar #(type, page, locations)
{
my ($self, $type, $page, $locations) = @_;
my $output = '<div class=INavigationBar>';
for (my $i = 0; $i < scalar @indexHeadings; $i++)
{
if ($i != 0)
{ $output .= ' · '; };
if (defined $locations->[$i])
{
$output .= '<a href="';
if ($locations->[$i] != $page)
{ $output .= $self->RelativeIndexFileOf($type, $locations->[$i]); };
$output .= '#' . $indexAnchors[$i] . '">' . $indexHeadings[$i] . '</a>';
}
else
{
$output .= $indexHeadings[$i];
};
};
$output .= '</div>';
return $output;
};
###############################################################################
# Group: File Functions
#
# Function: PurgeIndexFiles
#
# Removes all or some of the output files for an index.
#
# Parameters:
#
# type - The index <TopicType>.
# indexSections - An arrayref of sections, each section being an arrayref <NaturalDocs::SymbolTable::IndexElement>
# objects. The first section is for symbols, the second for numbers, and the rest for A through Z. May be
# undef.
# startingPage - If defined, only pages starting with this number will be removed. Otherwise all pages will be removed.
#
sub PurgeIndexFiles #(TopicType type, optional NaturalDocs::SymbolTable::IndexElement[] indexSections, optional int startingPage)
{
my ($self, $type, $indexSections, $page) = @_;
# First the regular index pages.
if (!defined $page)
{ $page = 1; };
for (;;)
{
my $file = $self->IndexFileOf($type, $page);
if (-e $file)
{
unlink($file);
$page++;
}
else
{
last;
};
};
# Next the search results.
for (my $i = 0; $i < 28; $i++)
{
if (!$indexSections || !$indexSections->[$i])
{
my $file = $self->SearchResultsFileOf($type, $searchExtensions[$i]);
if (-e $file)
{ unlink($file); };
};
};
};
#
# Function: OutputFileOf
#
# Returns the output file name of the source file. Will be undef if it is not a file from a valid input directory.
#
sub OutputFileOf #(sourceFile)
{
my ($self, $sourceFile) = @_;
my ($inputDirectory, $relativeSourceFile) = NaturalDocs::Settings->SplitFromInputDirectory($sourceFile);
if (!defined $inputDirectory)
{ return undef; };
my $outputDirectory = NaturalDocs::Settings->OutputDirectoryOf($self);
my $inputDirectoryName = NaturalDocs::Settings->InputDirectoryNameOf($inputDirectory);
$outputDirectory = NaturalDocs::File->JoinPaths( $outputDirectory,
'files' . ($inputDirectoryName != 1 ? $inputDirectoryName : ''), 1 );
# We need to change any extensions to dashes because Apache will think file.pl.html is a script.
# We also need to add a dash if the file doesn't have an extension so there'd be no conflicts with index.html,
# FunctionIndex.html, etc.
if (!($relativeSourceFile =~ tr/./-/))
{ $relativeSourceFile .= '-'; };
$relativeSourceFile =~ tr/ &?(){};#/_/;
$relativeSourceFile .= '.html';
return NaturalDocs::File->JoinPaths($outputDirectory, $relativeSourceFile);
};
#
# Function: OutputImageOf
#
# Returns the output image file name of the source image file. Will be undef if it is not a file from a valid input directory.
#
sub OutputImageOf #(sourceImageFile)
{
my ($self, $sourceImageFile) = @_;
my $outputDirectory = NaturalDocs::Settings->OutputDirectoryOf($self);
my $topLevelDirectory;
my ($inputDirectory, $relativeImageFile) = NaturalDocs::Settings->SplitFromInputDirectory($sourceImageFile);
if (defined $inputDirectory)
{
my $inputDirectoryName = NaturalDocs::Settings->InputDirectoryNameOf($inputDirectory);
$topLevelDirectory = 'files' . ($inputDirectoryName != 1 ? $inputDirectoryName : '');
}
else
{
($inputDirectory, $relativeImageFile) = NaturalDocs::Settings->SplitFromImageDirectory($sourceImageFile);
if (!defined $inputDirectory)
{ return undef; };
my $inputDirectoryName = NaturalDocs::Settings->ImageDirectoryNameOf($inputDirectory);
$topLevelDirectory = 'images' . ($inputDirectoryName != 1 ? $inputDirectoryName : '');
}
$outputDirectory = NaturalDocs::File->JoinPaths($outputDirectory, $topLevelDirectory, 1);
$relativeImageFile =~ tr/ /_/;
return NaturalDocs::File->JoinPaths($outputDirectory, $relativeImageFile);
};
#
# Function: IndexDirectory
#
# Returns the directory of the index files.
#
sub IndexDirectory
{
my $self = shift;
return NaturalDocs::File->JoinPaths( NaturalDocs::Settings->OutputDirectoryOf($self), 'index', 1);
};
#
# Function: IndexFileOf
#
# Returns the output file name of the index file.
#
# Parameters:
#
# type - The <TopicType> of the index.
# page - The page number. Undef is the same as one.
#
sub IndexFileOf #(type, page)
{
my ($self, $type, $page) = @_;
return NaturalDocs::File->JoinPaths( $self->IndexDirectory(), $self->RelativeIndexFileOf($type, $page) );
};
#
# Function: RelativeIndexFileOf
#
# Returns the output file name of the index file, relative to other index files.
#
# Parameters:
#
# type - The <TopicType> of the index.
# page - The page number. Undef is the same as one.
#
sub RelativeIndexFileOf #(type, page)
{
my ($self, $type, $page) = @_;
return NaturalDocs::Topics->NameOfType($type, 1, 1) . (defined $page && $page != 1 ? $page : '') . '.html';
};
#
# Function: SearchResultsDirectory
#
# Returns the directory of the search results files.
#
sub SearchResultsDirectory
{
my $self = shift;
return NaturalDocs::File->JoinPaths( NaturalDocs::Settings->OutputDirectoryOf($self), 'search', 1);
};
#
# Function: SearchResultsFileOf
#
# Returns the output file name of the search result file.
#
# Parameters:
#
# type - The <TopicType> of the index.
# extra - The string to add to the end of the file name, such as "A" or "Symbols".
#
sub SearchResultsFileOf #(TopicType type, string extra)
{
my ($self, $type, $extra) = @_;
my $fileName = NaturalDocs::Topics->NameOfType($type, 1, 1) . $extra . '.html';
return NaturalDocs::File->JoinPaths( $self->SearchResultsDirectory(), $fileName );
};
#
# Function: CSSDirectory
#
# Returns the directory of the CSS files.
#
sub CSSDirectory
{
my $self = shift;
return NaturalDocs::File->JoinPaths( NaturalDocs::Settings->OutputDirectoryOf($self), 'styles', 1);
};
#
# Function: MainCSSFile
#
# Returns the location of the main CSS file.
#
sub MainCSSFile
{
my $self = shift;
return NaturalDocs::File->JoinPaths( $self->CSSDirectory(), 'main.css' );
};
#
# Function: JavaScriptDirectory
#
# Returns the directory of the JavaScript files.
#
sub JavaScriptDirectory
{
my $self = shift;
return NaturalDocs::File->JoinPaths( NaturalDocs::Settings->OutputDirectoryOf($self), 'javascript', 1);
};
#
# Function: MainJavaScriptFile
#
# Returns the location of the main JavaScript file.
#
sub MainJavaScriptFile
{
my $self = shift;
return NaturalDocs::File->JoinPaths( $self->JavaScriptDirectory(), 'main.js' );
};
#
# Function: PrettifyJavaScriptFile
#
# Returns the location of the Google Prettify JavaScript file.
#
sub PrettifyJavaScriptFile
{
my $self = shift;
return NaturalDocs::File->JoinPaths( $self->JavaScriptDirectory(), 'prettify.js' );
};
#
# Function: SearchDataJavaScriptFile
#
# Returns the location of the search data JavaScript file.
#
sub SearchDataJavaScriptFile
{
my $self = shift;
return NaturalDocs::File->JoinPaths( $self->JavaScriptDirectory(), 'searchdata.js' );
};
###############################################################################
# Group: Support Functions
#
# Function: IndexTitleOf
#
# Returns the page title of the index file.
#
# Parameters:
#
# type - The type of index.
#
sub IndexTitleOf #(type)
{
my ($self, $type) = @_;
return ($type eq ::TOPIC_GENERAL() ? '' : NaturalDocs::Topics->NameOfType($type) . ' ') . 'Index';
};
#
# Function: MakeRelativeURL
#
# Returns a relative path between two files in the output tree and returns it in URL format.
#
# Parameters:
#
# baseFile - The base <FileName> in local format, *not* in URL format.
# targetFile - The target <FileName> of the link in local format, *not* in URL format.
# baseHasFileName - Whether baseFile has a file name attached or is just a path.
#
# Returns:
#
# The relative URL to the target.
#
sub MakeRelativeURL #(FileName baseFile, FileName targetFile, bool baseHasFileName) -> string relativeURL
{
my ($self, $baseFile, $targetFile, $baseHasFileName) = @_;
if ($baseHasFileName)
{ $baseFile = NaturalDocs::File->NoFileName($baseFile) };
my $relativePath = NaturalDocs::File->MakeRelativePath($baseFile, $targetFile);
return $self->ConvertAmpChars( NaturalDocs::File->ConvertToURL($relativePath) );
};
#
# Function: StringToHTML
#
# Converts a text string to HTML. Does not apply paragraph tags or accept formatting tags.
#
# Parameters:
#
# string - The string to convert.
# addHiddenBreaks - Whether to add hidden breaks to the string. You can use <ADD_HIDDEN_BREAKS> for this parameter
# if you want to make the calling code clearer.
#
# Returns:
#
# The string in HTML.
#
sub StringToHTML #(string, addHiddenBreaks)
{
my ($self, $string, $addHiddenBreaks) = @_;
$string =~ s/&/&/g;
$string =~ s/</</g;
$string =~ s/>/>/g;
# Me likey the fancy quotes. They work in IE 4+, Mozilla, and Opera 5+. We've already abandoned NS4 with the CSS
# styles, so might as well.
$string =~ s/^\'/‘/gm;
$string =~ s/([\ \(\[\{])\'/$1‘/g;
$string =~ s/\'/’/g;
$string =~ s/^\"/“/gm;
$string =~ s/([\ \(\[\{])\"/$1“/g;
$string =~ s/\"/”/g;
# Me likey the double spaces too. As you can probably tell, I like print-formatting better than web-formatting. The indented
# paragraphs without blank lines in between them do become readable when you have fancy quotes and double spaces too.
$string = $self->AddDoubleSpaces($string);
if ($addHiddenBreaks)
{ $string = $self->AddHiddenBreaks($string); };
return $string;
};
#
# Function: SymbolToHTMLSymbol
#
# Converts a <SymbolString> to a HTML symbol, meaning one that is safe to include in anchor and link tags. You don't need
# to pass the result to <ConvertAmpChars()>.
#
sub SymbolToHTMLSymbol #(symbol)
{
my ($self, $symbol) = @_;
my @identifiers = NaturalDocs::SymbolString->IdentifiersOf($symbol);
my $htmlSymbol = join('.', @identifiers);
# If only Mozilla was nice about putting special characters in URLs like IE and Opera are, I could leave spaces in and replace
# "<>& with their amp chars. But alas, Mozilla shows them as %20, etc. instead. It would have made for nice looking URLs.
$htmlSymbol =~ tr/ \"<>\?&%/_/d;
return $htmlSymbol;
};
#
# Function: StringToSearchResultID
#
# Takes a text string and translates it into something that can be used as a CSS ID.
#
# Parameters:
#
# string - The string to convert
# dontIncrement - If set, it reuses the last generated ID. Otherwise it generates a new one if it matches a previously
# generated one in a case-insensitive way.
#
sub StringToSearchResultID #(string string, bool dontIncrement = 0) => string
{
my ($self, $string, $dontIncrement) = @_;
$string =~ s/\_/_und/g;
$string =~ s/ +/_spc/g;
my %translation = ( '~' => '_til', '!' => '_exc', '@' => '_att', '#' => '_num', '$' => '_dol', '%' => '_pct', '^' => '_car',
'&' => '_amp', '*' => '_ast', '(' => '_lpa', ')' => '_rpa', '-' => '_min', '+' => '_plu', '=' => '_equ',
'{' => '_lbc', '}' => '_rbc', '[' => '_lbk', ']' => '_rbk', ':' => '_col', ';' => '_sco', '"' => '_quo',
'\'' => '_apo', '<' => '_lan', '>' => '_ran', ',' => '_com', '.' => '_per', '?' => '_que', '/' => '_sla' );
$string =~ s/([\~\!\@\#\$\%\^\&\*\(\)\-\+\=\{\}\[\]\:\;\"\'\<\>\,\.\?\/])/$translation{$1}/ge;
$string =~ s/[^a-z0-9_]/_zzz/gi;
my $number = $searchResultIDs{lc($string)};
if (!$number)
{ $number = 1; }
elsif (!$dontIncrement)
{ $number++; };
$searchResultIDs{lc($string)} = $number;
return 'SR' . ($number == 1 ? '' : $number) . '_' . $string;
};
#
# Function: NDMarkupToHTML
#
# Converts a block of <NDMarkup> to HTML.
#
# Parameters:
#
# sourceFile - The source <FileName> the <NDMarkup> appears in.
# text - The <NDMarkup> text to convert.
# symbol - The topic <SymbolString> the <NDMarkup> appears in.
# package - The package <SymbolString> the <NDMarkup> appears in.
# type - The <TopicType> the <NDMarkup> appears in.
# using - An arrayref of scope <SymbolStrings> the <NDMarkup> also has access to, or undef if none.
# style - Set to one of the <NDMarkupToHTML Styles> or leave undef for general.
#
# Returns:
#
# The text in HTML.
#
sub NDMarkupToHTML #(sourceFile, text, symbol, package, type, using, style)
{
my ($self, $sourceFile, $text, $symbol, $package, $type, $using, $style) = @_;
my $dlSymbolBehavior;
if ($type eq ::TOPIC_ENUMERATION())
{ $dlSymbolBehavior = NaturalDocs::Languages->LanguageOf($sourceFile)->EnumValues(); }
elsif (NaturalDocs::Topics->TypeInfo($type)->Scope() == ::SCOPE_ALWAYS_GLOBAL())
{ $dlSymbolBehavior = ::ENUM_GLOBAL(); }
else
{ $dlSymbolBehavior = ::ENUM_UNDER_PARENT(); };
my $output;
my $inCode;
my @splitText = split(/(<\/?code(?: type="[^"]+")?>)/, $text);
while (scalar @splitText)
{
$text = shift @splitText;
if ($text =~ /<code type="([^"]+)">/)
{
my $codeType = $1;
my $highlight = ( ($codeType eq "code" && NaturalDocs::Settings->HighlightCode()) ||
($codeType eq "anonymous" && NaturalDocs::Settings->HighlightAnonymous()) );
$output .= '<blockquote><pre' . ($highlight ? ' class="prettyprint"' : '') . '>';
$inCode = 1;
}
elsif ($text eq '</code>')
{
$output .= '</pre></blockquote>';
$inCode = undef;
}
elsif ($inCode)
{
# Leave line breaks in.
$output .= $text;
}
else
{
# Format non-code text.
# Convert linked images.
if ($text =~ /<img mode=\"link\"/)
{
if ($style == NDMARKUPTOHTML_GENERAL)
{
# Split by tags we would want to see the linked images appear after. For example, an image link appearing in
# the middle of a paragraph would appear after the end of that paragraph.
my @imageBlocks = split(/(<p>.*?<\/p>|<dl>.*?<\/dl>|<ul>.*?<\/ul>)/, $text);
$text = undef;
foreach my $imageBlock (@imageBlocks)
{
$imageBlock =~ s{<img mode=\"link\" target=\"([^\"]*)\" original=\"([^\"]*)\">}
{$self->BuildImage($sourceFile, 'link', $1, $2)}ge;
$text .= $imageBlock . $imageContent;
$imageContent = undef;
};
}
# Use only the text for tooltips and summaries.
else
{
$text =~ s{<img mode=\"link\" target=\"[^\"]*\" original=\"([^\"]*)\">}{$1}g;
};
};
# Convert quotes to fancy quotes. This has to be done before links because some of them may have JavaScript
# attributes that use the apostrophe character.
$text =~ s/^\'/‘/gm;
$text =~ s/([\ \(\[\{])\'/$1‘/g;
$text =~ s/\'/’/g;
$text =~ s/^"/“/gm;
$text =~ s/([\ \(\[\{])"/$1“/g;
$text =~ s/"/”/g;
# Resolve and convert links, except for tooltips.
if ($style != NDMARKUPTOHTML_TOOLTIP)
{
$text =~ s{<link target=\"([^\"]*)\" name=\"([^\"]*)\" original=\"([^\"]*)\">}
{$self->BuildTextLink($1, $2, $3, $package, $using, $sourceFile)}ge;
$text =~ s/<url target=\"([^\"]*)\" name=\"([^\"]*)\">/$self->BuildURLLink($1, $2)/ge;
}
else
{
$text =~ s{<link target=\"[^\"]*\" name=\"([^\"]*)\" original=\"[^\"]*\">}{$1}g;
$text =~ s{<url target=\"[^\"]*\" name=\"([^\"]*)\">}{$1}g;
};
# We do full e-mail links anyway just so the obfuscation remains.
$text =~ s/<email target=\"([^\"]*)\" name=\"([^\"]*)\">/$self->BuildEMailLink($1, $2)/ge;
# Convert inline images, but only for the general style.
if ($style == NDMARKUPTOHTML_GENERAL)
{
$text =~ s{<img mode=\"inline\" target=\"([^\"]*)\" original=\"([^\"]*)\">}
{$self->BuildImage($sourceFile, 'inline', $1, $2)}ge;
}
else
{
$text =~ s{<img mode=\"inline\" target=\"[^\"]*\" original=\"([^\"]*)\">}{$1}g;
};
# Copyright symbols. Prevent conversion when part of (a), (b), (c) lists.
if ($text !~ /\(a\)/i)
{ $text =~ s/\(c\)/©/gi; };
# Trademark symbols.
$text =~ s/\(tm\)/™/gi;
$text =~ s/\(r\)/®/gi;
# Add double spaces too.
$text = $self->AddDoubleSpaces($text);
# Headings
$text =~ s/<h>/<h4 class=CHeading>/g;
$text =~ s/<\/h>/<\/h4>/g;
# Description Lists
$text =~ s/<dl>/<table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList>/g;
$text =~ s/<\/dl>/<\/table>/g;
$text =~ s/<de>/<tr><td class=CDLEntry>/g;
$text =~ s/<\/de>/<\/td>/g;
if ($dlSymbolBehavior == ::ENUM_GLOBAL())
{ $text =~ s/<ds>([^<]+)<\/ds>/$self->MakeDescriptionListSymbol(undef, $1)/ge; }
elsif ($dlSymbolBehavior == ::ENUM_UNDER_PARENT())
{ $text =~ s/<ds>([^<]+)<\/ds>/$self->MakeDescriptionListSymbol($package, $1)/ge; }
else # ($dlSymbolBehavior == ::ENUM_UNDER_TYPE())
{ $text =~ s/<ds>([^<]+)<\/ds>/$self->MakeDescriptionListSymbol($symbol, $1)/ge; }
sub MakeDescriptionListSymbol #(package, text)
{
my ($self, $package, $text) = @_;
$text = NaturalDocs::NDMarkup->RestoreAmpChars($text);
my $symbol = NaturalDocs::SymbolString->FromText($text);
if (defined $package)
{ $symbol = NaturalDocs::SymbolString->Join($package, $symbol); };
return
'<tr>'
. '<td class=CDLEntry>'
# The anchors are closed, but not around the text, to prevent the :hover CSS style from kicking in.
. '<a name="' . $self->SymbolToHTMLSymbol($symbol) . '"></a>'
. $text
. '</td>';
};
$text =~ s/<dd>/<td class=CDLDescription>/g;
$text =~ s/<\/dd>/<\/td><\/tr>/g;
$output .= $text;
};
};
return $output;
};
#
# Function: BuildTextLink
#
# Creates a HTML link to a symbol, if it exists.
#
# Parameters:
#
# target - The link text.
# name - The link name.
# original - The original text as it appears in the source.
# package - The package <SymbolString> the link appears in, or undef if none.
# using - An arrayref of additional scope <SymbolStrings> the link has access to, or undef if none.
# sourceFile - The <FileName> the link appears in.
#
# Target, name, and original are assumed to still have <NDMarkup> amp chars.
#
# Returns:
#
# The link in HTML, including tags. If the link doesn't resolve to anything, returns the HTML that should be substituted for it.
#
sub BuildTextLink #(target, name, original, package, using, sourceFile)
{
my ($self, $target, $name, $original, $package, $using, $sourceFile) = @_;
my $plainTarget = $self->RestoreAmpChars($target);
my $symbol = NaturalDocs::SymbolString->FromText($plainTarget);
my $symbolTarget = NaturalDocs::SymbolTable->References(::REFERENCE_TEXT(), $symbol, $package, $using, $sourceFile);
if (defined $symbolTarget)
{
my $symbolTargetFile;
if ($symbolTarget->File() ne $sourceFile)
{
$symbolTargetFile = $self->MakeRelativeURL( $self->OutputFileOf($sourceFile),
$self->OutputFileOf($symbolTarget->File()), 1 );
};
# else leave it undef
my $symbolTargetTooltipID = $self->BuildToolTip($symbolTarget->Symbol(), $sourceFile, $symbolTarget->Type(),
$symbolTarget->Prototype(), $symbolTarget->Summary());
my $toolTipProperties = $self->BuildToolTipLinkProperties($symbolTargetTooltipID);
return '<a href="' . $symbolTargetFile . '#' . $self->SymbolToHTMLSymbol($symbolTarget->Symbol()) . '" '
. 'class=L' . NaturalDocs::Topics->NameOfType($symbolTarget->Type(), 0, 1) . ' ' . $toolTipProperties . '>'
. $name
. '</a>';
}
else
{
return $original;
};
};
#
# Function: BuildURLLink
#
# Creates a HTML link to an external URL. Long URLs will have hidden breaks to allow them to wrap.
#
# Parameters:
#
# target - The URL to link to.
# name - The label of the link.
#
# Both are assumed to still have <NDMarkup> amp chars.
#
# Returns:
#
# The HTML link, complete with tags.
#
sub BuildURLLink #(target, name)
{
my ($self, $target, $name) = @_;
# Don't restore amp chars on the target.
if (length $name < 50 || $name ne $target)
{ return '<a href="' . $target . '" class=LURL target=_top>' . $name . '</a>'; };
my @segments = split(/([\,\/]|&)/, $target);
my $output = '<a href="' . $target . '" class=LURL target=_top>';
# Get past the first batch of slashes, since we don't want to break on things like http://.
$output .= $segments[0];
my $i = 1;
while ($i < scalar @segments && ($segments[$i] eq '/' || !$segments[$i]))
{
$output .= $segments[$i];
$i++;
};
# Now break on each one of those symbols.
while ($i < scalar @segments)
{
if ($segments[$i] eq ',' || $segments[$i] eq '/' || $segments[$i] eq '&')
{ $output .= '<wbr>'; };
$output .= $segments[$i];
$i++;
};
$output .= '</a>';
return $output;
};
#
# Function: BuildEMailLink
#
# Creates a HTML link to an e-mail address. The address will be transparently munged to protect it (hopefully) from spambots.
#
# Parameters:
#
# target - The e-mail address.
# name - The label of the link.
#
# Both are assumed to still have <NDMarkup> amp chars.
#
# Returns:
#
# The HTML e-mail link, complete with tags.
#
sub BuildEMailLink #(target, name)
{
my ($self, $target, $name) = @_;
my @splitAddress;
# Hack the address up. We want two user pieces and two host pieces.
my ($user, $host) = split(/\@/, $self->RestoreAmpChars($target));
my $userSplit = length($user) / 2;
push @splitAddress, NaturalDocs::NDMarkup->ConvertAmpChars( substr($user, 0, $userSplit) );
push @splitAddress, NaturalDocs::NDMarkup->ConvertAmpChars( substr($user, $userSplit) );
push @splitAddress, '@';
my $hostSplit = length($host) / 2;
push @splitAddress, NaturalDocs::NDMarkup->ConvertAmpChars( substr($host, 0, $hostSplit) );
push @splitAddress, NaturalDocs::NDMarkup->ConvertAmpChars( substr($host, $hostSplit) );
# Now put it back together again. We'll use spans to split the text transparently and JavaScript to split and join the link.
my $output =
"<a href=\"#\" onClick=\"location.href='mai' + 'lto:' + '" . join("' + '", @splitAddress) . "'; return false;\" class=LEMail>";
if ($name eq $target)
{
$output .=
$splitAddress[0] . '<span style="display: none">.nosp@m.</span>' . $splitAddress[1]
. '<span>@</span>'
. $splitAddress[3] . '<span style="display: none">.nosp@m.</span>' . $splitAddress[4];
}
else
{ $output .= $name; };
$output .= '</a>';
return $output;
};
#
# Function: BuildImage
#
# Builds the HTML for an image.
#
# Parameters:
#
# sourceFile - The source <FileName> this image appears in.
# mode - Either "inline" or "link".
# target - The target.
# original - The original text.
#
# All are assumed to still have <NDMarkup> amp chars.
#
# Returns:
#
# The result in HTML. If the mode was "link", the target image's HTML is added to <imageContent>.
#
sub BuildImage #(sourceFile, mode, target, original)
{
my ($self, $sourceFile, $mode, $target, $original) = @_;
my $targetNoAmp = $self->RestoreAmpChars($target);
my $image = NaturalDocs::ImageReferenceTable->GetReferenceTarget($sourceFile, $targetNoAmp);
if ($image)
{
my ($width, $height) = NaturalDocs::Project->ImageFileDimensions($image);
if ($mode eq 'inline')
{
return
'<img src="' . $self->MakeRelativeURL($self->OutputFileOf($sourceFile),
$self->OutputImageOf($image), 1) . '"'
. ($width && $height ? ' width="' . $width . '" height="' . $height . '"' : '')
. '>';
}
else # link
{
# Make the text a little more friendly in the output by removing any folders and file extensions.
# (see images/Table1.gif) will be turned into (see Table1).
my $originalNoAmp = $self->RestoreAmpChars($original);
my $targetIndex = index($originalNoAmp, $targetNoAmp);
my ($shortTarget, $shortTargetNoAmp, $shortOriginal);
if ($targetIndex != -1)
{
$shortTargetNoAmp = (NaturalDocs::File->SplitPath($targetNoAmp))[2];
$shortTargetNoAmp = NaturalDocs::File->NoExtension($shortTargetNoAmp);
substr($originalNoAmp, $targetIndex, length($targetNoAmp), $shortTargetNoAmp);
$shortOriginal = NaturalDocs::NDMarkup->ConvertAmpChars($originalNoAmp);
$shortTarget = NaturalDocs::NDMarkup->ConvertAmpChars($shortTargetNoAmp);
};
my $output =
'<a href="#Image' . $imageAnchorNumber . '" class=CImageLink>'
. ($shortOriginal || $original)
. '</a>';
$imageContent .=
'<blockquote>'
. '<div class=CImage>'
. '<a name="Image' . $imageAnchorNumber . '"></a>'
. '<div class=CImageCaption>' . ($shortTarget || $target) . '</div>'
. '<img src="' . $self->MakeRelativeURL($self->OutputFileOf($sourceFile),
$self->OutputImageOf($image), 1) . '"'
. ($width && $height ? ' width="' . $width . '" height="' . $height . '"' : '')
. '>'
. '</div></blockquote>';
$imageAnchorNumber++;
return $output;
};
}
else # !$image
{
if ($mode eq 'inline')
{ return '<p>' . $original . '</p>'; }
else #($mode eq 'link')
{ return $original; };
};
};
#
# Function: BuildToolTipLinkProperties
#
# Returns the properties that should go in the link tag to add a tooltip to it. Because the function accepts undef, you can
# call it without checking if <BuildToolTip()> returned undef or not.
#
# Parameters:
#
# toolTipID - The ID of the tooltip. If undef, the function will return undef.
#
# Returns:
#
# The properties that should be put in the link tag, or undef if toolTipID wasn't specified.
#
sub BuildToolTipLinkProperties #(toolTipID)
{
my ($self, $toolTipID) = @_;
if (defined $toolTipID)
{
my $currentNumber = $tooltipLinkNumber;
$tooltipLinkNumber++;
return 'id=link' . $currentNumber . ' '
. 'onMouseOver="ShowTip(event, \'' . $toolTipID . '\', \'link' . $currentNumber . '\')" '
. 'onMouseOut="HideTip(\'' . $toolTipID . '\')"';
}
else
{ return undef; };
};
#
# Function: AddDoubleSpaces
#
# Adds second spaces after the appropriate punctuation with so they show up in HTML. They don't occur if there isn't at
# least one space after the punctuation, so things like class.member notation won't be affected.
#
# Parameters:
#
# text - The text to convert.
#
# Returns:
#
# The text with double spaces as necessary.
#
sub AddDoubleSpaces #(text)
{
my ($self, $text) = @_;
# Question marks and exclamation points get double spaces unless followed by a lowercase letter.
$text =~ s/ ([^\ \t\r\n] [\!\?]) # Must appear after a non-whitespace character to apply.
("|&[lr][sd]quo;|[\'\"\]\}\)]?) # Tolerate closing quotes, parenthesis, etc.
((?:<[^>]+>)*) # Tolerate tags
\ # The space
(?![a-z]) # Not followed by a lowercase character.
/$1$2$3 \ /gx;
# Periods get double spaces if it's not followed by a lowercase letter. However, if it's followed by a capital letter and the
# preceding word is in the list of acceptable abbreviations, it won't get the double space. Yes, I do realize I am seriously
# over-engineering this.
$text =~ s/ ([^\ \t\r\n]+) # The word prior to the period.
\.
("|&[lr][sd]quo;|[\'\"\]\}\)]?) # Tolerate closing quotes, parenthesis, etc.
((?:<[^>]+>)*) # Tolerate tags
\ # The space
([^a-z]) # The next character, if it's not a lowercase letter.
/$1 . '.' . $2 . $3 . MaybeExpand($1, $4) . $4/gex;
sub MaybeExpand #(leadWord, nextLetter)
{
my ($leadWord, $nextLetter) = @_;
if ($nextLetter =~ /^[A-Z]$/ && exists $abbreviations{ lc($leadWord) } )
{ return ' '; }
else
{ return ' '; };
};
return $text;
};
#
# Function: ConvertAmpChars
#
# Converts certain characters to their HTML amp char equivalents.
#
# Parameters:
#
# text - The text to convert.
#
# Returns:
#
# The converted text.
#
sub ConvertAmpChars #(text)
{
my ($self, $text) = @_;
$text =~ s/&/&/g;
$text =~ s/\"/"/g;
$text =~ s/</</g;
$text =~ s/>/>/g;
return $text;
};
#
# Function: RestoreAmpChars
#
# Restores all amp characters to their original state. This works with both <NDMarkup> amp chars and fancy quotes.
#
# Parameters:
#
# text - The text to convert.
#
# Returns:
#
# The converted text.
#
sub RestoreAmpChars #(text)
{
my ($self, $text) = @_;
$text = NaturalDocs::NDMarkup->RestoreAmpChars($text);
$text =~ s/&[lr]squo;/\'/g;
$text =~ s/&[lr]dquo;/\"/g;
return $text;
};
#
# Function: AddHiddenBreaks
#
# Adds hidden breaks to symbols. Puts them after symbol and directory separators so long names won't screw up the layout.
#
# Parameters:
#
# string - The string to break.
#
# Returns:
#
# The string with hidden breaks.
#
sub AddHiddenBreaks #(string)
{
my ($self, $string) = @_;
# \.(?=.{5,}) instead of \. so file extensions don't get breaks.
# :+ instead of :: because Mac paths are separated by a : and we want to get those too.
$string =~ s/(\w(?:\.(?=.{5,})|:+|->|\\|\/))(\w)/$1 . '<wbr>' . $2/ge;
return $string;
};
#
# Function: FindFirstFile
#
# A function that finds and returns the first file entry in the menu, or undef if none.
#
sub FindFirstFile
{
# Hidden parameter: arrayref
# Used for recursion only.
my ($self, $arrayref) = @_;
if (!defined $arrayref)
{ $arrayref = NaturalDocs::Menu->Content(); };
foreach my $entry (@$arrayref)
{
if ($entry->Type() == ::MENU_FILE())
{
return $entry;
}
elsif ($entry->Type() == ::MENU_GROUP())
{
my $result = $self->FindFirstFile($entry->GroupContent());
if (defined $result)
{ return $result; };
};
};
return undef;
};
#
# Function: ExpandMenu
#
# Determines which groups should be expanded.
#
# Parameters:
#
# sourceFile - The source <FileName> to use if you're looking for a source file.
# indexType - The index <TopicType> to use if you're looking for an index.
# selectionHierarchy - The <FileName> the menu is being built for. Does not have to be on the menu itself.
# rootLength - The length of the menu's root group, *not* including the contents of subgroups.
#
# Returns:
#
# An arrayref of all the group numbers that should be expanded. At minimum, it will contain the numbers of the groups
# present in <menuSelectionHierarchy>, though it may contain more.
#
sub ExpandMenu #(FileName sourceFile, TopicType indexType, NaturalDocs::Menu::Entry[] selectionHierarchy, int rootLength) -> int[] groupsToExpand
{
my ($self, $sourceFile, $indexType, $menuSelectionHierarchy, $rootLength) = @_;
my $toExpand = [ ];
# First expand everything in the selection hierarchy.
my $length = $rootLength;
foreach my $entry (@$menuSelectionHierarchy)
{
$length += $menuGroupLengths{$entry};
push @$toExpand, $menuGroupNumbers{$entry};
};
# Now do multiple passes of group expansion as necessary. We start from bottomIndex and expand outwards. We stop going
# in a direction if a group there is too long -- we do not skip over it and check later groups as well. However, if one direction
# stops, the other can keep going.
my $pass = 1;
my $hasSubGroups;
while ($length < MENU_LENGTH_LIMIT)
{
my $content;
my $topIndex;
my $bottomIndex;
if ($pass == 1)
{
# First pass, we expand the selection's siblings.
if (scalar @$menuSelectionHierarchy)
{ $content = $menuSelectionHierarchy->[0]->GroupContent(); }
else
{ $content = NaturalDocs::Menu->Content(); };
$bottomIndex = 0;
while ($bottomIndex < scalar @$content &&
!($content->[$bottomIndex]->Type() == ::MENU_FILE() &&
$content->[$bottomIndex]->Target() eq $sourceFile) &&
!($content->[$bottomIndex]->Type() != ::MENU_INDEX() &&
$content->[$bottomIndex]->Target() eq $indexType) )
{ $bottomIndex++; };
if ($bottomIndex == scalar @$content)
{ $bottomIndex = 0; };
$topIndex = $bottomIndex - 1;
}
elsif ($pass == 2)
{
# If the section we just expanded had no sub-groups, do another pass trying to expand the parent's sub-groups. The
# net effect is that groups won't collapse as much unnecessarily. Someone can click on a file in a sub-group and the
# groups in the parent will stay open.
if (!$hasSubGroups && scalar @$menuSelectionHierarchy)
{
if (scalar @$menuSelectionHierarchy > 1)
{ $content = $menuSelectionHierarchy->[1]->GroupContent(); }
else
{ $content = NaturalDocs::Menu->Content(); };
$bottomIndex = 0;
while ($bottomIndex < scalar @$content &&
$content->[$bottomIndex] != $menuSelectionHierarchy->[0])
{ $bottomIndex++; };
$topIndex = $bottomIndex - 1;
$bottomIndex++; # Increment past our own group.
$hasSubGroups = undef;
}
else
{ last; };
}
# No more passes.
else
{ last; };
while ( ($topIndex >= 0 || $bottomIndex < scalar @$content) && $length < MENU_LENGTH_LIMIT)
{
# We do the bottom first.
while ($bottomIndex < scalar @$content && $content->[$bottomIndex]->Type() != ::MENU_GROUP())
{ $bottomIndex++; };
if ($bottomIndex < scalar @$content)
{
my $bottomEntry = $content->[$bottomIndex];
$hasSubGroups = 1;
if ($length + $menuGroupLengths{$bottomEntry} <= MENU_LENGTH_LIMIT)
{
$length += $menuGroupLengths{$bottomEntry};
push @$toExpand, $menuGroupNumbers{$bottomEntry};
$bottomIndex++;
}
else
{ $bottomIndex = scalar @$content; };
};
# Top next.
while ($topIndex >= 0 && $content->[$topIndex]->Type() != ::MENU_GROUP())
{ $topIndex--; };
if ($topIndex >= 0)
{
my $topEntry = $content->[$topIndex];
$hasSubGroups = 1;
if ($length + $menuGroupLengths{$topEntry} <= MENU_LENGTH_LIMIT)
{
$length += $menuGroupLengths{$topEntry};
push @$toExpand, $menuGroupNumbers{$topEntry};
$topIndex--;
}
else
{ $topIndex = -1; };
};
};
$pass++;
};
return $toExpand;
};
#
# Function: GetMenuSelectionHierarchy
#
# Finds the sequence of menu groups that contain the current selection.
#
# Parameters:
#
# sourceFile - The source <FileName> to use if you're looking for a source file.
# indexType - The index <TopicType> to use if you're looking for an index.
#
# Returns:
#
# An arrayref of the <NaturalDocs::Menu::Entry> objects of each group surrounding the selected menu item. First entry is the
# group immediately encompassing it, and each subsequent entry works its way towards the outermost group.
#
sub GetMenuSelectionHierarchy #(FileName sourceFile, TopicType indexType) -> NaturalDocs::Menu::Entry[] selectionHierarchy
{
my ($self, $sourceFile, $indexType) = @_;
my $hierarchy = [ ];
$self->FindMenuSelection($sourceFile, $indexType, $hierarchy, NaturalDocs::Menu->Content());
return $hierarchy;
};
#
# Function: FindMenuSelection
#
# A recursive function that deterimes if it or any of its sub-groups has the menu selection.
#
# Parameters:
#
# sourceFile - The source <FileName> to use if you're looking for a source file.
# indexType - The index <TopicType> to use if you're looking for an index.
# hierarchyRef - A reference to the menu selection hierarchy.
# entries - An arrayref of <NaturalDocs::Menu::Entries> to search.
#
# Returns:
#
# Whether this group or any of its subgroups had the selection. If true, it will add any subgroups to the menu selection
# hierarchy but not itself. This prevents the topmost entry from being added.
#
sub FindMenuSelection #(FileName sourceFile, TopicType indexType, NaturalDocs::Menu::Entry[] hierarchyRef, NaturalDocs::Menu::Entry[] entries) -> bool hasSelection
{
my ($self, $sourceFile, $indexType, $hierarchyRef, $entries) = @_;
foreach my $entry (@$entries)
{
if ($entry->Type() == ::MENU_GROUP())
{
# If the subgroup has the selection...
if ( $self->FindMenuSelection($sourceFile, $indexType, $hierarchyRef, $entry->GroupContent()) )
{
push @$hierarchyRef, $entry;
return 1;
};
}
elsif ($entry->Type() == ::MENU_FILE())
{
if ($sourceFile eq $entry->Target())
{ return 1; };
}
elsif ($entry->Type() == ::MENU_INDEX())
{
if ($indexType eq $entry->Target)
{ return 1; };
};
};
return 0;
};
#
# Function: ResetToolTips
#
# Resets the <ToolTip Package Variables> for a new page.
#
# Parameters:
#
# samePage - Set this flag if there's the possibility that the next batch of tooltips may be on the same page as the last.
#
sub ResetToolTips #(samePage)
{
my ($self, $samePage) = @_;
if (!$samePage)
{
$tooltipLinkNumber = 1;
$tooltipNumber = 1;
};
$tooltipHTML = undef;
%tooltipSymbolsToNumbers = ( );
};
1;
|