| | @@ -28,11 +28,11 @@ |
| 28 | 28 | #include <assert.h> |
| 29 | 29 | #include "config.h" |
| 30 | 30 | #include "creoleparser.h" |
| 31 | 31 | |
| 32 | 32 | #if INTERFACE |
| 33 | | -#define HAVE_MACRO_EXTENSIONS 1 |
| 33 | +#define HAVE_CREOLE_MACRO 1 |
| 34 | 34 | #endif |
| 35 | 35 | |
| 36 | 36 | //{{{ LOCAL INTERFACE |
| 37 | 37 | #if LOCAL_INTERFACE |
| 38 | 38 | |
| | @@ -61,59 +61,59 @@ |
| 61 | 61 | |
| 62 | 62 | #define KIND_TABLE_ROW 0x0010000 |
| 63 | 63 | //}}} |
| 64 | 64 | //{{{ FLAG |
| 65 | 65 | // keep first four bits free |
| 66 | | -#define FLAG_CENTER 0x0000100 |
| 66 | +#define FLAG_CENTER 0x0000100 |
| 67 | 67 | //}}} |
| 68 | 68 | struct Node {//{{{ |
| 69 | 69 | |
| 70 | | - char *start; |
| 71 | | - char *end; |
| 72 | | - |
| 73 | | - int kind; |
| 74 | | - int level; |
| 75 | | - int flags; |
| 76 | | - |
| 77 | | - Node *parent; |
| 78 | | - Node *next; |
| 79 | | - Node *children; |
| 70 | + char *start; |
| 71 | + char *end; |
| 72 | + |
| 73 | + int kind; |
| 74 | + int level; |
| 75 | + int flags; |
| 76 | + |
| 77 | + Node *parent; |
| 78 | + Node *next; |
| 79 | + Node *children; |
| 80 | 80 | |
| 81 | 81 | }; |
| 82 | 82 | //}}} |
| 83 | 83 | struct NodePool {//{{{ |
| 84 | | - NodePool *next; |
| 85 | | - Node a[POOL_CHUNK_SIZE]; |
| 84 | + NodePool *next; |
| 85 | + Node a[POOL_CHUNK_SIZE]; |
| 86 | 86 | } |
| 87 | 87 | //}}} |
| 88 | 88 | struct Parser {//{{{ |
| 89 | 89 | |
| 90 | | - Blob *pOut; /* Output appended to this blob */ |
| 91 | | - Renderer *r; |
| 90 | + Blob *pOut; /* Output appended to this blob */ |
| 91 | + Renderer *r; |
| 92 | 92 | |
| 93 | | - NodePool *pool; |
| 94 | | - int nFree; |
| 93 | + NodePool *pool; |
| 94 | + int nFree; |
| 95 | 95 | |
| 96 | 96 | Node *this; |
| 97 | | - Node *previous; |
| 98 | | - Node *list; |
| 99 | | - |
| 100 | | - char *cursor; |
| 101 | | - |
| 102 | | - int lineWasBlank; |
| 103 | | - int charCount; |
| 104 | | - |
| 105 | | - Node *item; |
| 106 | | - Node *istack; |
| 107 | | - char *icursor; |
| 108 | | - char *iend; |
| 109 | | - |
| 110 | | - int inLink; |
| 111 | | - int inTable; |
| 112 | | - int iesc; |
| 113 | | - |
| 114 | | - Blob *iblob; |
| 97 | + Node *previous; |
| 98 | + Node *list; |
| 99 | + |
| 100 | + char *cursor; |
| 101 | + |
| 102 | + int lineWasBlank; |
| 103 | + int charCount; |
| 104 | + |
| 105 | + Node *item; |
| 106 | + Node *istack; |
| 107 | + char *icursor; |
| 108 | + char *iend; |
| 109 | + |
| 110 | + int inLink; |
| 111 | + int inTable; |
| 112 | + int iesc; |
| 113 | + |
| 114 | + Blob *iblob; |
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | |
| 119 | 119 | }; |
| | @@ -126,484 +126,485 @@ |
| 126 | 126 | //}}} |
| 127 | 127 | |
| 128 | 128 | //{{{ POOL MANAGEMENT |
| 129 | 129 | static Node *pool_new(Parser *p){ |
| 130 | 130 | |
| 131 | | - if ( p->pool == NULL || p->nFree == 0){ |
| 132 | | - |
| 133 | | - NodePool *temp = p->pool; |
| 134 | | - |
| 135 | | - p->pool = malloc(sizeof(NodePool)); |
| 136 | | - if( p->pool == NULL ) fossil_panic("out of memory"); |
| 137 | | - |
| 138 | | - p->pool->next = temp; |
| 139 | | - p->nFree = POOL_CHUNK_SIZE; |
| 140 | | - } |
| 141 | | - p->nFree -= 1; |
| 142 | | - Node *node = &(p->pool->a[p->nFree]); |
| 143 | | - memset(node, 0, sizeof(*node)); |
| 144 | | - |
| 145 | | - return node; |
| 131 | + if ( p->pool == NULL || p->nFree == 0){ |
| 132 | + |
| 133 | + NodePool *temp = p->pool; |
| 134 | + |
| 135 | + p->pool = malloc(sizeof(NodePool)); |
| 136 | + if( p->pool == NULL ) fossil_panic("out of memory"); |
| 137 | + |
| 138 | + p->pool->next = temp; |
| 139 | + p->nFree = POOL_CHUNK_SIZE; |
| 140 | + } |
| 141 | + p->nFree -= 1; |
| 142 | + Node *node = &(p->pool->a[p->nFree]); |
| 143 | + memset(node, 0, sizeof(*node)); |
| 144 | + |
| 145 | + return node; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
| 149 | 149 | static void pool_free(Parser *p){ |
| 150 | 150 | |
| 151 | | - NodePool *temp; |
| 151 | + NodePool *temp; |
| 152 | 152 | |
| 153 | | - while (p->pool != NULL){ |
| 154 | | - temp = p->pool; |
| 155 | | - p->pool = temp->next; |
| 156 | | - free(temp); |
| 157 | | - } |
| 153 | + while (p->pool != NULL){ |
| 154 | + temp = p->pool; |
| 155 | + p->pool = temp->next; |
| 156 | + free(temp); |
| 157 | + } |
| 158 | 158 | |
| 159 | 159 | } |
| 160 | 160 | //}}} |
| 161 | 161 | |
| 162 | 162 | //{{{ Utility Methods |
| 163 | 163 | |
| 164 | 164 | static char *cr_skipBlanks(Parser *p, char* z){//{{{ |
| 165 | | - char *s = z; |
| 166 | | - while (z[0] == ' ' || z[0] == '\t') z++; |
| 167 | | - p->charCount = z - s; |
| 168 | | - return z; |
| 165 | + char *s = z; |
| 166 | + while (z[0] == ' ' || z[0] == '\t') z++; |
| 167 | + p->charCount = z - s; |
| 168 | + return z; |
| 169 | 169 | } |
| 170 | 170 | //}}} |
| 171 | 171 | static int cr_countBlanks(Parser *p, char* z){//{{{ |
| 172 | | - cr_skipBlanks(p, z); |
| 173 | | - return p->charCount; |
| 172 | + cr_skipBlanks(p, z); |
| 173 | + return p->charCount; |
| 174 | 174 | } |
| 175 | 175 | //}}} |
| 176 | 176 | static char *cr_skipChars(Parser *p, char *z, char c){//{{{ |
| 177 | | - char *s = z; |
| 178 | | - while (z[0] == c) z++; |
| 179 | | - p->charCount = z - s; |
| 180 | | - return z; |
| 177 | + char *s = z; |
| 178 | + while (z[0] == c) z++; |
| 179 | + p->charCount = z - s; |
| 180 | + return z; |
| 181 | 181 | } |
| 182 | 182 | //}}} |
| 183 | 183 | static int cr_countChars(Parser *p, char *z, char c){//{{{ |
| 184 | | - cr_skipChars(p, z, c); |
| 185 | | - return p->charCount; |
| 184 | + cr_skipChars(p, z, c); |
| 185 | + return p->charCount; |
| 186 | 186 | } |
| 187 | 187 | //}}} |
| 188 | 188 | static char *cr_nextLine(Parser *p, char *z){//{{{ |
| 189 | 189 | |
| 190 | | - p->lineWasBlank = 1; |
| 191 | | - |
| 192 | | - while (1){ |
| 193 | | - |
| 194 | | - switch (z[0]){ |
| 195 | | - |
| 196 | | - case '\r': |
| 197 | | - if (z[1] == '\n') { |
| 198 | | - z[0] = ' '; |
| 199 | | - return z + 2; |
| 200 | | - } |
| 201 | | - z[0] = '\n'; |
| 202 | | - return z + 1; |
| 203 | | - |
| 204 | | - case'\n': |
| 205 | | - return z + 1; |
| 206 | | - |
| 207 | | - case '\t': |
| 208 | | - z[0] = ' '; |
| 209 | | - z++; |
| 210 | | - break; |
| 211 | | - |
| 212 | | - case ' ': |
| 213 | | - z++; |
| 214 | | - break; |
| 215 | | - |
| 216 | | - case '\0': |
| 217 | | - return z; |
| 218 | | - |
| 219 | | - default: |
| 220 | | - p->lineWasBlank = 0; |
| 221 | | - z++; |
| 222 | | - } |
| 223 | | - } |
| 190 | + p->lineWasBlank = 1; |
| 191 | + |
| 192 | + while (1){ |
| 193 | + |
| 194 | + switch (z[0]){ |
| 195 | + |
| 196 | + case '\r': |
| 197 | + if (z[1] == '\n') { |
| 198 | + z[0] = ' '; |
| 199 | + return z + 2; |
| 200 | + } |
| 201 | + z[0] = '\n'; |
| 202 | + return z + 1; |
| 203 | + |
| 204 | + case'\n': |
| 205 | + return z + 1; |
| 206 | + |
| 207 | + case '\t': |
| 208 | + z[0] = ' '; |
| 209 | + z++; |
| 210 | + break; |
| 211 | + |
| 212 | + case ' ': |
| 213 | + z++; |
| 214 | + break; |
| 215 | + |
| 216 | + case '\0': |
| 217 | + return z; |
| 218 | + |
| 219 | + default: |
| 220 | + p->lineWasBlank = 0; |
| 221 | + z++; |
| 222 | + } |
| 223 | + } |
| 224 | 224 | } |
| 225 | 225 | //}}} |
| 226 | 226 | //}}} |
| 227 | 227 | |
| 228 | 228 | //{{{ INLINE PARSER |
| 229 | 229 | |
| 230 | 230 | static int cr_isEsc(Parser *p){//{{{ |
| 231 | | - if (p->iesc){ |
| 232 | | - blob_append(p->iblob, p->icursor, 1); |
| 233 | | - p->iesc = 0; |
| 234 | | - p->icursor += 1; |
| 235 | | - return 1; |
| 236 | | - } |
| 237 | | - return 0; |
| 231 | + if (p->iesc){ |
| 232 | + blob_append(p->iblob, p->icursor, 1); |
| 233 | + p->iesc = 0; |
| 234 | + p->icursor += 1; |
| 235 | + return 1; |
| 236 | + } |
| 237 | + return 0; |
| 238 | 238 | } |
| 239 | 239 | //}}} |
| 240 | 240 | static int cr_iOpen(Parser *p, int kind){//{{{ |
| 241 | 241 | |
| 242 | | - switch (kind){ |
| 243 | | - |
| 244 | | - case KIND_BOLD: |
| 245 | | - blob_append(p->iblob, "<strong>", 8); |
| 246 | | - return 1; |
| 247 | | - |
| 248 | | - case KIND_ITALIC: |
| 249 | | - blob_append(p->iblob, "<em>", 4); |
| 250 | | - return 1; |
| 251 | | - |
| 252 | | - case KIND_SUPERSCRIPT: |
| 253 | | - blob_append(p->iblob, "<sup>", 5); |
| 254 | | - return 1; |
| 255 | | - |
| 256 | | - case KIND_SUBSCRIPT: |
| 257 | | - blob_append(p->iblob, "<sub>", 5); |
| 258 | | - return 1; |
| 259 | | - |
| 260 | | - case KIND_MONOSPACED: |
| 261 | | - blob_append(p->iblob, "<tt>", 4); |
| 262 | | - return 1; |
| 263 | | - } |
| 264 | | - return 0; |
| 242 | + switch (kind){ |
| 243 | + |
| 244 | + case KIND_BOLD: |
| 245 | + blob_append(p->iblob, "<strong>", 8); |
| 246 | + return 1; |
| 247 | + |
| 248 | + case KIND_ITALIC: |
| 249 | + blob_append(p->iblob, "<em>", 4); |
| 250 | + return 1; |
| 251 | + |
| 252 | + case KIND_SUPERSCRIPT: |
| 253 | + blob_append(p->iblob, "<sup>", 5); |
| 254 | + return 1; |
| 255 | + |
| 256 | + case KIND_SUBSCRIPT: |
| 257 | + blob_append(p->iblob, "<sub>", 5); |
| 258 | + return 1; |
| 259 | + |
| 260 | + case KIND_MONOSPACED: |
| 261 | + blob_append(p->iblob, "<tt>", 4); |
| 262 | + return 1; |
| 263 | + } |
| 264 | + return 0; |
| 265 | 265 | } |
| 266 | 266 | //}}} |
| 267 | 267 | static int cr_iClose(Parser *p, int kind){//{{{ |
| 268 | 268 | |
| 269 | | - switch (kind){ |
| 270 | | - |
| 271 | | - case KIND_BOLD: |
| 272 | | - blob_append(p->iblob, "</strong>", 9); |
| 273 | | - return 1; |
| 274 | | - |
| 275 | | - case KIND_ITALIC: |
| 276 | | - blob_append(p->iblob, "</em>", 5); |
| 277 | | - return 1; |
| 278 | | - |
| 279 | | - case KIND_SUPERSCRIPT: |
| 280 | | - blob_append(p->iblob, "</sup>", 6); |
| 281 | | - return 1; |
| 282 | | - |
| 283 | | - case KIND_SUBSCRIPT: |
| 284 | | - blob_append(p->iblob, "</sub>", 6); |
| 285 | | - return 1; |
| 286 | | - |
| 287 | | - case KIND_MONOSPACED: |
| 288 | | - blob_append(p->iblob, "</tt>", 5); |
| 289 | | - return 1; |
| 290 | | - } |
| 291 | | - return 0; |
| 269 | + switch (kind){ |
| 270 | + |
| 271 | + case KIND_BOLD: |
| 272 | + blob_append(p->iblob, "</strong>", 9); |
| 273 | + return 1; |
| 274 | + |
| 275 | + case KIND_ITALIC: |
| 276 | + blob_append(p->iblob, "</em>", 5); |
| 277 | + return 1; |
| 278 | + |
| 279 | + case KIND_SUPERSCRIPT: |
| 280 | + blob_append(p->iblob, "</sup>", 6); |
| 281 | + return 1; |
| 282 | + |
| 283 | + case KIND_SUBSCRIPT: |
| 284 | + blob_append(p->iblob, "</sub>", 6); |
| 285 | + return 1; |
| 286 | + |
| 287 | + case KIND_MONOSPACED: |
| 288 | + blob_append(p->iblob, "</tt>", 5); |
| 289 | + return 1; |
| 290 | + } |
| 291 | + return 0; |
| 292 | 292 | } |
| 293 | 293 | //}}} |
| 294 | 294 | |
| 295 | 295 | |
| 296 | 296 | static void cr_iMarkup(Parser *p, int kind){//{{{ |
| 297 | 297 | |
| 298 | | - if (p->iesc) { |
| 299 | | - blob_append(p->iblob, p->icursor, 1); |
| 300 | | - p->icursor +=1; |
| 301 | | - p->iesc =0; |
| 302 | | - return; |
| 303 | | - } |
| 304 | | - |
| 305 | | - if (p->icursor[1] != p->icursor[0]) { |
| 306 | | - blob_append(p->iblob, p->icursor, 1); |
| 307 | | - p->icursor +=1; |
| 308 | | - return; |
| 309 | | - } |
| 310 | | - |
| 311 | | - p->icursor += 2; |
| 312 | | - |
| 313 | | - if (kind & KIND_BREAK) { |
| 314 | | - blob_append(p->iblob, "<br />", 6); |
| 315 | | - return; |
| 316 | | - } |
| 317 | | - |
| 318 | | - if (kind & KIND_ITALIC && p->icursor[-3] == ':'){ |
| 319 | | - blob_append(p->iblob, "//", 2); |
| 320 | | - return; |
| 321 | | - } |
| 322 | | - |
| 323 | | - Node *n = p->istack; |
| 324 | | - |
| 325 | | - int found = 0; |
| 326 | | - while (n) { |
| 327 | | - if (n->kind & kind) { |
| 328 | | - found = 1; |
| 329 | | - break; |
| 330 | | - } |
| 331 | | - n = n->next; |
| 332 | | - } |
| 333 | | - |
| 334 | | - if (!found) { |
| 335 | | - n = pool_new(p); |
| 336 | | - n->kind = kind; |
| 337 | | - n->next = p->istack; |
| 338 | | - p->istack = n; |
| 339 | | - |
| 340 | | - assert(cr_iOpen(p, kind)); |
| 341 | | - return; |
| 342 | | - }; |
| 343 | | - |
| 344 | | - n= p->istack; |
| 345 | | - while (n){ |
| 346 | | - p->istack = n->next; |
| 347 | | - |
| 348 | | - assert(cr_iClose(p, n->kind)); |
| 349 | | - |
| 350 | | - if (kind == n->kind) return; |
| 351 | | - n = p->istack; |
| 352 | | - } |
| 298 | + if (p->iesc) { |
| 299 | + blob_append(p->iblob, p->icursor, 1); |
| 300 | + p->icursor +=1; |
| 301 | + p->iesc =0; |
| 302 | + return; |
| 303 | + } |
| 304 | + |
| 305 | + if (p->icursor[1] != p->icursor[0]) { |
| 306 | + blob_append(p->iblob, p->icursor, 1); |
| 307 | + p->icursor +=1; |
| 308 | + return; |
| 309 | + } |
| 310 | + |
| 311 | + p->icursor += 2; |
| 312 | + |
| 313 | + if (kind & KIND_BREAK) { |
| 314 | + blob_append(p->iblob, "<br />", 6); |
| 315 | + return; |
| 316 | + } |
| 317 | + |
| 318 | + if (kind & KIND_ITALIC && p->icursor[-3] == ':'){ |
| 319 | + blob_append(p->iblob, "//", 2); |
| 320 | + return; |
| 321 | + } |
| 322 | + |
| 323 | + Node *n = p->istack; |
| 324 | + |
| 325 | + int found = 0; |
| 326 | + while (n) { |
| 327 | + if (n->kind & kind) { |
| 328 | + found = 1; |
| 329 | + break; |
| 330 | + } |
| 331 | + n = n->next; |
| 332 | + } |
| 333 | + |
| 334 | + if (!found) { |
| 335 | + n = pool_new(p); |
| 336 | + n->kind = kind; |
| 337 | + n->next = p->istack; |
| 338 | + p->istack = n; |
| 339 | + |
| 340 | + assert(cr_iOpen(p, kind)); |
| 341 | + return; |
| 342 | + }; |
| 343 | + |
| 344 | + n= p->istack; |
| 345 | + while (n){ |
| 346 | + p->istack = n->next; |
| 347 | + |
| 348 | + assert(cr_iClose(p, n->kind)); |
| 349 | + |
| 350 | + if (kind == n->kind) return; |
| 351 | + n = p->istack; |
| 352 | + } |
| 353 | 353 | } |
| 354 | 354 | //}}} |
| 355 | 355 | static int cr_iNoWiki(Parser *p){//{{{ |
| 356 | 356 | |
| 357 | | - if ((p->iend - p->icursor)<6) return 0; |
| 358 | | - |
| 359 | | - if (p->icursor[1]!='{' || p->icursor[2]!='{') |
| 360 | | - return 0; |
| 361 | | - |
| 362 | | - char *s = p->icursor + 3; |
| 363 | | - |
| 364 | | - int count = p->iend - p->icursor - 6; |
| 365 | | - while (count--){ |
| 366 | | - if (s[0]=='}' && s[1]=='}' && s[2]=='}' && s[3]!='}'){ |
| 367 | | - blob_appendf(p->iblob, "<tt style='background:oldlace'>%s</tt>", htmlize(p->icursor + 3, s - p->icursor-3)); |
| 368 | | - p->icursor = s + 3; |
| 369 | | - return 1; |
| 370 | | - } |
| 371 | | - s++; |
| 372 | | - } |
| 373 | | - return 0; |
| 357 | + if ((p->iend - p->icursor)<6) return 0; |
| 358 | + |
| 359 | + if (p->icursor[1]!='{' || p->icursor[2]!='{') |
| 360 | + return 0; |
| 361 | + |
| 362 | + char *s = p->icursor + 3; |
| 363 | + |
| 364 | + int count = p->iend - p->icursor - 6; |
| 365 | + while (count--){ |
| 366 | + if (s[0]=='}' && s[1]=='}' && s[2]=='}' && s[3]!='}'){ |
| 367 | + blob_appendf(p->iblob, "<tt style='background:oldlace'>%s</tt>", htmlize(p->icursor + 3, s - p->icursor-3)); |
| 368 | + p->icursor = s + 3; |
| 369 | + return 1; |
| 370 | + } |
| 371 | + s++; |
| 372 | + } |
| 373 | + return 0; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | //}}} |
| 377 | 377 | static int cr_iImage(Parser *p){//{{{ |
| 378 | 378 | |
| 379 | | - if (p->inLink) return 0; |
| 380 | | - if ((p->iend - p->icursor)<3) return 0; |
| 381 | | - |
| 382 | | - if (p->icursor[1]!='{') return 0; |
| 383 | | - |
| 384 | | - char *s = p->icursor + 2; |
| 385 | | - char *bar = NULL; |
| 386 | | - |
| 387 | | - int count = p->iend - p->icursor - 4; |
| 388 | | - while (count--){ |
| 389 | | - if (s[0]=='}' && s[1]=='}'){ |
| 390 | | - if (!bar) bar = p->icursor + 2; |
| 391 | | - blob_appendf(p->iblob, "<span style='color:green;border:1px solid green;'>%s</span>", htmlize(bar, s - bar )); |
| 392 | | - p->icursor = s + 2; |
| 393 | | - return 1; |
| 394 | | - } |
| 395 | | - if (!bar && s[0]=='|') bar=s+1; |
| 396 | | - s++; |
| 397 | | - } |
| 398 | | - return 0; |
| 379 | + if (p->inLink) return 0; |
| 380 | + if ((p->iend - p->icursor)<3) return 0; |
| 381 | + |
| 382 | + if (p->icursor[1]!='{') return 0; |
| 383 | + |
| 384 | + char *s = p->icursor + 2; |
| 385 | + char *bar = NULL; |
| 386 | + |
| 387 | + int count = p->iend - p->icursor - 4; |
| 388 | + while (count--){ |
| 389 | + if (s[0]=='}' && s[1]=='}'){ |
| 390 | + if (!bar) bar = p->icursor + 2; |
| 391 | + blob_appendf(p->iblob, "<span style='color:green;border:1px solid green;'>%s</span>", htmlize(bar, s - bar )); |
| 392 | + p->icursor = s + 2; |
| 393 | + return 1; |
| 394 | + } |
| 395 | + if (!bar && s[0]=='|') bar=s+1; |
| 396 | + s++; |
| 397 | + } |
| 398 | + return 0; |
| 399 | 399 | } |
| 400 | 400 | //}}} |
| 401 | 401 | static int cr_iMacro(Parser *p){//{{{ |
| 402 | 402 | |
| 403 | | - if (p->inLink) return 0; |
| 404 | | - if ((p->iend - p->icursor)<3) return 0; |
| 405 | | - |
| 406 | | - if (p->icursor[1]!='<') return 0; |
| 407 | | - |
| 408 | | - char *s = p->icursor + 2; |
| 409 | | - |
| 410 | | - int count = p->iend - p->icursor - 4; |
| 411 | | - while (count--){ |
| 412 | | - if (s[0]=='>' && s[1]=='>'){ |
| 413 | | - blob_appendf(p->iblob, "<span style='color:red;border:1px solid red;'>%s</span>", htmlize(p->icursor, s - p->icursor + 2)); |
| 414 | | - p->icursor = s + 2; |
| 415 | | - return 1; |
| 416 | | - } |
| 417 | | - s++; |
| 418 | | - } |
| 419 | | - return 0; |
| 403 | + if (p->inLink) return 0; |
| 404 | + if ((p->iend - p->icursor)<3) return 0; |
| 405 | + |
| 406 | + if (p->icursor[1]!='<') return 0; |
| 407 | + |
| 408 | + char *s = p->icursor + 2; |
| 409 | + |
| 410 | + int count = p->iend - p->icursor - 3; |
| 411 | + while (count--){ |
| 412 | + blob_appendf(p->iblob, "|~%s|", s,2 ); |
| 413 | + if (s[0]=='>' && s[1]=='>'){ |
| 414 | + blob_appendf(p->iblob, "<span style='color:red;border:1px solid red;'>%s</span>", htmlize(p->icursor, s - p->icursor + 2)); |
| 415 | + p->icursor = s + 2; |
| 416 | + return 1; |
| 417 | + } |
| 418 | + s++; |
| 419 | + } |
| 420 | + return 0; |
| 420 | 421 | |
| 421 | 422 | } |
| 422 | 423 | //}}} |
| 423 | 424 | |
| 424 | 425 | static void cr_renderLink(Parser *p, char *s, char *bar, char *e){//{{{ |
| 425 | 426 | |
| 426 | | - int tsize = bar-s; |
| 427 | | - int dsize = e - bar-1; |
| 428 | | - |
| 429 | | - if (tsize < 1) return; |
| 430 | | - if (dsize < 1) dsize = 0; |
| 431 | | - |
| 432 | | - char zTarget[tsize + 1]; |
| 433 | | - memcpy(zTarget, s, tsize); |
| 434 | | - zTarget[tsize] = '\0'; |
| 435 | | - |
| 436 | | - char zClose[20]; |
| 437 | | - |
| 438 | | - Blob *pOut = p->r->pOut; |
| 439 | | - |
| 440 | | - p->r->pOut = p->iblob; |
| 441 | | - wf_openHyperlink(p->r, zTarget, zClose, sizeof(zClose)); |
| 442 | | - p->r->pOut = pOut; |
| 443 | | - |
| 444 | | - if (dsize) |
| 445 | | - cr_parseInline(p, bar+1, e) ; |
| 446 | | - else |
| 447 | | - blob_append(p->iblob, htmlize(s, tsize), -1); |
| 448 | | - blob_append(p->iblob, zClose, -1); |
| 427 | + int tsize = bar-s; |
| 428 | + int dsize = e - bar-1; |
| 429 | + |
| 430 | + if (tsize < 1) return; |
| 431 | + if (dsize < 1) dsize = 0; |
| 432 | + |
| 433 | + char zTarget[tsize + 1]; |
| 434 | + memcpy(zTarget, s, tsize); |
| 435 | + zTarget[tsize] = '\0'; |
| 436 | + |
| 437 | + char zClose[20]; |
| 438 | + |
| 439 | + Blob *pOut = p->r->pOut; |
| 440 | + |
| 441 | + p->r->pOut = p->iblob; |
| 442 | + wf_openHyperlink(p->r, zTarget, zClose, sizeof(zClose)); |
| 443 | + p->r->pOut = pOut; |
| 444 | + |
| 445 | + if (dsize) |
| 446 | + cr_parseInline(p, bar+1, e) ; |
| 447 | + else |
| 448 | + blob_append(p->iblob, htmlize(s, tsize), -1); |
| 449 | + blob_append(p->iblob, zClose, -1); |
| 449 | 450 | } |
| 450 | 451 | //}}} |
| 451 | 452 | |
| 452 | 453 | static int cr_iLink(Parser *p){//{{{ |
| 453 | 454 | |
| 454 | | - if (p->inLink) return 0; |
| 455 | | - if ((p->iend - p->icursor)<3) return 0; |
| 456 | | - |
| 457 | | - if (p->icursor[1]!='[') return 0; |
| 458 | | - |
| 459 | | - char *s = p->icursor + 2; |
| 460 | | - char *bar = NULL; |
| 461 | | - |
| 462 | | - int count = p->iend - p->icursor -3; |
| 463 | | - while (count--){ |
| 464 | | - if (s[0]==']' && s[1]==']'){ |
| 465 | | - if (!bar) bar = s; |
| 466 | | - p->inLink = 1; |
| 467 | | - cr_renderLink(p, p->icursor+2, bar, s); |
| 468 | | - p->inLink = 0; |
| 469 | | - p->icursor = s + 2; |
| 470 | | - return 1; |
| 471 | | - } |
| 472 | | - if (!bar && s[0]=='|') bar=s; |
| 473 | | - s++; |
| 474 | | - } |
| 475 | | - return 0; |
| 455 | + if (p->inLink) return 0; |
| 456 | + if ((p->iend - p->icursor)<3) return 0; |
| 457 | + |
| 458 | + if (p->icursor[1]!='[') return 0; |
| 459 | + |
| 460 | + char *s = p->icursor + 2; |
| 461 | + char *bar = NULL; |
| 462 | + |
| 463 | + int count = p->iend - p->icursor -3; |
| 464 | + while (count--){ |
| 465 | + if (s[0]==']' && s[1]==']'){ |
| 466 | + if (!bar) bar = s; |
| 467 | + p->inLink = 1; |
| 468 | + cr_renderLink(p, p->icursor+2, bar, s); |
| 469 | + p->inLink = 0; |
| 470 | + p->icursor = s + 2; |
| 471 | + return 1; |
| 472 | + } |
| 473 | + if (!bar && s[0]=='|') bar=s; |
| 474 | + s++; |
| 475 | + } |
| 476 | + return 0; |
| 476 | 477 | } |
| 477 | 478 | //}}} |
| 478 | 479 | |
| 479 | 480 | LOCAL char *cr_parseInline(Parser *p, char *s, char *e){//{{{ |
| 480 | 481 | |
| 481 | | - int save_iesc = p->iesc; |
| 482 | | - char *save_iend = p->iend; |
| 483 | | - Node *save_istack = p->istack; |
| 484 | | - |
| 485 | | - p->iesc = 0; |
| 486 | | - p->iend = e; |
| 487 | | - p->istack = NULL; |
| 488 | | - |
| 489 | | - p->icursor = s; |
| 490 | | - |
| 491 | | - char *eof = NULL; |
| 492 | | - while (!eof && p->icursor < p->iend ){ |
| 493 | | - |
| 494 | | - switch (*p->icursor) {//{{{ |
| 495 | | - |
| 496 | | - case '~': |
| 497 | | - if (p->iesc) { |
| 498 | | - blob_append(p->iblob, "~", 1); |
| 499 | | - p->iesc = 0; |
| 500 | | - } |
| 501 | | - p->iesc = !p->iesc; |
| 502 | | - p->icursor+=1; |
| 503 | | - break; |
| 504 | | - |
| 505 | | - case '*': |
| 506 | | - cr_iMarkup(p, KIND_BOLD); |
| 507 | | - break; |
| 508 | | - |
| 509 | | - case '/': |
| 510 | | - cr_iMarkup(p, KIND_ITALIC); |
| 511 | | - break; |
| 512 | | - |
| 513 | | - case '^': |
| 514 | | - cr_iMarkup(p, KIND_SUPERSCRIPT); |
| 515 | | - break; |
| 516 | | - |
| 517 | | - case ',': |
| 518 | | - cr_iMarkup(p, KIND_SUBSCRIPT); |
| 519 | | - break; |
| 520 | | - |
| 521 | | - case '#': |
| 522 | | - cr_iMarkup(p, KIND_MONOSPACED); |
| 523 | | - break; |
| 524 | | - |
| 525 | | - case '\\': |
| 526 | | - cr_iMarkup(p, KIND_BREAK); |
| 527 | | - break; |
| 528 | | - |
| 529 | | - case '{': |
| 530 | | - if (cr_isEsc(p)) break; |
| 531 | | - if (cr_iNoWiki(p)) break; |
| 532 | | - if (cr_iImage(p)) break; |
| 533 | | - blob_append(p->iblob, p->icursor, 1); |
| 534 | | - p->icursor += 1; |
| 535 | | - break; |
| 536 | | - |
| 537 | | - case '[': |
| 538 | | - if (cr_isEsc(p)) break; |
| 539 | | - if (cr_iLink(p)) break; |
| 540 | | - blob_append(p->iblob, p->icursor, 1); |
| 541 | | - p->icursor += 1; |
| 542 | | - break; |
| 543 | | - |
| 544 | | - |
| 545 | | - case '<': |
| 546 | | - if (cr_isEsc(p)) break; |
| 547 | | - if (cr_iMacro(p)) break; |
| 548 | | - |
| 549 | | - blob_append(p->iblob, "<", 4); |
| 550 | | - p->icursor += 1; |
| 551 | | - break; |
| 552 | | - |
| 553 | | - case '>': |
| 554 | | - if (p->iesc) { |
| 555 | | - blob_append(p->iblob, "~", 1); |
| 556 | | - p->iesc = 0; |
| 557 | | - } |
| 558 | | - blob_append(p->iblob, ">", 4); |
| 559 | | - p->icursor += 1; |
| 560 | | - break; |
| 561 | | - |
| 562 | | - case '&': |
| 563 | | - if (p->iesc) { |
| 564 | | - blob_append(p->iblob, "~", 1); |
| 565 | | - p->iesc = 0; |
| 566 | | - } |
| 567 | | - blob_append(p->iblob, "&", 5); |
| 568 | | - p->icursor += 1; |
| 569 | | - break; |
| 570 | | - |
| 571 | | - case '|': |
| 572 | | - if (p->inTable){ |
| 573 | | - if (p->iesc) { |
| 574 | | - blob_append(p->iblob, p->icursor, 1); |
| 575 | | - p->iesc = 0; |
| 576 | | - p->icursor += 1; |
| 577 | | - break; |
| 578 | | - } |
| 579 | | - eof = p->icursor + 1; |
| 580 | | - break; |
| 581 | | - } |
| 582 | | - // fall through to default |
| 583 | | - |
| 584 | | - default: |
| 585 | | - if (p->iesc) { |
| 586 | | - blob_append(p->iblob, "~", 1); |
| 587 | | - p->iesc = 0; |
| 588 | | - } |
| 589 | | - blob_append(p->iblob, p->icursor, 1); |
| 590 | | - p->icursor +=1; |
| 591 | | - }//}}} |
| 592 | | - |
| 593 | | - } |
| 594 | | - |
| 595 | | - while (p->istack){ |
| 596 | | - cr_iClose(p, p->istack->kind); |
| 597 | | - p->istack = p->istack->next; |
| 598 | | - } |
| 599 | | - |
| 600 | | - p->iesc = save_iesc; |
| 601 | | - p->iend = save_iend; |
| 602 | | - p->istack = save_istack; |
| 603 | | - |
| 604 | | - return eof; |
| 482 | + int save_iesc = p->iesc; |
| 483 | + char *save_iend = p->iend; |
| 484 | + Node *save_istack = p->istack; |
| 485 | + |
| 486 | + p->iesc = 0; |
| 487 | + p->iend = e; |
| 488 | + p->istack = NULL; |
| 489 | + |
| 490 | + p->icursor = s; |
| 491 | + |
| 492 | + char *eof = NULL; |
| 493 | + while (!eof && p->icursor < p->iend ){ |
| 494 | + |
| 495 | + switch (*p->icursor) {//{{{ |
| 496 | + |
| 497 | + case '~': |
| 498 | + if (p->iesc) { |
| 499 | + blob_append(p->iblob, "~", 1); |
| 500 | + p->iesc = 0; |
| 501 | + } |
| 502 | + p->iesc = !p->iesc; |
| 503 | + p->icursor+=1; |
| 504 | + break; |
| 505 | + |
| 506 | + case '*': |
| 507 | + cr_iMarkup(p, KIND_BOLD); |
| 508 | + break; |
| 509 | + |
| 510 | + case '/': |
| 511 | + cr_iMarkup(p, KIND_ITALIC); |
| 512 | + break; |
| 513 | + |
| 514 | + case '^': |
| 515 | + cr_iMarkup(p, KIND_SUPERSCRIPT); |
| 516 | + break; |
| 517 | + |
| 518 | + case ',': |
| 519 | + cr_iMarkup(p, KIND_SUBSCRIPT); |
| 520 | + break; |
| 521 | + |
| 522 | + case '#': |
| 523 | + cr_iMarkup(p, KIND_MONOSPACED); |
| 524 | + break; |
| 525 | + |
| 526 | + case '\\': |
| 527 | + cr_iMarkup(p, KIND_BREAK); |
| 528 | + break; |
| 529 | + |
| 530 | + case '{': |
| 531 | + if (cr_isEsc(p)) break; |
| 532 | + if (cr_iNoWiki(p)) break; |
| 533 | + if (cr_iImage(p)) break; |
| 534 | + blob_append(p->iblob, p->icursor, 1); |
| 535 | + p->icursor += 1; |
| 536 | + break; |
| 537 | + |
| 538 | + case '[': |
| 539 | + if (cr_isEsc(p)) break; |
| 540 | + if (cr_iLink(p)) break; |
| 541 | + blob_append(p->iblob, p->icursor, 1); |
| 542 | + p->icursor += 1; |
| 543 | + break; |
| 544 | + |
| 545 | + |
| 546 | + case '<': |
| 547 | + if (cr_isEsc(p)) break; |
| 548 | + if (cr_iMacro(p)) break; |
| 549 | + |
| 550 | + blob_append(p->iblob, "<", 4); |
| 551 | + p->icursor += 1; |
| 552 | + break; |
| 553 | + |
| 554 | + case '>': |
| 555 | + if (p->iesc) { |
| 556 | + blob_append(p->iblob, "~", 1); |
| 557 | + p->iesc = 0; |
| 558 | + } |
| 559 | + blob_append(p->iblob, ">", 4); |
| 560 | + p->icursor += 1; |
| 561 | + break; |
| 562 | + |
| 563 | + case '&': |
| 564 | + if (p->iesc) { |
| 565 | + blob_append(p->iblob, "~", 1); |
| 566 | + p->iesc = 0; |
| 567 | + } |
| 568 | + blob_append(p->iblob, "&", 5); |
| 569 | + p->icursor += 1; |
| 570 | + break; |
| 571 | + |
| 572 | + case '|': |
| 573 | + if (p->inTable){ |
| 574 | + if (p->iesc) { |
| 575 | + blob_append(p->iblob, p->icursor, 1); |
| 576 | + p->iesc = 0; |
| 577 | + p->icursor += 1; |
| 578 | + break; |
| 579 | + } |
| 580 | + eof = p->icursor + 1; |
| 581 | + break; |
| 582 | + } |
| 583 | + // fall through to default |
| 584 | + |
| 585 | + default: |
| 586 | + if (p->iesc) { |
| 587 | + blob_append(p->iblob, "~", 1); |
| 588 | + p->iesc = 0; |
| 589 | + } |
| 590 | + blob_append(p->iblob, p->icursor, 1); |
| 591 | + p->icursor +=1; |
| 592 | + }//}}} |
| 593 | + |
| 594 | + } |
| 595 | + |
| 596 | + while (p->istack){ |
| 597 | + cr_iClose(p, p->istack->kind); |
| 598 | + p->istack = p->istack->next; |
| 599 | + } |
| 600 | + |
| 601 | + p->iesc = save_iesc; |
| 602 | + p->iend = save_iend; |
| 603 | + p->istack = save_istack; |
| 604 | + |
| 605 | + return eof; |
| 605 | 606 | |
| 606 | 607 | } |
| 607 | 608 | //}}} |
| 608 | 609 | //}}} |
| 609 | 610 | |
| | @@ -610,472 +611,455 @@ |
| 610 | 611 | //{{{ BLOCK PARSER |
| 611 | 612 | |
| 612 | 613 | static void cr_renderListItem(Parser *p, Node *n){//{{{ |
| 613 | 614 | |
| 614 | 615 | |
| 615 | | - blob_append(p->iblob, "<li>", 4); |
| 616 | | - cr_parseInline(p, n->start, n->end); |
| 617 | | - |
| 618 | | - if (n->children){ |
| 619 | | - |
| 620 | | - int ord = (n->children->kind & KIND_ORDERED_LIST); |
| 621 | | - |
| 622 | | - if (ord) blob_append(p->iblob, "<ol>", 4); |
| 623 | | - else blob_append(p->iblob, "<ul>", 4); |
| 624 | | - |
| 625 | | - n = n->children; |
| 626 | | - while (n){ |
| 627 | | - cr_renderListItem(p, n); |
| 628 | | - n = n->next; |
| 629 | | - } |
| 630 | | - |
| 631 | | - if (ord) blob_append(p->iblob, "</ol>", 5); |
| 632 | | - else blob_append(p->iblob, "</ul>", 5); |
| 633 | | - } |
| 634 | | - blob_append(p->iblob, "</li>", 5); |
| 616 | + blob_append(p->iblob, "<li>", 4); |
| 617 | + cr_parseInline(p, n->start, n->end); |
| 618 | + |
| 619 | + if (n->children){ |
| 620 | + |
| 621 | + int ord = (n->children->kind & KIND_ORDERED_LIST); |
| 622 | + |
| 623 | + if (ord) blob_append(p->iblob, "<ol>", 4); |
| 624 | + else blob_append(p->iblob, "<ul>", 4); |
| 625 | + |
| 626 | + n = n->children; |
| 627 | + while (n){ |
| 628 | + cr_renderListItem(p, n); |
| 629 | + n = n->next; |
| 630 | + } |
| 631 | + |
| 632 | + if (ord) blob_append(p->iblob, "</ol>", 5); |
| 633 | + else blob_append(p->iblob, "</ul>", 5); |
| 634 | + } |
| 635 | + blob_append(p->iblob, "</li>", 5); |
| 635 | 636 | } |
| 636 | 637 | //}}} |
| 637 | 638 | static void cr_renderList(Parser *p){//{{{ |
| 638 | 639 | |
| 639 | | - Node *n = p->list; |
| 640 | | - |
| 641 | | - while (n->parent !=n) n = n->parent; |
| 642 | | - |
| 643 | | - int ord = (n->kind & KIND_ORDERED_LIST); |
| 644 | | - |
| 645 | | - if (ord) blob_append(p->iblob, "\n\n<ol>", -1); |
| 646 | | - else blob_append(p->iblob, "\n\n<ul>", -1); |
| 647 | | - |
| 648 | | - while (n) { |
| 649 | | - cr_renderListItem(p, n); |
| 650 | | - n = n->next; |
| 651 | | - } |
| 652 | | - |
| 653 | | - if (ord) blob_append(p->iblob, "</ol>", 5); |
| 654 | | - else blob_append(p->iblob, "</ul>", 5); |
| 640 | + Node *n = p->list; |
| 641 | + |
| 642 | + while (n->parent !=n) n = n->parent; |
| 643 | + |
| 644 | + int ord = (n->kind & KIND_ORDERED_LIST); |
| 645 | + |
| 646 | + if (ord) blob_append(p->iblob, "\n\n<ol>", -1); |
| 647 | + else blob_append(p->iblob, "\n\n<ul>", -1); |
| 648 | + |
| 649 | + while (n) { |
| 650 | + cr_renderListItem(p, n); |
| 651 | + n = n->next; |
| 652 | + } |
| 653 | + |
| 654 | + if (ord) blob_append(p->iblob, "</ol>", 5); |
| 655 | + else blob_append(p->iblob, "</ul>", 5); |
| 655 | 656 | } |
| 656 | 657 | |
| 657 | 658 | //}}} |
| 658 | 659 | |
| 659 | 660 | static void cr_renderTableRow(Parser *p, Node *row){//{{{ |
| 660 | 661 | |
| 661 | | - char *s = row->start; |
| 662 | | - int th; |
| 663 | | - |
| 664 | | - blob_append(p->iblob, "\n<tr>", -1); |
| 665 | | - |
| 666 | | - while (s && s < row->end){ |
| 667 | | - |
| 668 | | - if ((th = *s == '=')) { |
| 669 | | - s++; |
| 670 | | - blob_append(p->iblob, "<th>", -1); |
| 671 | | - } |
| 672 | | - else { |
| 673 | | - blob_append(p->iblob, "<td>", -1); |
| 674 | | - } |
| 675 | | - |
| 676 | | - s = cr_parseInline(p, s, row->end); |
| 677 | | - |
| 678 | | - if (th) |
| 679 | | - blob_append(p->iblob, "</th>\n", -1); |
| 680 | | - else |
| 681 | | - blob_append(p->iblob, "</td>\n", -1); |
| 682 | | - |
| 683 | | - if (!s) break; |
| 684 | | - } |
| 685 | | - blob_append(p->iblob, "</tr>", 5); |
| 662 | + char *s = row->start; |
| 663 | + int th; |
| 664 | + |
| 665 | + blob_append(p->iblob, "\n<tr>", -1); |
| 666 | + |
| 667 | + while (s && s < row->end){ |
| 668 | + |
| 669 | + if ((th = *s == '=')) { |
| 670 | + s++; |
| 671 | + blob_append(p->iblob, "<th>", -1); |
| 672 | + } |
| 673 | + else { |
| 674 | + blob_append(p->iblob, "<td>", -1); |
| 675 | + } |
| 676 | + |
| 677 | + s = cr_parseInline(p, s, row->end); |
| 678 | + |
| 679 | + if (th) |
| 680 | + blob_append(p->iblob, "</th>\n", -1); |
| 681 | + else |
| 682 | + blob_append(p->iblob, "</td>\n", -1); |
| 683 | + |
| 684 | + if (!s) break; |
| 685 | + } |
| 686 | + blob_append(p->iblob, "</tr>", 5); |
| 686 | 687 | } |
| 687 | 688 | //}}} |
| 688 | 689 | static void cr_renderTable(Parser *p, Node *n){//{{{ |
| 689 | 690 | |
| 690 | | - Node *row = n->children; |
| 691 | | - |
| 692 | | - blob_append(p->iblob, "<table class='creoletable'>", -1); |
| 693 | | - p->inTable = 1; |
| 694 | | - while (row){ |
| 695 | | - |
| 696 | | - cr_renderTableRow(p, row); |
| 697 | | - row = row->next; |
| 698 | | - |
| 699 | | - } |
| 700 | | - blob_append(p->iblob, "</table>", -1); |
| 701 | | - p->inTable = 0; |
| 691 | + Node *row = n->children; |
| 692 | + |
| 693 | + blob_append(p->iblob, "<table class='creoletable'>", -1); |
| 694 | + p->inTable = 1; |
| 695 | + while (row){ |
| 696 | + |
| 697 | + cr_renderTableRow(p, row); |
| 698 | + row = row->next; |
| 699 | + |
| 700 | + } |
| 701 | + blob_append(p->iblob, "</table>", -1); |
| 702 | + p->inTable = 0; |
| 702 | 703 | |
| 703 | 704 | } |
| 704 | 705 | //}}} |
| 705 | 706 | |
| 706 | 707 | static void cr_render(Parser *p, Node *node){//{{{ |
| 707 | 708 | |
| 708 | | - if (node->kind & KIND_PARAGRAPH){ |
| 709 | | - blob_append(p->iblob, "\n<p>", -1); |
| 710 | | - cr_parseInline(p, node->start, node->end ); |
| 711 | | - blob_append(p->iblob, "</p>\n", -1 ); |
| 712 | | - } |
| 713 | | - |
| 714 | | - if (node->kind & KIND_HEADING){ |
| 715 | | - blob_appendf(p->iblob, |
| 716 | | - "\n<h%d %s>", |
| 717 | | - node->level, |
| 718 | | - (node->flags & FLAG_CENTER) ? " style='text-align:center;'" : "" |
| 719 | | - ); |
| 720 | | - cr_parseInline(p, node->start, node->end); |
| 721 | | - blob_appendf(p->iblob, "</h%d>\n", node->level ); |
| 722 | | - return; |
| 723 | | - } |
| 724 | | - |
| 725 | | - if (node->kind & KIND_HORIZONTAL_RULE){ |
| 726 | | - blob_append(p->iblob, "<hr />", -1); |
| 727 | | - return; |
| 728 | | - } |
| 729 | | - |
| 730 | | - if (node->kind & KIND_LIST){ |
| 731 | | - cr_renderList(p); |
| 732 | | - p->list = NULL; |
| 733 | | - return; |
| 734 | | - } |
| 735 | | - |
| 736 | | - if (node->kind & KIND_TABLE){ |
| 737 | | - cr_renderTable(p, node); |
| 738 | | - return; |
| 739 | | - } |
| 740 | | - |
| 741 | | - if (node->kind & KIND_NO_WIKI_BLOCK){ |
| 742 | | - blob_appendf(p->iblob, |
| 743 | | - "\n<blockquote style='background:oldlace'><pre>%s</pre></blockquote>\n", |
| 744 | | - htmlize( node->start, node->end - node->start) |
| 745 | | - ); |
| 746 | | - } |
| 709 | + if (node->kind & KIND_PARAGRAPH){ |
| 710 | + blob_append(p->iblob, "\n<p>", -1); |
| 711 | + cr_parseInline(p, node->start, node->end ); |
| 712 | + blob_append(p->iblob, "</p>\n", -1 ); |
| 713 | + } |
| 714 | + |
| 715 | + if (node->kind & KIND_HEADING){ |
| 716 | + blob_appendf(p->iblob, |
| 717 | + "\n<h%d %s>", |
| 718 | + node->level, |
| 719 | + (node->flags & FLAG_CENTER) ? " style='text-align:center;'" : "" |
| 720 | + ); |
| 721 | + cr_parseInline(p, node->start, node->end); |
| 722 | + blob_appendf(p->iblob, "</h%d>\n", node->level ); |
| 723 | + return; |
| 724 | + } |
| 725 | + |
| 726 | + if (node->kind & KIND_HORIZONTAL_RULE){ |
| 727 | + blob_append(p->iblob, "<hr />", -1); |
| 728 | + return; |
| 729 | + } |
| 730 | + |
| 731 | + if (node->kind & KIND_LIST){ |
| 732 | + cr_renderList(p); |
| 733 | + p->list = NULL; |
| 734 | + return; |
| 735 | + } |
| 736 | + |
| 737 | + if (node->kind & KIND_TABLE){ |
| 738 | + cr_renderTable(p, node); |
| 739 | + return; |
| 740 | + } |
| 741 | + |
| 742 | + if (node->kind & KIND_NO_WIKI_BLOCK){ |
| 743 | + blob_appendf(p->iblob, |
| 744 | + "\n<blockquote style='background:oldlace'><pre>%s</pre></blockquote>\n", |
| 745 | + htmlize( node->start, node->end - node->start) |
| 746 | + ); |
| 747 | + } |
| 747 | 748 | } |
| 748 | 749 | //}}} |
| 749 | 750 | |
| 750 | 751 | static char *cr_findEndOfBlock(Parser *p, char *s, char c){//{{{ |
| 751 | 752 | |
| 752 | | - char *end; |
| 753 | | - while (s[0]){ |
| 754 | | - |
| 755 | | - end = s; |
| 756 | | - if (s[0] == c && s[0] == c && s[0] == c) { |
| 757 | | - s = cr_nextLine(p, s + 3); |
| 758 | | - if (p->lineWasBlank) { |
| 759 | | - p->cursor = s; |
| 760 | | - return end; |
| 761 | | - } |
| 762 | | - } |
| 763 | | - else { |
| 764 | | - s = cr_nextLine(p, s); |
| 765 | | - } |
| 766 | | - } |
| 767 | | - return 0; |
| 753 | + char *end; |
| 754 | + while (s[0]){ |
| 755 | + |
| 756 | + end = s; |
| 757 | + if (s[0] == c && s[0] == c && s[0] == c) { |
| 758 | + s = cr_nextLine(p, s + 3); |
| 759 | + if (p->lineWasBlank) { |
| 760 | + p->cursor = s; |
| 761 | + return end; |
| 762 | + } |
| 763 | + } |
| 764 | + else { |
| 765 | + s = cr_nextLine(p, s); |
| 766 | + } |
| 767 | + } |
| 768 | + return 0; |
| 768 | 769 | } |
| 769 | 770 | //}}} |
| 770 | 771 | static int cr_addListItem(Parser *p, Node *n){//{{{ |
| 771 | 772 | |
| 772 | | - n->parent = n; |
| 773 | | - n->next = n->children = NULL; |
| 774 | | - |
| 775 | | - if (!p->list) { |
| 776 | | - if (n->level != 1) return 0; |
| 777 | | - p->list = n; |
| 778 | | - return 1; |
| 779 | | - } |
| 780 | | - |
| 781 | | - Node *list = p->list; |
| 782 | | - |
| 783 | | - while (n->level < list->level){ |
| 784 | | - list = list->parent; |
| 785 | | - } |
| 786 | | - |
| 787 | | - if (n->level == list->level){ |
| 788 | | - |
| 789 | | - if (n->kind != list->kind){ |
| 790 | | - if (n->level>1) return 0; |
| 791 | | - cr_renderList(p); |
| 792 | | - p->list = n; |
| 793 | | - return 1; |
| 794 | | - } |
| 795 | | - n->parent = list->parent; |
| 796 | | - p->list = list->next = n; |
| 797 | | - return 1; |
| 798 | | - } |
| 799 | | - |
| 800 | | - if ( (n->level - list->level) > 1 ) return 0; |
| 801 | | - n->parent = p->list; |
| 802 | | - p->list->children = n; |
| 803 | | - p->list = n; |
| 804 | | - return 1; |
| 773 | + n->parent = n; |
| 774 | + n->next = n->children = NULL; |
| 775 | + |
| 776 | + if (!p->list) { |
| 777 | + if (n->level != 1) return 0; |
| 778 | + p->list = n; |
| 779 | + return 1; |
| 780 | + } |
| 781 | + |
| 782 | + Node *list = p->list; |
| 783 | + |
| 784 | + while (n->level < list->level){ |
| 785 | + list = list->parent; |
| 786 | + } |
| 787 | + |
| 788 | + if (n->level == list->level){ |
| 789 | + |
| 790 | + if (n->kind != list->kind){ |
| 791 | + if (n->level>1) return 0; |
| 792 | + cr_renderList(p); |
| 793 | + p->list = n; |
| 794 | + return 1; |
| 795 | + } |
| 796 | + n->parent = list->parent; |
| 797 | + p->list = list->next = n; |
| 798 | + return 1; |
| 799 | + } |
| 800 | + |
| 801 | + if ( (n->level - list->level) > 1 ) return 0; |
| 802 | + n->parent = p->list; |
| 803 | + p->list->children = n; |
| 804 | + p->list = n; |
| 805 | + return 1; |
| 805 | 806 | |
| 806 | 807 | } |
| 807 | 808 | //}}} |
| 808 | 809 | |
| 809 | 810 | static int isEndWikiMarker(Parser *p){//{{{ |
| 810 | 811 | |
| 811 | | - char *s = p->cursor; |
| 812 | | - if (memcmp(s, "<<fossil>>", 10)) return 0; |
| 813 | | - p->this->start = s; |
| 814 | | - p->this->kind = KIND_END_WIKI_MARKER; |
| 815 | | - p->cursor += 10; |
| 816 | | - return 1; |
| 812 | + char *s = p->cursor; |
| 813 | + if (memcmp(s, "<<fossil>>", 10)) return 0; |
| 814 | + p->this->start = s; |
| 815 | + p->this->kind = KIND_END_WIKI_MARKER; |
| 816 | + p->cursor += 10; |
| 817 | + return 1; |
| 817 | 818 | } |
| 818 | 819 | ///}}} |
| 819 | 820 | static int isNoWikiBlock(Parser *p){//{{{ |
| 820 | 821 | |
| 821 | | - char *s = p->cursor; |
| 822 | | - |
| 823 | | - if (s[0] != '{') return 0; s++; |
| 824 | | - if (s[0] != '{') return 0; s++; |
| 825 | | - if (s[0] != '{') return 0; s++; |
| 826 | | - |
| 827 | | - s = cr_nextLine(p, s); |
| 828 | | - if (!p->lineWasBlank) return 0; |
| 829 | | - |
| 830 | | - p->this->start = s; |
| 831 | | - |
| 832 | | - s = cr_findEndOfBlock(p, s, '}'); |
| 833 | | - |
| 834 | | - if (!s) return 0; |
| 835 | | - |
| 836 | | - // p->cursor was set by findEndOfBlock |
| 837 | | - p->this->kind = KIND_NO_WIKI_BLOCK; |
| 838 | | - p->this->end = s; |
| 839 | | - return 1; |
| 822 | + char *s = p->cursor; |
| 823 | + |
| 824 | + if (s[0] != '{') return 0; s++; |
| 825 | + if (s[0] != '{') return 0; s++; |
| 826 | + if (s[0] != '{') return 0; s++; |
| 827 | + |
| 828 | + s = cr_nextLine(p, s); |
| 829 | + if (!p->lineWasBlank) return 0; |
| 830 | + |
| 831 | + p->this->start = s; |
| 832 | + |
| 833 | + s = cr_findEndOfBlock(p, s, '}'); |
| 834 | + |
| 835 | + if (!s) return 0; |
| 836 | + |
| 837 | + // p->cursor was set by findEndOfBlock |
| 838 | + p->this->kind = KIND_NO_WIKI_BLOCK; |
| 839 | + p->this->end = s; |
| 840 | + return 1; |
| 840 | 841 | } |
| 841 | 842 | |
| 842 | 843 | //}}} |
| 843 | 844 | static int isParaBreak(Parser *p){//{{{ |
| 844 | 845 | |
| 845 | | - char *s = cr_nextLine(p, p->cursor); |
| 846 | | - if (!p->lineWasBlank) return 0; |
| 846 | + char *s = cr_nextLine(p, p->cursor); |
| 847 | + if (!p->lineWasBlank) return 0; |
| 847 | 848 | |
| 848 | | - p->cursor = s; |
| 849 | | - p->this->kind = KIND_PARA_BREAK; |
| 850 | | - return 1; |
| 849 | + p->cursor = s; |
| 850 | + p->this->kind = KIND_PARA_BREAK; |
| 851 | + return 1; |
| 851 | 852 | } |
| 852 | 853 | //}}} |
| 853 | 854 | static int isHeading(Parser *p){//{{{ |
| 854 | 855 | |
| 855 | | - char *s = cr_skipBlanks(p, p->cursor); |
| 856 | | - |
| 857 | | - int flags = 0; |
| 858 | | - int level = cr_countChars(p, s, '='); |
| 859 | | - if (!level) return 0; |
| 860 | | - |
| 861 | | - s += level; |
| 862 | | - |
| 863 | | - if (s[0] == '<' && s[1] == '>') { |
| 864 | | - flags |= FLAG_CENTER; |
| 865 | | - s += 2; |
| 866 | | - } |
| 867 | | - s = cr_skipBlanks(p, s); |
| 868 | | - |
| 869 | | - p->this->start = s; |
| 870 | | - |
| 871 | | - s = cr_nextLine(p, s); |
| 872 | | - char *z = s; |
| 873 | | - |
| 874 | | - if (s[-1] == '\n') s--; |
| 875 | | - while(s[-1] == ' ' || s[-1]=='\t') s--; |
| 876 | | - while(s[-1] == '=' ) s--; |
| 877 | | - if (p->this->start < s){ |
| 878 | | - p->cursor = z; |
| 879 | | - p->this->kind = KIND_HEADING; |
| 880 | | - p->this->end = s; |
| 881 | | - p->this->level = level; |
| 882 | | - p->this->flags |= flags; |
| 883 | | - return 1; |
| 884 | | - } |
| 885 | | - return 0; |
| 856 | + char *s = cr_skipBlanks(p, p->cursor); |
| 857 | + |
| 858 | + int flags = 0; |
| 859 | + int level = cr_countChars(p, s, '='); |
| 860 | + if (!level) return 0; |
| 861 | + |
| 862 | + s += level; |
| 863 | + |
| 864 | + if (s[0] == '<' && s[1] == '>') { |
| 865 | + flags |= FLAG_CENTER; |
| 866 | + s += 2; |
| 867 | + } |
| 868 | + s = cr_skipBlanks(p, s); |
| 869 | + |
| 870 | + p->this->start = s; |
| 871 | + |
| 872 | + s = cr_nextLine(p, s); |
| 873 | + char *z = s; |
| 874 | + |
| 875 | + if (s[-1] == '\n') s--; |
| 876 | + while(s[-1] == ' ' || s[-1]=='\t') s--; |
| 877 | + while(s[-1] == '=' ) s--; |
| 878 | + if (p->this->start < s){ |
| 879 | + p->cursor = z; |
| 880 | + p->this->kind = KIND_HEADING; |
| 881 | + p->this->end = s; |
| 882 | + p->this->level = level; |
| 883 | + p->this->flags |= flags; |
| 884 | + return 1; |
| 885 | + } |
| 886 | + return 0; |
| 886 | 887 | } |
| 887 | 888 | //}}} |
| 888 | 889 | static int isHorizontalRule(Parser *p){//{{{ |
| 889 | 890 | |
| 890 | | - char *s = cr_skipBlanks(p, p->cursor); |
| 891 | | - |
| 892 | | - int level = cr_countChars(p, s, '-'); |
| 893 | | - |
| 894 | | - if (level < 4) return 0; |
| 895 | | - s = cr_nextLine(p, s + level); |
| 896 | | - if (!p->lineWasBlank) return 0; |
| 897 | | - |
| 898 | | - p->cursor = s; |
| 899 | | - p->this->kind = KIND_HORIZONTAL_RULE; |
| 900 | | - |
| 901 | | - return 1; |
| 891 | + char *s = cr_skipBlanks(p, p->cursor); |
| 892 | + |
| 893 | + int level = cr_countChars(p, s, '-'); |
| 894 | + |
| 895 | + if (level < 4) return 0; |
| 896 | + s = cr_nextLine(p, s + level); |
| 897 | + if (!p->lineWasBlank) return 0; |
| 898 | + |
| 899 | + p->cursor = s; |
| 900 | + p->this->kind = KIND_HORIZONTAL_RULE; |
| 901 | + |
| 902 | + return 1; |
| 902 | 903 | } |
| 903 | 904 | //}}} |
| 904 | 905 | static int isListItem(Parser *p){//{{{ |
| 905 | 906 | |
| 906 | | - char *s = cr_skipBlanks(p, p->cursor); |
| 907 | | - |
| 908 | | - int level = cr_countChars(p, s, '#'); |
| 909 | | - if (!level) level = cr_countChars(p, s, '*'); |
| 910 | | - |
| 911 | | - if ( !level) return 0; |
| 912 | | - |
| 913 | | - p->this->kind = (s[0] == '#') ? KIND_ORDERED_LIST : KIND_UNORDERED_LIST; |
| 914 | | - p->this->level = level; |
| 915 | | - |
| 916 | | - s = cr_skipBlanks(p, s + level); |
| 917 | | - p->this->start = s; |
| 918 | | - |
| 919 | | - s = cr_nextLine(p, s); |
| 920 | | - if (p->lineWasBlank) return 0; |
| 921 | | - |
| 922 | | - if (cr_addListItem(p, p->this)){ |
| 923 | | - p->cursor = p->this->end = s; |
| 924 | | - return 1; |
| 925 | | - } |
| 926 | | - p->this->kind = 0; |
| 927 | | - return 0; |
| 907 | + char *s = cr_skipBlanks(p, p->cursor); |
| 908 | + |
| 909 | + int level = cr_countChars(p, s, '#'); |
| 910 | + if (!level) level = cr_countChars(p, s, '*'); |
| 911 | + |
| 912 | + if ( !level) return 0; |
| 913 | + |
| 914 | + p->this->kind = (s[0] == '#') ? KIND_ORDERED_LIST : KIND_UNORDERED_LIST; |
| 915 | + p->this->level = level; |
| 916 | + |
| 917 | + s = cr_skipBlanks(p, s + level); |
| 918 | + p->this->start = s; |
| 919 | + |
| 920 | + s = cr_nextLine(p, s); |
| 921 | + if (p->lineWasBlank) return 0; |
| 922 | + |
| 923 | + if (cr_addListItem(p, p->this)){ |
| 924 | + p->cursor = p->this->end = s; |
| 925 | + return 1; |
| 926 | + } |
| 927 | + p->this->kind = 0; |
| 928 | + return 0; |
| 928 | 929 | } |
| 929 | 930 | //}}} |
| 930 | 931 | static int isTable(Parser *p){//{{{ |
| 931 | 932 | |
| 932 | | - p->this->start = p->cursor; |
| 933 | | - char *s = cr_skipBlanks(p, p->cursor); |
| 934 | | - if (s[0] != '|') return 0; |
| 933 | + p->this->start = p->cursor; |
| 934 | + char *s = cr_skipBlanks(p, p->cursor); |
| 935 | + if (s[0] != '|') return 0; |
| 935 | 936 | s +=1; |
| 936 | | - p->this->kind = KIND_TABLE; |
| 937 | | - |
| 938 | | - |
| 939 | | - //p->cursor = p->this->end = cr_nextLine(p, s); |
| 940 | | - Node *row; |
| 941 | | - Node *tail = NULL; |
| 942 | | - |
| 943 | | - while (1) { |
| 944 | | - |
| 945 | | - row = pool_new(p); |
| 946 | | - row->kind = KIND_TABLE_ROW; |
| 947 | | - |
| 948 | | - if (tail) tail = tail->next = row; |
| 949 | | - else p->this->children = tail = row; |
| 950 | | - |
| 951 | | - row->start = s; |
| 952 | | - p->cursor = s = row->end = p->this->end = cr_nextLine(p, s); |
| 953 | | - |
| 954 | | - if (row->end[-1] == '\n') row->end -= 1; |
| 955 | | - while(row->end[-1] == ' ' ) row->end -= 1; |
| 956 | | - if (row->end[-1] == '|') row->end -= 1; |
| 957 | | - |
| 958 | | - if (!*s) break; |
| 959 | | - |
| 960 | | - // blanks *not* normalized |
| 961 | | - s = cr_skipBlanks(p, p->cursor); |
| 962 | | - if (s[0] != '|') break; |
| 963 | | - s++; |
| 964 | | - |
| 965 | | - } |
| 966 | | - return 1; |
| 937 | + p->this->kind = KIND_TABLE; |
| 938 | + |
| 939 | + |
| 940 | + //p->cursor = p->this->end = cr_nextLine(p, s); |
| 941 | + Node *row; |
| 942 | + Node *tail = NULL; |
| 943 | + |
| 944 | + while (1) { |
| 945 | + |
| 946 | + row = pool_new(p); |
| 947 | + row->kind = KIND_TABLE_ROW; |
| 948 | + |
| 949 | + if (tail) tail = tail->next = row; |
| 950 | + else p->this->children = tail = row; |
| 951 | + |
| 952 | + row->start = s; |
| 953 | + p->cursor = s = row->end = p->this->end = cr_nextLine(p, s); |
| 954 | + |
| 955 | + if (row->end[-1] == '\n') row->end -= 1; |
| 956 | + while(row->end[-1] == ' ' ) row->end -= 1; |
| 957 | + if (row->end[-1] == '|') row->end -= 1; |
| 958 | + |
| 959 | + if (!*s) break; |
| 960 | + |
| 961 | + // blanks *not* normalized |
| 962 | + s = cr_skipBlanks(p, p->cursor); |
| 963 | + if (s[0] != '|') break; |
| 964 | + s++; |
| 965 | + |
| 966 | + } |
| 967 | + return 1; |
| 967 | 968 | |
| 968 | 969 | }; |
| 969 | 970 | //}}} |
| 970 | 971 | static int isParagraph(Parser *p){//{{{ |
| 971 | 972 | |
| 972 | | - char *s = p->cursor; |
| 973 | | - p->this->start = s; |
| 974 | | - |
| 975 | | - s = cr_nextLine(p, s); |
| 976 | | - p->cursor = p->this->end = s; |
| 977 | | - p->this->kind = KIND_PARAGRAPH; |
| 978 | | - return 1; |
| 979 | | - |
| 980 | | -} |
| 981 | | -//}}} |
| 982 | | -static void cr_parse(Parser *p, char* z){//{{{ |
| 983 | | - |
| 984 | | - p->previous = pool_new(p); |
| 985 | | - p->previous->kind = KIND_PARA_BREAK; |
| 986 | | - |
| 987 | | - p->this = pool_new(p); |
| 988 | | - p->this->kind = KIND_PARA_BREAK; |
| 989 | | - |
| 990 | | - p->inLink = 0; |
| 991 | | - p->inTable = 0; |
| 992 | | - |
| 993 | | - p->cursor = z; |
| 994 | | - p->list = NULL; |
| 995 | | - p->istack = NULL; |
| 996 | | - |
| 997 | | - while (p->cursor[0]) { |
| 998 | | - |
| 999 | | - while (1){ |
| 1000 | | - |
| 1001 | | - // must be first |
| 1002 | | - if (isNoWikiBlock(p)) break; |
| 1003 | | - if (isParaBreak(p)) break; |
| 1004 | | - |
| 1005 | | - // order not important |
| 1006 | | - if (isHeading(p)) break; |
| 1007 | | - if (isHorizontalRule(p)) break; |
| 1008 | | - if (isListItem(p)) break; |
| 1009 | | - if (isTable(p)) break; |
| 1010 | | - |
| 1011 | | - // here for efficiency? |
| 1012 | | - if (isEndWikiMarker(p)) break; |
| 1013 | | - |
| 1014 | | - // must be last |
| 1015 | | - if (isParagraph(p)); break; |
| 1016 | | - |
| 1017 | | - // doh! |
| 1018 | | - assert(0); |
| 1019 | | - } |
| 1020 | | - |
| 1021 | | - int kind = p->this->kind; |
| 1022 | | - int prev = p->previous->kind; |
| 1023 | | - |
| 1024 | | - if (kind & KIND_END_WIKI_MARKER) return; |
| 1025 | | - |
| 1026 | | - if (kind == KIND_PARAGRAPH && prev & KIND_LIST_OR_PARAGRAPH) { |
| 1027 | | - p->previous->end = p->this->end; |
| 1028 | | - p->this = pool_new(p); |
| 1029 | | - continue; |
| 1030 | | - } |
| 1031 | | - |
| 1032 | | - if ( !(kind & KIND_LIST && prev & KIND_LIST) ) |
| 1033 | | - cr_render(p, p->previous); |
| 1034 | | - |
| 1035 | | - p->previous = p->this; |
| 1036 | | - p->this = pool_new(p); |
| 1037 | | - |
| 1038 | | - } |
| 1039 | | -} |
| 1040 | | -//}}} |
| 1041 | | - |
| 1042 | | -//}}} |
| 1043 | | - |
| 1044 | | -char *wiki_render_creole(Renderer *r, char *z){//{{{ |
| 1045 | | - |
| 1046 | | - Parser parser; |
| 1047 | | - Parser *p = &parser; |
| 1048 | | - |
| 1049 | | - p->r = r; |
| 1050 | | - p->iblob = r->pOut; |
| 1051 | | - |
| 1052 | | - p->nFree = 0; |
| 1053 | | - p->pool = NULL; |
| 1054 | | - |
| 1055 | | - cr_parse(p, z); |
| 1056 | | - |
| 1057 | | - cr_render(p, p->previous); |
| 1058 | | - |
| 1059 | | - pool_free(p); |
| 1060 | | - |
| 1061 | | - return p->cursor; |
| 1062 | | - |
| 1063 | | -} |
| 1064 | | -//}}} |
| 1065 | | - |
| 1066 | | - |
| 1067 | | -char *wiki_render_macro(Renderer *p, char *z, int *tokenType){ |
| 1068 | | - if (!memcmp(z, "<<fossil>>", 9)){ |
| 1069 | | - *tokenType = 1; |
| 1070 | | - return z + 10; |
| 1071 | | - } |
| 1072 | | - if (memcmp(z, "<<creole>>", 9)) { |
| 1073 | | - *tokenType = 0; |
| 1074 | | - return z; |
| 1075 | | - } |
| 1076 | | - *tokenType = 1; |
| 1077 | | - return wiki_render_creole(p, z+10); |
| 1078 | | - |
| 1079 | | -} |
| 1080 | | - |
| 1081 | | -/* :folding=explicit:collapseFolds=1:tabSize=2:indentSize=2:noTabs=false: */ |
| 973 | + char *s = p->cursor; |
| 974 | + p->this->start = s; |
| 975 | + |
| 976 | + s = cr_nextLine(p, s); |
| 977 | + p->cursor = p->this->end = s; |
| 978 | + p->this->kind = KIND_PARAGRAPH; |
| 979 | + return 1; |
| 980 | + |
| 981 | +} |
| 982 | +//}}} |
| 983 | +static void cr_parse(Parser *p, char* z){//{{{ |
| 984 | + |
| 985 | + p->previous = pool_new(p); |
| 986 | + p->previous->kind = KIND_PARA_BREAK; |
| 987 | + |
| 988 | + p->this = pool_new(p); |
| 989 | + p->this->kind = KIND_PARA_BREAK; |
| 990 | + |
| 991 | + p->inLink = 0; |
| 992 | + p->inTable = 0; |
| 993 | + |
| 994 | + p->cursor = z; |
| 995 | + p->list = NULL; |
| 996 | + p->istack = NULL; |
| 997 | + |
| 998 | + while (p->cursor[0]) { |
| 999 | + |
| 1000 | + while (1){ |
| 1001 | + |
| 1002 | + // must be first |
| 1003 | + if (isNoWikiBlock(p)) break; |
| 1004 | + if (isParaBreak(p)) break; |
| 1005 | + |
| 1006 | + // order not important |
| 1007 | + if (isHeading(p)) break; |
| 1008 | + if (isHorizontalRule(p)) break; |
| 1009 | + if (isListItem(p)) break; |
| 1010 | + if (isTable(p)) break; |
| 1011 | + |
| 1012 | + // here for efficiency? |
| 1013 | + if (isEndWikiMarker(p)) break; |
| 1014 | + |
| 1015 | + // must be last |
| 1016 | + if (isParagraph(p)); break; |
| 1017 | + |
| 1018 | + // doh! |
| 1019 | + assert(0); |
| 1020 | + } |
| 1021 | + |
| 1022 | + int kind = p->this->kind; |
| 1023 | + int prev = p->previous->kind; |
| 1024 | + |
| 1025 | + if (kind & KIND_END_WIKI_MARKER) return; |
| 1026 | + |
| 1027 | + if (kind == KIND_PARAGRAPH && prev & KIND_LIST_OR_PARAGRAPH) { |
| 1028 | + p->previous->end = p->this->end; |
| 1029 | + p->this = pool_new(p); |
| 1030 | + continue; |
| 1031 | + } |
| 1032 | + |
| 1033 | + if ( !(kind & KIND_LIST && prev & KIND_LIST) ) |
| 1034 | + cr_render(p, p->previous); |
| 1035 | + |
| 1036 | + p->previous = p->this; |
| 1037 | + p->this = pool_new(p); |
| 1038 | + |
| 1039 | + } |
| 1040 | +} |
| 1041 | +//}}} |
| 1042 | + |
| 1043 | +//}}} |
| 1044 | + |
| 1045 | +char *wiki_render_creole(Renderer *r, char *z){ |
| 1046 | + |
| 1047 | + Parser parser; |
| 1048 | + Parser *p = &parser; |
| 1049 | + |
| 1050 | + p->r = r; |
| 1051 | + p->iblob = r->pOut; |
| 1052 | + |
| 1053 | + p->nFree = 0; |
| 1054 | + p->pool = NULL; |
| 1055 | + |
| 1056 | + cr_parse(p, z); |
| 1057 | + |
| 1058 | + cr_render(p, p->previous); |
| 1059 | + |
| 1060 | + pool_free(p); |
| 1061 | + |
| 1062 | + return p->cursor; |
| 1063 | + |
| 1064 | +} |
| 1065 | + |
| 1082 | 1066 | |