[gmime] Updated text/enriched filter to parse paraindent params
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Updated text/enriched filter to parse paraindent params
- Date: Wed, 20 Dec 2017 17:11:53 +0000 (UTC)
commit 12867372b93d82cedff557663a7dae10499d2f09
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date: Sat Dec 16 15:37:39 2017 -0500
Updated text/enriched filter to parse paraindent params
gmime/gmime-filter-enriched.c | 58 ++++++++++++++++++++++++++++++++++++-
tests/data/filters/enriched.html | 2 +-
tests/test-filters.c | 1 +
3 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/gmime/gmime-filter-enriched.c b/gmime/gmime-filter-enriched.c
index d3cb3b3..adf811e 100644
--- a/gmime/gmime-filter-enriched.c
+++ b/gmime/gmime-filter-enriched.c
@@ -193,10 +193,64 @@ enriched_tag_needs_param (const char *tag)
}
#endif
+typedef enum {
+ PARAINDENT_NONE = 0,
+ PARAINDENT_LEFT = (1 << 0),
+ PARAINDENT_RIGHT = (1 << 1),
+ PARAINDENT_IN = (1 << 2),
+ PARAINDENT_OUT = (1 << 3)
+} paraindent_t;
+
+static const char *valid_indents[] = {
+ "left", "right", "in", "out"
+};
+
static char *
-param_parse_paraindent (const char *inptr, size_t inlen)
+param_parse_paraindent (const char *in, size_t inlen)
{
- return g_strdup ("text-indent:40px");
+ const char *inend = in + inlen;
+ const char *inptr = in;
+ paraindent_t indent = 0;
+ GString *str;
+ guint i;
+
+ while (inptr < inend) {
+ const char *value = inptr;
+ size_t vlen;
+
+ while (inptr < inend && *inptr != ',')
+ inptr++;
+
+ vlen = inptr - value;
+
+ for (i = 0; i < G_N_ELEMENTS (valid_indents); i++) {
+ size_t n = strlen (valid_indents[i]);
+
+ if (vlen == n && !g_ascii_strncasecmp (value, valid_indents[i], n)) {
+ indent |= 1 << i;
+ break;
+ }
+ }
+
+ inptr++;
+ }
+
+ str = g_string_new ("");
+
+ /* if In and Out are both specified, they cancel each other out? */
+ if (indent & PARAINDENT_IN && indent & PARAINDENT_OUT)
+ indent = indent & ~(PARAINDENT_IN | PARAINDENT_OUT);
+
+ if (indent & PARAINDENT_LEFT)
+ g_string_append_printf (str, "%smargin-left:4em", str->len > 0 ? "; " : "");
+ if (indent & PARAINDENT_RIGHT)
+ g_string_append_printf (str, "%smargin-right:4em", str->len > 0 ? "; " : "");
+ if (indent & PARAINDENT_IN)
+ g_string_append_printf (str, "%smargin:4em", str->len > 0 ? "; " : "");
+ if (indent & PARAINDENT_OUT)
+ g_string_append_printf (str, "%smargin:-4em", str->len > 0 ? "; " : "");
+
+ return g_string_free (str, FALSE);
}
static const char *valid_colours[] = {
diff --git a/tests/data/filters/enriched.html b/tests/data/filters/enriched.html
index 8fd8d68..b869d41 100644
--- a/tests/data/filters/enriched.html
+++ b/tests/data/filters/enriched.html
@@ -1 +1 @@
-<b>Hello, <i>world!</i></b><br><font color="red">Blood</font> is <b>thicker</b> than <font
color="#0000FF">water</font>.<br><p style="text-indent:40px"><i>-- Well-known proverb </i></p>
\ No newline at end of file
+<b>Hello, <i>world!</i></b><br><font color="red">Blood</font> is <b>thicker</b> than <font
color="#0000FF">water</font>.<br><p style="margin-left:4em"><i>-- Well-known proverb </i></p>
\ No newline at end of file
diff --git a/tests/test-filters.c b/tests/test-filters.c
index 8423c69..d270fb7 100644
--- a/tests/test-filters.c
+++ b/tests/test-filters.c
@@ -184,6 +184,7 @@ test_enriched (const char *datadir, const char *input, const char *output)
if (actual->len != expected->len) {
testsuite_check_failed ("%s failed: stream lengths do not match: expected=%u; actual=%u",
what, expected->len, actual->len);
+ printf ("enriched: -->%.*s<--\n", (int) actual->len, (char *) actual->data);
goto error;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]