[gmime: 1/10] GMimeFilterHtml: add option to enclose citation in blockquotes
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime: 1/10] GMimeFilterHtml: add option to enclose citation in blockquotes
- Date: Fri, 17 Feb 2017 20:04:15 +0000 (UTC)
commit 56367080553d236cae392f0ded976325e841e661
Author: Gaute Hope <eg gaute vetsj com>
Date: Wed Apr 20 10:37:27 2016 +0200
GMimeFilterHtml: add option to enclose citation in blockquotes
The option GMIME_FILTER_HTML_BLOCKQUOTE_CITATION encloses citations in
blockquotes. This allows for easier customization using CSS of the
resulting HTML.
Each blockquote is not closed untill the citation depth level is closed,
all blockquotes are closed at the end.
GMIME_FILTER_HTML_MARK_CITATION is disabled when
GMIME_FILTER_HTML_BLOCKQUOTE_CITATION is enabled.
gmime/gmime-filter-html.c | 60 ++++++++++++++++++++++++++++++++++++++++++--
gmime/gmime-filter-html.h | 25 ++++++++++++------
2 files changed, 74 insertions(+), 11 deletions(-)
---
diff --git a/gmime/gmime-filter-html.c b/gmime/gmime-filter-html.c
index edb4615..098d032 100644
--- a/gmime/gmime-filter-html.c
+++ b/gmime/gmime-filter-html.c
@@ -140,6 +140,7 @@ g_mime_filter_html_init (GMimeFilterHTML *filter, GMimeFilterHTMLClass *klass)
filter->colour = 0;
filter->column = 0;
filter->pre_open = FALSE;
+ filter->prev_cit_depth = 0;
}
static void
@@ -351,10 +352,43 @@ html_convert (GMimeFilter *filter, char *in, size_t inlen, size_t prespace,
break;
html->column = 0;
- depth = 0;
+ depth = citation_depth (start, inend);
- if (html->flags & GMIME_FILTER_HTML_MARK_CITATION) {
- if ((depth = citation_depth (start, inend)) > 0) {
+ if (html->flags & GMIME_FILTER_HTML_BLOCKQUOTE_CITATION) {
+ if (html->prev_cit_depth < depth) {
+ while (html->prev_cit_depth < depth) {
+ html->prev_cit_depth++;
+
+ char bq[33];
+ int ldepth = html->prev_cit_depth > 999 ? 999 : html->prev_cit_depth;
+
+ g_snprintf (bq, 33, "<blockquote class=\"level_%03d\">", ldepth);
+
+ outptr = check_size (filter, outptr, &outend, 33);
+ outptr = g_stpcpy (outptr, bq);
+ }
+
+ /* remove '>' */
+ while (*start == '>' && start < inend) start++;
+
+ /* remove leading space */
+ if (*start == ' ' && start < inend) start++;
+
+
+ } else if (depth > 0) {
+ /* we are still at the same depth or lower: remove '>' */
+ while (*start == '>' && start < inend) start++;
+
+ /* remove leading space */
+ if (*start == ' ' && start < inend) start++;
+
+ } else if (*start == '>') {
+ /* >From line */
+ start++;
+ }
+
+ } else if (html->flags & GMIME_FILTER_HTML_MARK_CITATION) {
+ if (depth > 0) {
char font[25];
/* FIXME: we could easily support multiple colour depths here */
@@ -419,6 +453,15 @@ html_convert (GMimeFilter *filter, char *in, size_t inlen, size_t prespace,
} else {
outptr = writeln (filter, start, inptr, outptr, &outend);
}
+
+ if ((html->flags & GMIME_FILTER_HTML_BLOCKQUOTE_CITATION) &&
+ (depth < html->prev_cit_depth)) {
+ while (html->prev_cit_depth > depth) {
+ outptr = check_size (filter, outptr, &outend, 14);
+ outptr = g_stpcpy (outptr, "</blockquote>");
+ html->prev_cit_depth--;
+ }
+ }
if ((html->flags & GMIME_FILTER_HTML_MARK_CITATION) && depth > 0) {
outptr = check_size (filter, outptr, &outend, 8);
@@ -442,6 +485,16 @@ html_convert (GMimeFilter *filter, char *in, size_t inlen, size_t prespace,
outptr = check_size (filter, outptr, &outend, 10);
outptr = g_stpcpy (outptr, "</pre>");
}
+
+ if ((html->flags & GMIME_FILTER_HTML_BLOCKQUOTE_CITATION) &&
+ (html->prev_cit_depth > 0)) {
+ /* close open blockquotes */
+ while (html->prev_cit_depth > 0) {
+ outptr = check_size (filter, outptr, &outend, 14);
+ outptr = g_stpcpy (outptr, "</blockquote>");
+ html->prev_cit_depth--;
+ }
+ }
} else if (start < inend) {
/* backup */
g_mime_filter_backup (filter, start, (unsigned) (inend - start));
@@ -473,6 +526,7 @@ filter_reset (GMimeFilter *filter)
html->column = 0;
html->pre_open = FALSE;
+ html->prev_cit_depth = 0;
}
diff --git a/gmime/gmime-filter-html.h b/gmime/gmime-filter-html.h
index 4edf5d4..bbc000e 100644
--- a/gmime/gmime-filter-html.h
+++ b/gmime/gmime-filter-html.h
@@ -42,7 +42,7 @@ typedef struct _GMimeFilterHTMLClass GMimeFilterHTMLClass;
*
* Wrap stream in <pre> tags.
**/
-#define GMIME_FILTER_HTML_PRE (1 << 0)
+#define GMIME_FILTER_HTML_PRE (1 << 0)
/**
@@ -50,7 +50,7 @@ typedef struct _GMimeFilterHTMLClass GMimeFilterHTMLClass;
*
* Convert new-lines ('\n') into <br> tags.
**/
-#define GMIME_FILTER_HTML_CONVERT_NL (1 << 1)
+#define GMIME_FILTER_HTML_CONVERT_NL (1 << 1)
/**
@@ -59,7 +59,7 @@ typedef struct _GMimeFilterHTMLClass GMimeFilterHTMLClass;
* Preserve whitespace by converting spaces into their appropriate
* html entities.
**/
-#define GMIME_FILTER_HTML_CONVERT_SPACES (1 << 2)
+#define GMIME_FILTER_HTML_CONVERT_SPACES (1 << 2)
/**
@@ -67,7 +67,7 @@ typedef struct _GMimeFilterHTMLClass GMimeFilterHTMLClass;
*
* Wrap detected URLs in <a href=...> tags.
**/
-#define GMIME_FILTER_HTML_CONVERT_URLS (1 << 3)
+#define GMIME_FILTER_HTML_CONVERT_URLS (1 << 3)
/**
@@ -75,7 +75,7 @@ typedef struct _GMimeFilterHTMLClass GMimeFilterHTMLClass;
*
* Change the colour of citation text.
**/
-#define GMIME_FILTER_HTML_MARK_CITATION (1 << 4)
+#define GMIME_FILTER_HTML_MARK_CITATION (1 << 4)
/**
@@ -83,7 +83,7 @@ typedef struct _GMimeFilterHTMLClass GMimeFilterHTMLClass;
*
* Wrap email addresses in "mailto:" href tags.
**/
-#define GMIME_FILTER_HTML_CONVERT_ADDRESSES (1 << 5)
+#define GMIME_FILTER_HTML_CONVERT_ADDRESSES (1 << 5)
/**
@@ -91,7 +91,7 @@ typedef struct _GMimeFilterHTMLClass GMimeFilterHTMLClass;
*
* Converts 8bit characters to '?'.
**/
-#define GMIME_FILTER_HTML_ESCAPE_8BIT (1 << 6)
+#define GMIME_FILTER_HTML_ESCAPE_8BIT (1 << 6)
/**
@@ -99,7 +99,14 @@ typedef struct _GMimeFilterHTMLClass GMimeFilterHTMLClass;
*
* Cites text by prepending "> " to each cited line.
**/
-#define GMIME_FILTER_HTML_CITE (1 << 7)
+#define GMIME_FILTER_HTML_CITE (1 << 7)
+
+/**
+ * GMIME_FILTER_HTML_MARK_CITATION_BLOCKQUOTE:
+ *
+ * Enclose citation text in blockquotes.
+ **/
+#define GMIME_FILTER_HTML_BLOCKQUOTE_CITATION (1 << 8)
/**
@@ -110,6 +117,7 @@ typedef struct _GMimeFilterHTMLClass GMimeFilterHTMLClass;
* @colour: cite colour
* @column: current column
* @pre_open: currently inside of a 'pre' tag.
+ * @prev_cit_depth: current citation depth level.
*
* A filter for converting text/plain into text/html.
**/
@@ -123,6 +131,7 @@ struct _GMimeFilterHTML {
guint32 column : 31;
guint32 pre_open : 1;
+ guint32 prev_cit_depth : 31;
};
struct _GMimeFilterHTMLClass {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]