Revision 3252

View differences:

libsylph/html.c
211 211
	parser->empty_line = TRUE;
212 212
	parser->space = FALSE;
213 213
	parser->pre = FALSE;
214
	parser->blockquote = 0;
214 215

  
215 216
#define SYMBOL_TABLE_ADD(table, list) \
216 217
{ \
......
326 327
static void html_append_char(HTMLParser *parser, gchar ch)
327 328
{
328 329
	GString *str = parser->str;
330
	const gchar *bq_prefix = NULL;
329 331

  
330 332
	if (!parser->pre && parser->space) {
331 333
		g_string_append_c(str, ' ');
332 334
		parser->space = FALSE;
333 335
	}
334 336

  
335
	g_string_append_c(str, ch);
337
	if (parser->newline && parser->blockquote > 0)
338
		bq_prefix = "  ";
336 339

  
337 340
	parser->empty_line = FALSE;
338 341
	if (ch == '\n') {
339 342
		parser->newline = TRUE;
340
		if (str->len > 1 && str->str[str->len - 2] == '\n')
343
		if (str->len > 0 && str->str[str->len - 1] == '\n')
341 344
			parser->empty_line = TRUE;
342 345
	} else
343 346
		parser->newline = FALSE;
347

  
348
	if (bq_prefix) {
349
		gint i;
350
		for (i = 0; i < parser->blockquote; i++)
351
			g_string_append(str, bq_prefix);
352
	}
353
	g_string_append_c(str, ch);
344 354
}
345 355

  
346 356
static void html_append_str(HTMLParser *parser, const gchar *str, gint len)
347 357
{
348 358
	GString *string = parser->str;
359
	const gchar *bq_prefix = NULL;
349 360

  
350 361
	if (!parser->pre && parser->space) {
351 362
		g_string_append_c(string, ' ');
......
353 364
	}
354 365

  
355 366
	if (len == 0) return;
367

  
368
	if (parser->newline && parser->blockquote > 0)
369
		bq_prefix = "  ";
370

  
371
	if (bq_prefix) {
372
		gint i;
373
		for (i = 0; i < parser->blockquote; i++)
374
			g_string_append(string, bq_prefix);
375
	}
376

  
356 377
	if (len < 0)
357 378
		g_string_append(string, str);
358 379
	else
......
555 576
	} else if (!strcmp(tag->name, "/pre")) {
556 577
		parser->pre = FALSE;
557 578
		parser->state = HTML_NORMAL;
579
	} else if (!strcmp(tag->name, "blockquote")) {
580
		parser->blockquote++;
581
		parser->state = HTML_BLOCKQUOTE;
582
	} else if (!strcmp(tag->name, "/blockquote")) {
583
		parser->blockquote--;
584
		if (parser->blockquote < 0)
585
			parser->blockquote = 0;
586
		parser->state = HTML_NORMAL;
558 587
	} else if (!strcmp(tag->name, "hr")) {
559 588
		if (!parser->newline) {
560 589
			parser->space = FALSE;
libsylph/html.h
38 38
	HTML_UNKNOWN,
39 39
	HTML_CONV_FAILED,
40 40
	HTML_ERR,
41
	HTML_EOF
41
	HTML_EOF,
42
	HTML_BLOCKQUOTE
42 43
} HTMLState;
43 44

  
44 45
typedef struct _HTMLParser	HTMLParser;
......
65 66
	gboolean empty_line;
66 67
	gboolean space;
67 68
	gboolean pre;
69
	gint blockquote;
68 70
};
69 71

  
70 72
struct _HTMLAttr

Also available in: Unified diff