[vte/wip/html: 14/425] Convert VteCellAttr to CSS string



commit 830de14b922789c24800e987de1db3050d0e942d
Author: Joachim Breitner <mail joachim-breitner de>
Date:   Thu Jul 21 00:08:24 2011 +0200

    Convert VteCellAttr to CSS string
    
    This works, but is unsatisfying. Pasting into evolution does not
    preserve boldness, as it seems to expect <b> tags.

 src/vte.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)
---
diff --git a/src/vte.c b/src/vte.c
index e0c78ba..47905c2 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -6543,6 +6543,27 @@ vte_terminal_cellattr_equal(const VteCellAttr *attr1, const VteCellAttr *attr2)
 }
 
 /*
+ * Converts a VteCellAttr to a CSS style string.
+ */
+static gboolean
+vte_terminal_cellattr_to_css(const VteCellAttr *attr) {
+       GString *string;
+
+       string = g_string_new(NULL);
+
+       if (attr->bold)          g_string_append(string, "font-weight:bold;");
+       // fore, back, standout
+       if (attr->underline)     g_string_append(string, "text-decoration:underline");
+       if (attr->strikethrough) g_string_append(string, "text-decoration:line-through");
+       // reverse
+       if (attr->blink)         g_string_append(string, "text-decoration:blink");
+       // half
+       if (attr->invisible)     g_string_append(string, "visibility:hidden");
+
+       return g_string_free(string, FALSE);
+}
+
+/*
  * Similar to vte_terminal_find_charcell, but takes a VteCharAttribute for
  * indexing and returns the VteCellAttr.
  */
@@ -6575,8 +6596,8 @@ char *
 vte_terminal_attributes_to_html(VteTerminal *terminal, const gchar *text, GArray *attrs) {
        GString *string;
        guint from,to;
-       VteCellAttr *attr;
-       char *escaped;
+       const VteCellAttr *attr;
+       char *escaped, *style;
 
        g_assert(strlen(text) == attrs->len);
 
@@ -6604,9 +6625,17 @@ vte_terminal_attributes_to_html(VteTerminal *terminal, const gchar *text, GArray
                                to++;
                        }
                        escaped = g_markup_escape_text(text + from, to - from);
-                       g_string_append(string, "<span>");
-                       g_string_append(string, escaped);
-                       g_string_append(string, "</span>");
+                       style = vte_terminal_cellattr_to_css(attr);
+                       if (style[0] != '\0') {
+                               g_string_append_printf(string,
+                                       "<span style=\"%s\">%s</span>", 
+                                       style,
+                                       escaped
+                                       );
+                       } else {
+                               g_string_append(string, escaped);
+                       }
+                       g_free(style);
                        g_free(escaped);
                        from = to;
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]