Mercurial > pidgin
comparison src/html.c @ 5104:a20a644e0da4
[gaim-migrate @ 5467]
getting better...
gaim will ignore the <span> tags for now, until we can really make use of them
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Fri, 11 Apr 2003 00:52:02 +0000 |
| parents | a7e9036cd46f |
| children | b99910bfedd2 |
comparison
equal
deleted
inserted
replaced
| 5103:bfcf72c5a930 | 5104:a20a644e0da4 |
|---|---|
| 321 g_free(gunk); | 321 g_free(gunk); |
| 322 callback(data, g_strdup(_("g003: Error opening connection.\n")), 0); | 322 callback(data, g_strdup(_("g003: Error opening connection.\n")), 0); |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 | 325 |
| 326 struct gaim_parse_tag { | |
| 327 char *src_tag; | |
| 328 char *dest_tag; | |
| 329 }; | |
| 330 | |
| 326 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \ | 331 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \ |
| 327 char *o = strchr(c+1, '<'); \ | 332 char *o = strchr(c+1, '<'); \ |
| 328 char *p = strchr(c+1, '>'); \ | 333 char *p = strchr(c+1, '>'); \ |
| 329 if(p && (!o || p < o)) { \ | 334 if(p && (!o || p < o)) { \ |
| 330 if(*(p-1) != '/') \ | 335 if(*(p-1) != '/') { \ |
| 331 tags = g_list_prepend(tags, y); \ | 336 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); \ |
| 337 pt->src_tag = x; \ | |
| 338 pt->dest_tag = y; \ | |
| 339 tags = g_list_prepend(tags, pt); \ | |
| 340 } \ | |
| 332 xhtml = g_string_append(xhtml, "<" y); \ | 341 xhtml = g_string_append(xhtml, "<" y); \ |
| 333 c += strlen("<" x ); \ | 342 c += strlen("<" x ); \ |
| 334 xhtml = g_string_append_len(xhtml, c, (p - c) + 1); \ | 343 xhtml = g_string_append_len(xhtml, c, (p - c) + 1); \ |
| 335 c = p + 1; \ | 344 c = p + 1; \ |
| 336 } else { \ | 345 } else { \ |
| 341 if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \ | 350 if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \ |
| 342 (*(c+strlen("<" x)) == '>' || \ | 351 (*(c+strlen("<" x)) == '>' || \ |
| 343 !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \ | 352 !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \ |
| 344 xhtml = g_string_append(xhtml, "<" y); \ | 353 xhtml = g_string_append(xhtml, "<" y); \ |
| 345 c += strlen("<" x); \ | 354 c += strlen("<" x); \ |
| 346 if(*c != '/') \ | 355 if(*c != '/') { \ |
| 347 tags = g_list_prepend(tags, y); \ | 356 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); \ |
| 357 pt->src_tag = x; \ | |
| 358 pt->dest_tag = y; \ | |
| 359 tags = g_list_prepend(tags, pt); \ | |
| 360 } \ | |
| 348 continue; \ | 361 continue; \ |
| 349 } | 362 } |
| 350 #define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x) | 363 #define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x) |
| 351 | 364 |
| 352 char *html_to_xhtml(const char *html) { | 365 char *html_to_xhtml(const char *html) { |
| 370 c++; | 383 c++; |
| 371 } else if(*c == '<') { | 384 } else if(*c == '<') { |
| 372 if(*(c+1) == '/') { /* closing tag */ | 385 if(*(c+1) == '/') { /* closing tag */ |
| 373 tag = tags; | 386 tag = tags; |
| 374 while(tag) { | 387 while(tag) { |
| 375 if(!g_ascii_strncasecmp((c+2), tag->data, strlen(tag->data)) && *(c+strlen(tag->data)+2) == '>') { | 388 struct gaim_parse_tag *pt = tag->data; |
| 376 c += strlen(tag->data) + 3; | 389 if(!g_ascii_strncasecmp((c+2), pt->src_tag, strlen(pt->src_tag)) && *(c+strlen(pt->src_tag)+2) == '>') { |
| 390 c += strlen(pt->src_tag) + 3; | |
| 377 break; | 391 break; |
| 378 } | 392 } |
| 379 tag = tag->next; | 393 tag = tag->next; |
| 380 } | 394 } |
| 381 if(tag) { | 395 if(tag) { |
| 382 while(tags) { | 396 while(tags) { |
| 383 g_string_append_printf(xhtml, "</%s>", (char *)tags->data); | 397 struct gaim_parse_tag *pt = tags->data; |
| 398 g_string_append_printf(xhtml, "</%s>", pt->dest_tag); | |
| 384 if(tags == tag) | 399 if(tags == tag) |
| 385 break; | 400 break; |
| 386 tags = g_list_remove(tags, tags->data); | 401 tags = g_list_remove(tags, pt); |
| 402 g_free(pt); | |
| 387 } | 403 } |
| 404 g_free(tag->data); | |
| 388 tags = g_list_remove(tags, tag->data); | 405 tags = g_list_remove(tags, tag->data); |
| 389 } else { | 406 } else { |
| 390 /* we tried to close a tag we never opened! escape it | 407 /* we tried to close a tag we never opened! escape it |
| 391 * and move on */ | 408 * and move on */ |
| 392 xhtml = g_string_append(xhtml, "<"); | 409 xhtml = g_string_append(xhtml, "<"); |
| 416 ALLOW_TAG("li"); | 433 ALLOW_TAG("li"); |
| 417 ALLOW_TAG("ol"); | 434 ALLOW_TAG("ol"); |
| 418 ALLOW_TAG("p"); | 435 ALLOW_TAG("p"); |
| 419 ALLOW_TAG("pre"); | 436 ALLOW_TAG("pre"); |
| 420 ALLOW_TAG("q"); | 437 ALLOW_TAG("q"); |
| 421 ALLOW_TAG_ALT("s", "strike"); /* FIXME: see strike */ | |
| 422 ALLOW_TAG("span"); | 438 ALLOW_TAG("span"); |
| 423 ALLOW_TAG("strike"); /* FIXME: not valid, need to convert */ | |
| 424 ALLOW_TAG("strong"); | 439 ALLOW_TAG("strong"); |
| 425 ALLOW_TAG("sub"); /* FIXME: not valid, need to convert */ | |
| 426 ALLOW_TAG("sup"); /* FIXME: not valid, need to convert */ | |
| 427 ALLOW_TAG("u"); /* FIXME: need to convert */ | |
| 428 ALLOW_TAG_ALT("underline","u"); /* FIXME: need to convert */ | |
| 429 ALLOW_TAG("ul"); | 440 ALLOW_TAG("ul"); |
| 430 | 441 |
| 442 if(!g_ascii_strncasecmp(c, "<u>", 2) || !g_ascii_strncasecmp(c, "<underline>", strlen("<underline>"))) { | |
| 443 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); | |
| 444 pt->src_tag = *(c+2) == '>' ? "u" : "underline"; | |
| 445 pt->dest_tag = "span"; | |
| 446 tags = g_list_prepend(tags, pt); | |
| 447 c = strchr(c, '>') + 1; | |
| 448 xhtml = g_string_append(xhtml, "<span style='text-decoration: underline;'>"); | |
| 449 continue; | |
| 450 } | |
| 451 if(!g_ascii_strncasecmp(c, "<s>", 2) || !g_ascii_strncasecmp(c, "<strike>", strlen("<strike>"))) { | |
| 452 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); | |
| 453 pt->src_tag = *(c+2) == '>' ? "s" : "strike"; | |
| 454 pt->dest_tag = "span"; | |
| 455 tags = g_list_prepend(tags, pt); | |
| 456 c = strchr(c, '>') + 1; | |
| 457 xhtml = g_string_append(xhtml, "<span style='text-decoration: line-through;'>"); | |
| 458 continue; | |
| 459 } | |
| 460 if(!g_ascii_strncasecmp(c, "<sub>", 5)) { | |
| 461 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); | |
| 462 pt->src_tag = "sub"; | |
| 463 pt->dest_tag = "span"; | |
| 464 tags = g_list_prepend(tags, pt); | |
| 465 c = strchr(c, '>') + 1; | |
| 466 xhtml = g_string_append(xhtml, "<span style='vertical-align:sub;'>"); | |
| 467 continue; | |
| 468 } | |
| 469 if(!g_ascii_strncasecmp(c, "<sup>", 5)) { | |
| 470 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); | |
| 471 pt->src_tag = "sup"; | |
| 472 pt->dest_tag = "span"; | |
| 473 tags = g_list_prepend(tags, pt); | |
| 474 c = strchr(c, '>') + 1; | |
| 475 xhtml = g_string_append(xhtml, "<span style='vertical-align:super;'>"); | |
| 476 continue; | |
| 477 } | |
| 431 if(!g_ascii_strncasecmp(c, "<!--", strlen("<!--"))) { | 478 if(!g_ascii_strncasecmp(c, "<!--", strlen("<!--"))) { |
| 432 char *p = strstr(c + strlen("<!--"), "-->"); | 479 char *p = strstr(c + strlen("<!--"), "-->"); |
| 433 if(p) { | 480 if(p) { |
| 434 xhtml = g_string_append(xhtml, "<!--"); | 481 xhtml = g_string_append(xhtml, "<!--"); |
| 435 c += strlen("<!--"); | 482 c += strlen("<!--"); |
