[gnome-notes/117-notes-synced-via-nextcloud-are-all-bold: 5/5] note-obj: Fix all text in bold



commit 6a556918bf097bc46f2392c3172cf62ea1022224
Author: Isaque Galdino <igaldino gmail com>
Date:   Tue Feb 19 20:10:54 2019 -0300

    note-obj: Fix all text in bold
    
    When application was creating a note from a text, it was replacing all
    "\n" character with a "<br/>" tab element.
    
    This change fixes that, wrapping every text line up in a "<div></div>"
    pair tag element, taking care to not do that for the first line, which
    is the note title.
    
    This change also fixes the CSS for the title.

 data/Default.css            | 15 ++++++++-------
 src/libbiji/biji-note-obj.c | 41 ++++++++++++++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 18 deletions(-)
---
diff --git a/data/Default.css b/data/Default.css
index 9c8f781..0a12963 100644
--- a/data/Default.css
+++ b/data/Default.css
@@ -1,15 +1,21 @@
 body {
   max-width:        35.0em;
-  margin:           0 auto;
+  margin:           -1em auto;
   word-wrap:        break-word;
   color:            black;
-  background-size:  2.0em 2.0em;
   line-height:      1.5em;
   padding:          2.0em;
   font-size:        150%;
+}
+
+body::first-line {
   font-weight:      bold;
 }
 
+div {
+  margin:           0.75em 0;
+}
+
 ul {
   list-style-position:inside;
   margin-top :      0;
@@ -24,8 +30,3 @@ ol {
   padding:          0 0 0 .75em;
 }
 
-body > div {
-  margin:           0.75em 0;
-  font-size:        100%;
-  font-weight:      normal;
-}
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index b84e368..518cafa 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -815,17 +815,36 @@ biji_note_obj_set_create_date (BijiNoteObj *note, gint64 time)
 gchar *
 html_from_plain_text (const gchar *content)
 {
-  gchar *escaped, *retval;
+  g_auto(GStrv)  lines   = NULL;
+  char          *body    = NULL;
+  char          *retval  = NULL;
+  char          *aux     = NULL;
 
-  if (content == NULL)
-    content = "";
+  if (content)
+    {
+      aux = biji_str_mass_replace (content, "&", "&amp;", "<", "&lt;", ">", "&gt;", NULL);
+      lines = g_strsplit (aux, "\n", -1);
+      g_free (aux);
+
+      if (lines)
+        {
+          body = g_strdup (lines[0]);
+          for (int i = 1; lines[i]; i++)
+            {
+              aux = body;
+              if (g_strcmp0 (lines[i], ""))
+                body = g_strconcat (aux, "<div>", lines[i], "</div>", NULL);
+              else
+                body = g_strconcat (aux, "<div><br/></div>", NULL);
+              g_free (aux);
+            }
+        }
+    }
 
-  escaped = biji_str_mass_replace (content,
-                                "&", "&amp;",
-                                "<", "&lt;",
-                                ">", "&gt;",
-                                "\n", "<br/>",
-                                NULL);
+  if (!body)
+    {
+      body = g_strdup ("");
+    }
 
   retval = g_strconcat ("<html xmlns=\"http://www.w3.org/1999/xhtml\";>",
                         "<head>",
@@ -833,10 +852,10 @@ html_from_plain_text (const gchar *content)
                         "<script language='javascript' src='bijiben.js'></script>"
                         "</head>",
                         "<body contenteditable='true' id='editable'>",
-                        escaped,
+                        body,
                         "</body></html>", NULL);
 
-  g_free (escaped);
+  g_free (body);
   return retval;
 }
 


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