Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch creole Excluding Merge-Ins
This is equivalent to a diff from 63d5a4fe25 to df90572760
2010-02-26
| ||
13:09 | Update SQLite to pre-3.6.23. check-in: 1efd09ed4f user: drh tags: trunk | |
03:02 | Merge in latest changes from trunk. Leaf check-in: df90572760 user: linuxfood tags: creole | |
2010-02-25
| ||
14:06 | Pull over the latest clear-title changes from trunk. check-in: 16e703be11 user: drh tags: clear-title | |
12:58 | If a file has been deleted from the filesystem, but not deleted by fossil, then make the "update" command restore that file. Ticket [7c3ca0eae8287] check-in: 63d5a4fe25 user: drh tags: trunk | |
2010-02-24
| ||
22:39 | Back out the changes of [0e2281fc8a757] since they were causing a segfault while trying to enter a new ticket. The ticket [6b498a792c0] should still be fixed. check-in: 5a6634c453 user: drh tags: trunk | |
2009-10-05
| ||
20:05 | add wiki-contents macro to creole parser, plus minor bug fix check-in: b99aa66d1f user: robert tags: creole | |
Added src/creoleparser.c.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
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 |
/* ** Copyright (c) 2009 Robert Ledger ** ** {{{ License ** ** This program is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public ** License version 2 as published by the Free Software Foundation. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** General Public License for more details. ** ** You should have received a copy of the GNU General Public ** License along with this library; if not, write to the ** Free Software Foundation, Inc., 59 Temple Place - Suite 330, ** Boston, MA 02111-1307, USA. ** ** Author contact information: ** robert@pytrash.co.uk ** http://pytrash.co.uk **}}} ******************************************************************************* ** ** This file contains code to render creole 1.0 formated text as html. */ #include <assert.h> #include "config.h" #include "creoleparser.h" #if INTERFACE #define HAVE_CREOLE_MACRO 1 #endif //{{{ LOCAL INTERFACE #if LOCAL_INTERFACE #define POOL_CHUNK_SIZE 100 //{{{ KIND #define KIND_ROOT 0x0000001 #define KIND_HORIZONTAL_RULE 0x0000002 #define KIND_HEADING 0x0000004 #define KIND_ORDERED_LIST 0x0000008 #define KIND_UNORDERED_LIST 0x0000010 #define KIND_PARAGRAPH 0x0000020 #define KIND_TABLE 0x0000040 #define KIND_NO_WIKI_BLOCK 0x0000080 #define KIND_PARA_BREAK 0x0000100 #define KIND_END_WIKI_MARKER 0x0000200 #define KIND_BOLD 0x0000400 #define KIND_ITALIC 0x0000800 #define KIND_SUPERSCRIPT 0x0001000 #define KIND_SUBSCRIPT 0x0002000 #define KIND_MONOSPACED 0x0004000 #define KIND_BREAK 0x0008000 #define KIND_TABLE_ROW 0x0010000 #define KIND_MACRO 0X0020000 //}}} //{{{ MACRO #define MACRO_NONE 0X0000000 #define MACRO_FOSSIL 0x0000001 #define MACRO_WIKI_CONTENTS 0X0000002 //}}} //{{{ FLAG // keep first four bits free (why?:) #define FLAG_CENTER 0x0000100 #define FLAG_MACRO_BLOCK 0X0000200 //}}} struct Node {//{{{ char *start; char *end; int kind; int level; int flags; Node *parent; Node *next; Node *children; }; //}}} struct NodePool {//{{{ NodePool *next; Node a[POOL_CHUNK_SIZE]; } //}}} struct Parser {//{{{ Blob *pOut; /* Output appended to this blob */ Renderer *r; NodePool *pool; int nFree; Node *this; Node *previous; Node *list; char *cursor; int lineWasBlank; int charCount; Node *item; Node *istack; char *icursor; char *iend; int inLink; int inTable; int iesc; Blob *iblob; }; //}}} #endif const int KIND_LIST = (KIND_UNORDERED_LIST | KIND_ORDERED_LIST); const int KIND_LIST_OR_PARAGRAPH = (KIND_PARAGRAPH | KIND_UNORDERED_LIST | KIND_ORDERED_LIST); //}}} //{{{ POOL MANAGEMENT static Node *pool_new(Parser *p){ if ( p->pool == NULL || p->nFree == 0){ NodePool *temp = p->pool; p->pool = malloc(sizeof(NodePool)); if( p->pool == NULL ) fossil_panic("out of memory"); p->pool->next = temp; p->nFree = POOL_CHUNK_SIZE; } p->nFree -= 1; Node *node = &(p->pool->a[p->nFree]); memset(node, 0, sizeof(*node)); return node; } static void pool_free(Parser *p){ NodePool *temp; while (p->pool != NULL){ temp = p->pool; p->pool = temp->next; free(temp); } } //}}} //{{{ Utility Methods static char *cr_skipBlanks(Parser *p, char* z){//{{{ char *s = z; while (z[0] == ' ' || z[0] == '\t') z++; p->charCount = z - s; return z; } //}}} static int cr_countBlanks(Parser *p, char* z){//{{{ cr_skipBlanks(p, z); return p->charCount; } //}}} static char *cr_skipChars(Parser *p, char *z, char c){//{{{ char *s = z; while (z[0] == c) z++; p->charCount = z - s; return z; } //}}} static int cr_countChars(Parser *p, char *z, char c){//{{{ cr_skipChars(p, z, c); return p->charCount; } //}}} static char *cr_nextLine(Parser *p, char *z){//{{{ p->lineWasBlank = 1; while (1){ switch (z[0]){ case '\r': if (z[1] == '\n') { z[0] = ' '; return z + 2; } z[0] = '\n'; return z + 1; case '\n': return z + 1; case '\t': z[0] = ' '; z++; break; case ' ': z++; break; case '\0': return z; default: p->lineWasBlank = 0; z++; } } } //}}} //}}} //{{{ INLINE PARSER static int cr_isEsc(Parser *p){//{{{ if (p->iesc){ blob_append(p->iblob, p->icursor, 1); p->iesc = 0; p->icursor += 1; return 1; } return 0; } //}}} static int cr_iOpen(Parser *p, int kind){//{{{ switch (kind){ case KIND_BOLD: blob_append(p->iblob, "<strong>", 8); return 1; case KIND_ITALIC: blob_append(p->iblob, "<em>", 4); return 1; case KIND_SUPERSCRIPT: blob_append(p->iblob, "<sup>", 5); return 1; case KIND_SUBSCRIPT: blob_append(p->iblob, "<sub>", 5); return 1; case KIND_MONOSPACED: blob_append(p->iblob, "<tt>", 4); return 1; } return 0; } //}}} static int cr_iClose(Parser *p, int kind){//{{{ switch (kind){ case KIND_BOLD: blob_append(p->iblob, "</strong>", 9); return 1; case KIND_ITALIC: blob_append(p->iblob, "</em>", 5); return 1; case KIND_SUPERSCRIPT: blob_append(p->iblob, "</sup>", 6); return 1; case KIND_SUBSCRIPT: blob_append(p->iblob, "</sub>", 6); return 1; case KIND_MONOSPACED: blob_append(p->iblob, "</tt>", 5); return 1; } return 0; } //}}} static void cr_iMarkup(Parser *p, int kind){//{{{ if (p->iesc) { blob_append(p->iblob, p->icursor, 1); p->icursor +=1; p->iesc =0; return; } if (p->icursor[1] != p->icursor[0]) { blob_append(p->iblob, p->icursor, 1); p->icursor +=1; return; } p->icursor += 2; if (kind & KIND_BREAK) { blob_append(p->iblob, "<br />", 6); return; } if (kind & KIND_ITALIC && p->icursor[-3] == ':'){ blob_append(p->iblob, "//", 2); return; } Node *n = p->istack; int found = 0; while (n) { if (n->kind & kind) { found = 1; break; } n = n->next; } if (!found) { n = pool_new(p); n->kind = kind; n->next = p->istack; p->istack = n; assert(cr_iOpen(p, kind)); return; }; n= p->istack; while (n){ p->istack = n->next; assert(cr_iClose(p, n->kind)); if (kind == n->kind) return; n = p->istack; } } //}}} static int cr_iNoWiki(Parser *p){//{{{ if ((p->iend - p->icursor)<6) return 0; if (p->icursor[1]!='{' || p->icursor[2]!='{') return 0; char *s = p->icursor + 3; int count = p->iend - p->icursor - 3; while (count--){ if (s[0]=='}' && s[1]=='}' && s[2]=='}' && s[3]!='}'){ blob_appendf(p->iblob, "<tt class='creole-inline-nowiki'>%s</tt>", htmlize(p->icursor + 3, s - p->icursor-3)); p->icursor = s + 3; return 1; } s++; } return 0; } //}}} static int cr_iImage(Parser *p){//{{{ if (p->inLink) return 0; if ((p->iend - p->icursor)<3) return 0; if (p->icursor[1]!='{') return 0; char *s = p->icursor + 2; char *bar = NULL; int count = p->iend - p->icursor - 4; while (count--){ if (s[0]=='}' && s[1]=='}'){ if (!bar) bar = p->icursor + 2; blob_appendf(p->iblob, "<span class='creole-noimage'>%s</span>", htmlize(bar, s - bar )); p->icursor = s + 2; return 1; } if (!bar && s[0]=='|') bar=s+1; s++; } return 0; } //}}} static int cr_iMacro(Parser *p){//{{{ if (p->inLink) return 0; if ((p->iend - p->icursor)<3) return 0; if (p->icursor[1]!='<') return 0; char *s = p->icursor + 2; int count = p->iend - p->icursor - 3; while (count--){ if (s[0]=='>' && s[1]=='>'){ blob_appendf(p->iblob, "<span class='creole-nomacro'>%s</span>", htmlize(p->icursor, s - p->icursor + 2)); p->icursor = s + 2; return 1; } s++; } return 0; } //}}} static void cr_renderLink(Parser *p, char *s, char *bar, char *e){//{{{ int tsize = bar-s; int dsize = e - bar-1; if (tsize < 1) return; if (dsize < 1) dsize = 0; char zTarget[tsize + 1]; memcpy(zTarget, s, tsize); zTarget[tsize] = '\0'; char zClose[20]; Blob *pOut = p->r->pOut; p->r->pOut = p->iblob; wf_openHyperlink(p->r, zTarget, zClose, sizeof(zClose)); p->r->pOut = pOut; if (dsize) cr_parseInline(p, bar+1, e) ; else blob_append(p->iblob, htmlize(s, tsize), -1); blob_append(p->iblob, zClose, -1); } //}}} static int cr_iLink(Parser *p){//{{{ if (p->inLink) return 0; if ((p->iend - p->icursor)<3) return 0; if (p->icursor[1]!='[') return 0; char *s = p->icursor + 2; char *bar = NULL; int count = p->iend - p->icursor -3; while (count--){ if (s[0]==']' && s[1]==']'){ if (!bar) bar = s; p->inLink = 1; cr_renderLink(p, p->icursor+2, bar, s); p->inLink = 0; p->icursor = s + 2; return 1; } if (!bar && s[0]=='|') bar=s; s++; } return 0; } //}}} LOCAL char *cr_parseInline(Parser *p, char *s, char *e){//{{{ int save_iesc = p->iesc; char *save_iend = p->iend; Node *save_istack = p->istack; p->iesc = 0; p->iend = e; p->istack = NULL; p->icursor = s; char *eof = NULL; while (!eof && p->icursor < p->iend ){ switch (*p->icursor) {//{{{ case '~': if (p->iesc) { blob_append(p->iblob, "~", 1); p->iesc = 0; } p->iesc = !p->iesc; p->icursor+=1; break; case '*': cr_iMarkup(p, KIND_BOLD); break; case '/': cr_iMarkup(p, KIND_ITALIC); break; case '^': cr_iMarkup(p, KIND_SUPERSCRIPT); break; case ',': cr_iMarkup(p, KIND_SUBSCRIPT); break; case '#': cr_iMarkup(p, KIND_MONOSPACED); break; case '\\': cr_iMarkup(p, KIND_BREAK); break; case '{': if (cr_isEsc(p)) break; if (cr_iNoWiki(p)) break; if (cr_iImage(p)) break; blob_append(p->iblob, p->icursor, 1); p->icursor += 1; break; case '[': if (cr_isEsc(p)) break; if (cr_iLink(p)) break; blob_append(p->iblob, p->icursor, 1); p->icursor += 1; break; case '<': if (cr_isEsc(p)) break; if (cr_iMacro(p)) break; blob_append(p->iblob, "<", 4); p->icursor += 1; break; case '>': if (p->iesc) { blob_append(p->iblob, "~", 1); p->iesc = 0; } blob_append(p->iblob, ">", 4); p->icursor += 1; break; case '&': if (p->iesc) { blob_append(p->iblob, "~", 1); p->iesc = 0; } blob_append(p->iblob, "&", 5); p->icursor += 1; break; case '|': if (p->inTable){ if (p->iesc) { blob_append(p->iblob, p->icursor, 1); p->iesc = 0; p->icursor += 1; break; } eof = p->icursor + 1; break; } // fall through to default default: if (p->iesc) { blob_append(p->iblob, "~", 1); p->iesc = 0; } blob_append(p->iblob, p->icursor, 1); p->icursor +=1; }//}}} } while (p->istack){ cr_iClose(p, p->istack->kind); p->istack = p->istack->next; } p->iesc = save_iesc; p->iend = save_iend; p->istack = save_istack; return eof; } //}}} //}}} //{{{ BLOCK PARSER static void cr_renderListItem(Parser *p, Node *n){//{{{ blob_append(p->iblob, "<li>", 4); cr_parseInline(p, n->start, n->end); if (n->children){ int ord = (n->children->kind & KIND_ORDERED_LIST); if (ord) blob_append(p->iblob, "<ol>", 4); else blob_append(p->iblob, "<ul>", 4); n = n->children; while (n){ cr_renderListItem(p, n); n = n->next; } if (ord) blob_append(p->iblob, "</ol>", 5); else blob_append(p->iblob, "</ul>", 5); } blob_append(p->iblob, "</li>", 5); } //}}} static void cr_renderList(Parser *p){//{{{ Node *n = p->list; while (n->parent !=n) n = n->parent; int ord = (n->kind & KIND_ORDERED_LIST); if (ord) blob_append(p->iblob, "\n\n<ol>", -1); else blob_append(p->iblob, "\n\n<ul>", -1); while (n) { cr_renderListItem(p, n); n = n->next; } if (ord) blob_append(p->iblob, "</ol>", 5); else blob_append(p->iblob, "</ul>", 5); } //}}} static void cr_renderTableRow(Parser *p, Node *row){//{{{ char *s = row->start; int th; blob_append(p->iblob, "\n<tr>", -1); while (s && s < row->end){ if ((th = *s == '=')) { s++; blob_append(p->iblob, "<th>", -1); } else { blob_append(p->iblob, "<td>", -1); } s = cr_parseInline(p, s, row->end); if (th) blob_append(p->iblob, "</th>\n", -1); else blob_append(p->iblob, "</td>\n", -1); if (!s) break; } blob_append(p->iblob, "</tr>", 5); } //}}} static void cr_renderTable(Parser *p, Node *n){//{{{ Node *row = n->children; blob_append(p->iblob, "<table class='creoletable'>", -1); p->inTable = 1; while (row){ cr_renderTableRow(p, row); row = row->next; } blob_append(p->iblob, "</table>", -1); p->inTable = 0; } //}}} static void cr_renderMacro(Parser *p, Node *n){//{{{ switch (n->level){ case MACRO_WIKI_CONTENTS: do_macro_wiki_contents(p, n); break; } } //}}} static void cr_render(Parser *p, Node *node){//{{{ if (node->kind & KIND_PARAGRAPH){ blob_append(p->iblob, "\n<p>", -1); cr_parseInline(p, node->start, node->end ); blob_append(p->iblob, "</p>\n", -1 ); } if (node->kind & KIND_HEADING){ blob_appendf(p->iblob, "\n<h%d %s>", node->level, (node->flags & FLAG_CENTER) ? " style='text-align:center;'" : "" ); cr_parseInline(p, node->start, node->end); blob_appendf(p->iblob, "</h%d>\n", node->level ); return; } if (node->kind & KIND_MACRO){ cr_renderMacro(p, node); return; } if (node->kind & KIND_HORIZONTAL_RULE){ blob_append(p->iblob, "<hr />", -1); return; } if (node->kind & KIND_LIST){ cr_renderList(p); p->list = NULL; return; } if (node->kind & KIND_TABLE){ cr_renderTable(p, node); return; } if (node->kind & KIND_NO_WIKI_BLOCK){ blob_appendf(p->iblob, "\n<pre class='creole-block-nowiki'>%s</pre>\n", htmlize( node->start, node->end - node->start) ); } } //}}} static char *cr_findEndOfBlock(Parser *p, char *s, char c){//{{{ char *end; while (s[0]){ end = s; if (s[0] == c && s[0] == c && s[0] == c) { s = cr_nextLine(p, s + 3); if (p->lineWasBlank) { p->cursor = s; return end; } } else { s = cr_nextLine(p, s); } } return 0; } //}}} static int cr_addListItem(Parser *p, Node *n){//{{{ n->parent = n; n->next = n->children = NULL; if (!p->list) { if (n->level != 1) return 0; p->list = n; return 1; } Node *list = p->list; while (n->level < list->level){ list = list->parent; } if (n->level == list->level){ if (n->kind != list->kind){ if (n->level>1) return 0; cr_renderList(p); p->list = n; return 1; } n->parent = list->parent; p->list = list->next = n; return 1; } if ( (n->level - list->level) > 1 ) return 0; n->parent = p->list; p->list->children = n; p->list = n; return 1; } //}}} static int isEndWikiMarker(Parser *p){//{{{ char *s = p->cursor; if (memcmp(s, "<<fossil>>", 10)) return 0; p->this->start = s; p->this->kind = KIND_END_WIKI_MARKER; p->cursor += 10; return 1; } //}}} static int isNoWikiBlock(Parser *p){//{{{ char *s = p->cursor; if (s[0] != '{') return 0; s++; if (s[0] != '{') return 0; s++; if (s[0] != '{') return 0; s++; s = cr_nextLine(p, s); if (!p->lineWasBlank) return 0; p->this->start = s; s = cr_findEndOfBlock(p, s, '}'); if (!s) return 0; // p->cursor was set by findEndOfBlock p->this->kind = KIND_NO_WIKI_BLOCK; p->this->end = s; return 1; } //}}} static int isParaBreak(Parser *p){//{{{ char *s = cr_nextLine(p, p->cursor); if (!p->lineWasBlank) return 0; p->cursor = s; p->this->kind = KIND_PARA_BREAK; return 1; } //}}} static int isMacro(Parser *p){//{{{ char *s = p->cursor; int macroId; int matchLength; /* This is succinct but somewhat hard to follow. Read as: If not '<' then return, otherwise increment s; Repeat above; If '<' then return; */ if (s[0]!='<') return 0; s++; if (s[0]!='<') return 0; s++; if (s[0]=='<') return 0; matchLength = cr_has_macro(s, ¯oId); if (!matchLength) return 0; s += matchLength; p->this->start = s; if (s[-1]!='>'){ while (s[0] && s[1] && s[0]!='\n' && !(s[0]=='>' && s[1]=='>')) s++; if (!(s[0] == '>' && s[1] == '>')) return 0; s +=2; } p->cursor = s; p->this->kind = KIND_MACRO; p->this->level = macroId; p->this->flags &= FLAG_MACRO_BLOCK; p->this->end = s-2; return 1; } //}}} static int isHeading(Parser *p){//{{{ char *s = cr_skipBlanks(p, p->cursor); int flags = 0; int level = cr_countChars(p, s, '='); if (!level) return 0; s += level; if (s[0] == '<' && s[1] == '>') { flags |= FLAG_CENTER; s += 2; } s = cr_skipBlanks(p, s); p->this->start = s; s = cr_nextLine(p, s); char *z = s; if (s[-1] == '\n') s--; while(s[-1] == ' ' || s[-1]=='\t') s--; while(s[-1] == '=' ) s--; if (p->this->start < s){ p->cursor = z; p->this->kind = KIND_HEADING; p->this->end = s; p->this->level = level; p->this->flags |= flags; return 1; } return 0; } //}}} static int isHorizontalRule(Parser *p){//{{{ char *s = cr_skipBlanks(p, p->cursor); int level = cr_countChars(p, s, '-'); if (level < 4) return 0; s = cr_nextLine(p, s + level); if (!p->lineWasBlank) return 0; p->cursor = s; p->this->kind = KIND_HORIZONTAL_RULE; return 1; } //}}} static int isListItem(Parser *p){//{{{ char *s = cr_skipBlanks(p, p->cursor); int level = cr_countChars(p, s, '#'); if (!level) level = cr_countChars(p, s, '*'); if ( !level) return 0; p->this->kind = (s[0] == '#') ? KIND_ORDERED_LIST : KIND_UNORDERED_LIST; p->this->level = level; s = cr_skipBlanks(p, s + level); p->this->start = s; s = cr_nextLine(p, s); if (p->lineWasBlank) return 0; if (cr_addListItem(p, p->this)){ p->cursor = p->this->end = s; return 1; } p->this->kind = 0; return 0; } //}}} static int isTable(Parser *p){//{{{ p->this->start = p->cursor; char *s = cr_skipBlanks(p, p->cursor); if (s[0] != '|') return 0; s +=1; p->this->kind = KIND_TABLE; //p->cursor = p->this->end = cr_nextLine(p, s); Node *row; Node *tail = NULL; while (1) { row = pool_new(p); row->kind = KIND_TABLE_ROW; if (tail) tail = tail->next = row; else p->this->children = tail = row; row->start = s; p->cursor = s = row->end = p->this->end = cr_nextLine(p, s); if (row->end[-1] == '\n') row->end -= 1; while(row->end[-1] == ' ' ) row->end -= 1; if (row->end[-1] == '|') row->end -= 1; if (!*s) break; // blanks *not* normalized s = cr_skipBlanks(p, p->cursor); if (s[0] != '|') break; s++; } return 1; }; //}}} static int isParagraph(Parser *p){//{{{ char *s = p->cursor; p->this->start = s; s = cr_nextLine(p, s); p->cursor = p->this->end = s; p->this->kind = KIND_PARAGRAPH; return 1; } //}}} static void cr_parse(Parser *p, char* z){//{{{ p->previous = pool_new(p); p->previous->kind = KIND_PARA_BREAK; p->this = pool_new(p); p->this->kind = KIND_PARA_BREAK; p->inLink = 0; p->inTable = 0; p->cursor = z; p->list = NULL; p->istack = NULL; while (p->cursor[0]) { while (1){ // must be first if (isNoWikiBlock(p)) break; if (isParaBreak(p)) break; // order not important if (isMacro(p)) break; if (isHeading(p)) break; if (isHorizontalRule(p)) break; if (isListItem(p)) break; if (isTable(p)) break; // here for efficiency? if (isEndWikiMarker(p)) break; // must be last if (isParagraph(p)); break; // doh! assert(0); } int kind = p->this->kind; int prev = p->previous->kind; if (kind & KIND_END_WIKI_MARKER) return; if (kind == KIND_PARAGRAPH && prev & KIND_LIST_OR_PARAGRAPH) { p->previous->end = p->this->end; p->this = pool_new(p); continue; } if ( !(kind & KIND_LIST && prev & KIND_LIST) ) cr_render(p, p->previous); p->previous = p->this; p->this = pool_new(p); } } //}}} //}}} //{{{ MACROS LOCAL void do_macro_wiki_contents(Parser *p, Node *n){//{{{ Stmt q; blob_append(p->iblob, "<ul>", 4); db_prepare(&q, "SELECT substr(tagname, 6, 1000) FROM tag WHERE tagname GLOB 'wiki-*'" " ORDER BY lower(tagname)" ); while( db_step(&q)==SQLITE_ROW ){ const char *zName = db_column_text(&q, 0); blob_appendf(p->iblob, "<li><a href=\"%s/wiki?name=%T\">%h</a></li>", g.zBaseURL, zName, zName); } db_finalize(&q); blob_append(p->iblob, "</ul>", 5); }//}}} static int cr_match(char *z1, char *z2, int *len){ *len = strlen(z2); return !memcmp(z1, z2 ,*len); } int cr_has_macro(char *z, int *tokenType){ int len; if (cr_match(z, "wiki-contents>>", &len)) { *tokenType = MACRO_WIKI_CONTENTS; return len; } tokenType = MACRO_NONE; return 0; } //}}} char *wiki_render_creole(Renderer *r, char *z){ Parser parser; Parser *p = &parser; p->r = r; p->iblob = r->pOut; p->nFree = 0; p->pool = NULL; cr_parse(p, z); cr_render(p, p->previous); pool_free(p); return p->cursor; } |
Changes to src/main.mk.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 .. 98 99 100 101 102 103 104 105 106 107 108 109 110 111 ... 171 172 173 174 175 176 177 178 179 180 181 182 183 184 ... 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 ... 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
$(SRCDIR)/checkout.c \ $(SRCDIR)/clearsign.c \ $(SRCDIR)/clone.c \ $(SRCDIR)/comformat.c \ $(SRCDIR)/configure.c \ $(SRCDIR)/construct.c \ $(SRCDIR)/content.c \ $(SRCDIR)/db.c \ $(SRCDIR)/delta.c \ $(SRCDIR)/deltacmd.c \ $(SRCDIR)/descendants.c \ $(SRCDIR)/diff.c \ $(SRCDIR)/diffcmd.c \ $(SRCDIR)/doc.c \ ................................................................................ checkout_.c \ clearsign_.c \ clone_.c \ comformat_.c \ configure_.c \ construct_.c \ content_.c \ db_.c \ delta_.c \ deltacmd_.c \ descendants_.c \ diff_.c \ diffcmd_.c \ doc_.c \ ................................................................................ $(OBJDIR)/checkout.o \ $(OBJDIR)/clearsign.o \ $(OBJDIR)/clone.o \ $(OBJDIR)/comformat.o \ $(OBJDIR)/configure.o \ $(OBJDIR)/construct.o \ $(OBJDIR)/content.o \ $(OBJDIR)/db.o \ $(OBJDIR)/delta.o \ $(OBJDIR)/deltacmd.o \ $(OBJDIR)/descendants.o \ $(OBJDIR)/diff.o \ $(OBJDIR)/diffcmd.o \ $(OBJDIR)/doc.o \ ................................................................................ # $(SRCDIR)/../manifest: # noop clean: rm -f $(OBJDIR)/*.o *_.c $(APPNAME) VERSION.h rm -f translate makeheaders mkindex page_index.h headers rm -f add.h allrepo.h bag.h blob.h branch.h browse.h captcha.h cgi.h checkin.h checkout.h clearsign.h clone.h comformat.h configure.h construct.h content.h db.h delta.h deltacmd.h descendants.h diff.h diffcmd.h doc.h encode.h file.h finfo.h graph.h http.h http_socket.h http_ssl.h http_transport.h info.h login.h main.h manifest.h md5.h merge.h merge3.h name.h pivot.h pqueue.h printf.h rebuild.h report.h rss.h rstats.h schema.h search.h setup.h sha1.h shun.h skins.h stat.h style.h sync.h tag.h th_main.h timeline.h tkt.h tktsetup.h undo.h update.h url.h user.h verify.h vfile.h wiki.h wikiformat.h winhttp.h xfer.h zip.h page_index.h: $(TRANS_SRC) mkindex ./mkindex $(TRANS_SRC) >$@ headers: page_index.h makeheaders VERSION.h ./makeheaders add_.c:add.h allrepo_.c:allrepo.h bag_.c:bag.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h construct_.c:construct.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h file_.c:file.h finfo_.c:finfo.h graph_.c:graph.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h info_.c:info.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h pivot_.c:pivot.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h rstats_.c:rstats.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h zip_.c:zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h VERSION.h touch headers headers: Makefile Makefile: add_.c: $(SRCDIR)/add.c translate ./translate $(SRCDIR)/add.c >add_.c $(OBJDIR)/add.o: add_.c add.h $(SRCDIR)/config.h ................................................................................ content_.c: $(SRCDIR)/content.c translate ./translate $(SRCDIR)/content.c >content_.c $(OBJDIR)/content.o: content_.c content.h $(SRCDIR)/config.h $(XTCC) -o $(OBJDIR)/content.o -c content_.c content.h: headers db_.c: $(SRCDIR)/db.c translate ./translate $(SRCDIR)/db.c >db_.c $(OBJDIR)/db.o: db_.c db.h $(SRCDIR)/config.h $(XTCC) -o $(OBJDIR)/db.o -c db_.c db.h: headers |
> > > | | > > > > > > > |
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 .. 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 ... 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 ... 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 ... 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
$(SRCDIR)/checkout.c \ $(SRCDIR)/clearsign.c \ $(SRCDIR)/clone.c \ $(SRCDIR)/comformat.c \ $(SRCDIR)/configure.c \ $(SRCDIR)/construct.c \ $(SRCDIR)/content.c \ $(SRCDIR)/creoleparser.c \ $(SRCDIR)/db.c \ $(SRCDIR)/delta.c \ $(SRCDIR)/deltacmd.c \ $(SRCDIR)/descendants.c \ $(SRCDIR)/diff.c \ $(SRCDIR)/diffcmd.c \ $(SRCDIR)/doc.c \ ................................................................................ checkout_.c \ clearsign_.c \ clone_.c \ comformat_.c \ configure_.c \ construct_.c \ content_.c \ creoleparser_.c \ db_.c \ delta_.c \ deltacmd_.c \ descendants_.c \ diff_.c \ diffcmd_.c \ doc_.c \ ................................................................................ $(OBJDIR)/checkout.o \ $(OBJDIR)/clearsign.o \ $(OBJDIR)/clone.o \ $(OBJDIR)/comformat.o \ $(OBJDIR)/configure.o \ $(OBJDIR)/construct.o \ $(OBJDIR)/content.o \ $(OBJDIR)/creoleparser.o \ $(OBJDIR)/db.o \ $(OBJDIR)/delta.o \ $(OBJDIR)/deltacmd.o \ $(OBJDIR)/descendants.o \ $(OBJDIR)/diff.o \ $(OBJDIR)/diffcmd.o \ $(OBJDIR)/doc.o \ ................................................................................ # $(SRCDIR)/../manifest: # noop clean: rm -f $(OBJDIR)/*.o *_.c $(APPNAME) VERSION.h rm -f translate makeheaders mkindex page_index.h headers rm -f add.h allrepo.h bag.h blob.h branch.h browse.h captcha.h cgi.h checkin.h checkout.h clearsign.h clone.h comformat.h configure.h construct.h content.h creoleparser.h db.h delta.h deltacmd.h descendants.h diff.h diffcmd.h doc.h encode.h file.h finfo.h graph.h http.h http_socket.h http_ssl.h http_transport.h info.h login.h main.h manifest.h md5.h merge.h merge3.h name.h pivot.h pqueue.h printf.h rebuild.h report.h rss.h rstats.h schema.h search.h setup.h sha1.h shun.h skins.h stat.h style.h sync.h tag.h th_main.h timeline.h tkt.h tktsetup.h undo.h update.h url.h user.h verify.h vfile.h wiki.h wikiformat.h winhttp.h xfer.h zip.h page_index.h: $(TRANS_SRC) mkindex ./mkindex $(TRANS_SRC) >$@ headers: page_index.h makeheaders VERSION.h ./makeheaders add_.c:add.h allrepo_.c:allrepo.h bag_.c:bag.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h construct_.c:construct.h content_.c:content.h creoleparser_.c:creoleparser.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h file_.c:file.h finfo_.c:finfo.h graph_.c:graph.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h info_.c:info.h login_.c:login.h main_.c:main.h manifest_.c:manifest.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h name_.c:name.h pivot_.c:pivot.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h report_.c:report.h rss_.c:rss.h rstats_.c:rstats.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h update_.c:update.h url_.c:url.h user_.c:user.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winhttp_.c:winhttp.h xfer_.c:xfer.h zip_.c:zip.h $(SRCDIR)/sqlite3.h $(SRCDIR)/th.h VERSION.h touch headers headers: Makefile Makefile: add_.c: $(SRCDIR)/add.c translate ./translate $(SRCDIR)/add.c >add_.c $(OBJDIR)/add.o: add_.c add.h $(SRCDIR)/config.h ................................................................................ content_.c: $(SRCDIR)/content.c translate ./translate $(SRCDIR)/content.c >content_.c $(OBJDIR)/content.o: content_.c content.h $(SRCDIR)/config.h $(XTCC) -o $(OBJDIR)/content.o -c content_.c content.h: headers creoleparser_.c: $(SRCDIR)/creoleparser.c translate ./translate $(SRCDIR)/creoleparser.c >creoleparser_.c $(OBJDIR)/creoleparser.o: creoleparser_.c creoleparser.h $(SRCDIR)/config.h $(XTCC) -o $(OBJDIR)/creoleparser.o -c creoleparser_.c creoleparser.h: headers db_.c: $(SRCDIR)/db.c translate ./translate $(SRCDIR)/db.c >db_.c $(OBJDIR)/db.o: db_.c db.h $(SRCDIR)/config.h $(XTCC) -o $(OBJDIR)/db.o -c db_.c db.h: headers |
Changes to src/makemake.tcl.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
checkout clearsign clone comformat configure construct content db delta deltacmd descendants diff diffcmd doc |
> |
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
checkout
clearsign
clone
comformat
configure
construct
content
creoleparser
db
delta
deltacmd
descendants
diff
diffcmd
doc
|
Changes to src/style.c.
381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
@ @ /* The label/value pairs on (for example) the ci page */ @ table.label-value th { @ vertical-align: top; @ text-align: right; @ padding: 0.2ex 2ex; @ } ; /* ** WEBPAGE: style.css */ void page_style_css(void){ char *zCSS = 0; |
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
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 |
@ @ /* The label/value pairs on (for example) the ci page */ @ table.label-value th { @ vertical-align: top; @ text-align: right; @ padding: 0.2ex 2ex; @ } @ @ /* For marking important UI elements which shouldn't be @ lightly dismissed. I mainly use it to mark "not yet @ implemented" parts of a page. Whether or not to have @ a 'border' attribute set is arguable. */ @ .achtung { @ color: #ff0000; @ background: #ffff00; @ border: 1px solid #ff0000; @ } @ @ div.miniform { @ font-size: smaller; @ margin: 8px; @ } @ /* additions to support creole parser */ @ @ .creoletable { @ border: 1px solid #666666; @ border-spacing: 0; @ margin: 1.5em 2em 1.8em 2em; @ } @ .creoletable * tr th { @ font-size: 100%; @ padding: .5em .7em .5em .7em; @ border-left: 1px solid #666666; @ background-color: #558195; @ vertical-align: bottom; @ color: white; @ empty-cells: show; @ } @ .creoletable * tr td { @ padding: .4em .7em .45em .7em; @ border-left: 1px solid #D9D9D9; @ border-top: 1px solid #D9D9D9; @ vertical-align: center; @ empty-cells: show; @ } @ .creole-block-nowiki { @ background: oldlace; @ margin: 2em; @ overflow: auto; @ } @ .creole-inline-nowiki { @ background: oldlace; @ } @ .creole-noimage { @ color:green; @ border:1px solid green; @ } @ .creole-nomacro { @ color:red; @ border:1px solid red; @ } ; /* ** WEBPAGE: style.css */ void page_style_css(void){ char *zCSS = 0; |
Changes to src/wiki.c.
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
char *zDate; const char *zUser; const char *zRemark; char *zId; zDate = db_text(0, "SELECT datetime('now')"); zId = db_text(0, "SELECT lower(hex(randomblob(8)))"); blob_appendf(p, "\n\n<hr><div id=\"%s\"><i>On %s UTC %h", zId, zDate, g.zLogin); free(zDate); zUser = PD("u",g.zLogin); if( zUser[0] && strcmp(zUser,g.zLogin) ){ blob_appendf(p, " (claiming to be %h)", zUser); } zRemark = PD("r",""); blob_appendf(p, " added:</i><br />\n%s</div id=\"%s\">", zRemark, zId); } /* ** WEBPAGE: wikiappend ** URL: /wikiappend?name=PAGENAME */ void wikiappend_page(void){ |
> | |
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
char *zDate; const char *zUser; const char *zRemark; char *zId; zDate = db_text(0, "SELECT datetime('now')"); zId = db_text(0, "SELECT lower(hex(randomblob(8)))"); blob_append(p, "\n<<fossil>>\n", -1); blob_appendf(p, "\n\n<hr><div id=\"%s\"><i>On %s UTC %h", zId, zDate, g.zLogin); free(zDate); zUser = PD("u",g.zLogin); if( zUser[0] && strcmp(zUser,g.zLogin) ){ blob_appendf(p, " (claiming to be %h)", zUser); } zRemark = PD("r",""); blob_appendf(p, " added:</i><br />\n%s\n<<fossil>>\n</div id=\"%s\">", zRemark, zId); } /* ** WEBPAGE: wikiappend ** URL: /wikiappend?name=PAGENAME */ void wikiappend_page(void){ |
Changes to src/wikiformat.c.
333 334 335 336 337 338 339 340 341 342 343 344 345 346 ... 348 349 350 351 352 353 354 355 356 357 358 359 360 361 ... 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 ... 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 .... 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 .... 1433 1434 1435 1436 1437 1438 1439 |
#define TOKEN_NEWLINE 5 /* A single "\n" */ #define TOKEN_BUL_LI 6 /* " * " */ #define TOKEN_NUM_LI 7 /* " # " */ #define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */ #define TOKEN_INDENT 9 /* " " */ #define TOKEN_RAW 10 /* Output exactly (used when wiki-use-html==1) */ #define TOKEN_TEXT 11 /* None of the above */ /* ** State flags */ #define AT_NEWLINE 0x001 /* At start of a line */ #define AT_PARAGRAPH 0x002 /* At start of a paragraph */ #define ALLOW_WIKI 0x004 /* Allow wiki markup */ ................................................................................ #define INLINE_MARKUP_ONLY 0x010 /* Allow only "inline" markup */ #define IN_LIST 0x020 /* Within wiki <ul> or <ol> */ #define WIKI_USE_HTML 0x040 /* wiki-use-html option = on */ /* ** Current state of the rendering engine */ typedef struct Renderer Renderer; struct Renderer { Blob *pOut; /* Output appended to this blob */ int state; /* Flag that govern rendering */ int wikiList; /* Current wiki list type */ int inVerbatim; /* True in <verbatim> mode */ int preVerbState; /* Value of state prior to verbatim */ ................................................................................ int nAlloc; /* Space allocated for aStack */ struct sStack { short iCode; /* Markup code */ short allowWiki; /* ALLOW_WIKI if wiki allowed before tag */ const char *zId; /* ID attribute or NULL */ } *aStack; }; /* ** z points to a "<" character. Check to see if this is the start of ** a valid markup. If it is, return the total number of characters in ** the markup including the initial "<" and the terminating ">". If ** it is not well-formed markup, return 0. */ ................................................................................ ** Get the next wiki token. ** ** z points to the start of a token. Return the number of ** characters in that token. Write the token type into *pTokenType. */ static int nextWikiToken(const char *z, Renderer *p, int *pTokenType){ int n; if( z[0]=='<' ){ n = markupLength(z); if( n>0 ){ *pTokenType = TOKEN_MARKUP; return n; }else{ *pTokenType = TOKEN_CHARACTER; return 1; ................................................................................ while( z[0] ){ if( wikiUseHtml ){ n = nextRawToken(z, p, &tokenType); }else{ n = nextWikiToken(z, p, &tokenType); } p->state &= ~(AT_NEWLINE|AT_PARAGRAPH); switch( tokenType ){ case TOKEN_PARAGRAPH: { if( inlineOnly ){ /* blob_append(p->pOut, " ¶ ", -1); */ blob_append(p->pOut, " ", -1); }else{ ................................................................................ iStart = i+6; for(i=iStart; z[i] && (z[i]!='<' || strncmp(&z[i],"</title>",8)!=0); i++){} if( z[i]!='<' ) return 0; blob_init(pTitle, &z[iStart], i-iStart); blob_init(pTail, &z[i+8], -1); return 1; } |
> > > > | > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 ... 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 ... 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 ... 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 .... 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 .... 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 |
#define TOKEN_NEWLINE 5 /* A single "\n" */ #define TOKEN_BUL_LI 6 /* " * " */ #define TOKEN_NUM_LI 7 /* " # " */ #define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */ #define TOKEN_INDENT 9 /* " " */ #define TOKEN_RAW 10 /* Output exactly (used when wiki-use-html==1) */ #define TOKEN_TEXT 11 /* None of the above */ /* macro tokens - hackyyyy */ #define TOKEN_FOSSIL 12 /* fossil macro */ #define TOKEN_CREOLE 13 /* creole macro */ /* ** State flags */ #define AT_NEWLINE 0x001 /* At start of a line */ #define AT_PARAGRAPH 0x002 /* At start of a paragraph */ #define ALLOW_WIKI 0x004 /* Allow wiki markup */ ................................................................................ #define INLINE_MARKUP_ONLY 0x010 /* Allow only "inline" markup */ #define IN_LIST 0x020 /* Within wiki <ul> or <ol> */ #define WIKI_USE_HTML 0x040 /* wiki-use-html option = on */ /* ** Current state of the rendering engine */ #if INTERFACE typedef struct Renderer Renderer; struct Renderer { Blob *pOut; /* Output appended to this blob */ int state; /* Flag that govern rendering */ int wikiList; /* Current wiki list type */ int inVerbatim; /* True in <verbatim> mode */ int preVerbState; /* Value of state prior to verbatim */ ................................................................................ int nAlloc; /* Space allocated for aStack */ struct sStack { short iCode; /* Markup code */ short allowWiki; /* ALLOW_WIKI if wiki allowed before tag */ const char *zId; /* ID attribute or NULL */ } *aStack; }; #endif /* ** z points to a "<" character. Check to see if this is the start of ** a valid markup. If it is, return the total number of characters in ** the markup including the initial "<" and the terminating ">". If ** it is not well-formed markup, return 0. */ ................................................................................ ** Get the next wiki token. ** ** z points to the start of a token. Return the number of ** characters in that token. Write the token type into *pTokenType. */ static int nextWikiToken(const char *z, Renderer *p, int *pTokenType){ int n; if( !p->inVerbatim && z[0] == '<' && z[1] == '<' ) { if (!memcmp(z, "<<fossil>>", 10)) { *pTokenType = TOKEN_FOSSIL; return 10; } #ifdef HAVE_CREOLE_MACRO if (!memcmp(z, "<<creole>>", 10)) { *pTokenType = TOKEN_CREOLE; return 10; } #endif } else if( z[0]=='<' ){ n = markupLength(z); if( n>0 ){ *pTokenType = TOKEN_MARKUP; return n; }else{ *pTokenType = TOKEN_CHARACTER; return 1; ................................................................................ while( z[0] ){ if( wikiUseHtml ){ n = nextRawToken(z, p, &tokenType); }else{ n = nextWikiToken(z, p, &tokenType); } /* ** Additions to support creole switch */ if(tokenType == TOKEN_FOSSIL) { z+=10; continue; } #ifdef HAVE_CREOLE_MACRO else if(tokenType == TOKEN_CREOLE) { z = wiki_render_creole(p, z+n); } #endif /* if (!p->inVerbatim && z[0]=='<' && z[1] == '<') { z = wiki_render_macro(p, z, &tokenType); if (tokenType) continue; } */ /* end additions */ p->state &= ~(AT_NEWLINE|AT_PARAGRAPH); switch( tokenType ){ case TOKEN_PARAGRAPH: { if( inlineOnly ){ /* blob_append(p->pOut, " ¶ ", -1); */ blob_append(p->pOut, " ", -1); }else{ ................................................................................ iStart = i+6; for(i=iStart; z[i] && (z[i]!='<' || strncmp(&z[i],"</title>",8)!=0); i++){} if( z[i]!='<' ) return 0; blob_init(pTitle, &z[iStart], i-iStart); blob_init(pTail, &z[i+8], -1); return 1; } /* ** Additions to support macro extensions ** ** This only allows block level macros, not inline macros ** ** All macros must recognize '<<fossil>>' in the input ** stream and return control to fossil. */ char *wiki_render_macro(Renderer *p, char *z, int *tokenType){ if (!memcmp(z, "<<fossil>>", 10)){ *tokenType = TOKEN_MARKUP; /* Close enough for "in-progress". Should have it's own token type. */ return z + 10; } #ifdef HAVE_CREOLE_MACRO if (!memcmp(z, "<<creole>>", 10)) { *tokenType = TOKEN_MARKUP; return wiki_render_creole(p, z+10); } #endif *tokenType = 0; return z; } int wf_linkLength(const char *z){ return linkLength(z); } void wf_openHyperlink( Renderer *p, /* Rendering context */ const char *zTarget, /* Hyperlink traget; text within [...] */ char *zClose, /* Write hyperlink closing text here */ int nClose /* Bytes available in zClose[] */ ){ return openHyperlink(p, zTarget, zClose, nClose); } /* end additions */ |