Skip to content

Commit

Permalink
markdown support #806
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed May 27, 2024
1 parent e90ca52 commit 0567a12
Show file tree
Hide file tree
Showing 16 changed files with 2,195 additions and 78 deletions.
2 changes: 1 addition & 1 deletion core/Objects/BaseObject.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Objects.BaseObject : GLib.Object {
public string keywords { get; set; default = ""; }
public string icon_name { get; set; default = ""; }
public signal void deleted ();
public signal void updated ();
public signal void updated (string update_id = "");
public signal void archived ();
public signal void unarchived ();

Expand Down
2 changes: 1 addition & 1 deletion core/Services/Database.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ public class Services.Database : GLib.Object {
set_parameter_str (stmt, "$id", item.id);

if (stmt.step () == Sqlite.DONE) {
item.updated ();
item.updated (update_id);
item_updated (item, update_id);
} else {
warning ("Error: %d: %s", db.errcode (), db.errmsg ());
Expand Down
84 changes: 84 additions & 0 deletions core/Widgets/Markdown/Color.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
*
* Based on Folio
* https://github.com/toolstack/Folio
*/

namespace Color {
public struct HSL {
public float h;
public float s;
public float l;
}

public struct RGB {
public float r;
public float g;
public float b;

public inline RGB (float r = 0, float g = 0, float b = 0) {
this.r = r;
this.g = g;
this.b = b;
}

public inline RGB times (RGB rgb) {
return RGB (r * rgb.r, g * rgb.g, b * rgb.b);
}

public inline RGB multiply (float x) {
return RGB (r * x, g * x, b * x);
}

public inline RGB plus (RGB rgb) {
return RGB (r + rgb.r, g + rgb.g, b + rgb.b);
}
}

public inline HSL rgb_to_hsl (RGB rgb, out HSL hsl = null) {
hsl = HSL();
float s, v;
Gtk.rgb_to_hsv(rgb.r, rgb.g, rgb.b, out hsl.h, out s, out v);
hsl.l = v - v * s / 2;
float m = float.min (hsl.l, 1 - hsl.l);
hsl.s = (m != 0) ? (v-hsl.l)/m : 0;
return hsl;
}

public inline RGB hsl_to_rgb (HSL hsl, out RGB rgb = null) {
rgb = RGB();
float v = hsl.s * float.min (hsl.l, 1 - hsl.l) + hsl.l;
float s = (v != 0) ? 2-2*hsl.l/v : 0;
Gtk.hsv_to_rgb(hsl.h, s, v, out rgb.r, out rgb.g, out rgb.b);
return rgb;
}

public inline RGB RGBA_to_rgb (Gdk.RGBA rgba, out RGB rgb = null) {
rgb = RGB();
rgb.r = rgba.red;
rgb.g = rgba.green;
rgb.b = rgba.blue;
return rgb;
}

public inline Gdk.RGBA rgb_to_RGBA (RGB rgb, out Gdk.RGBA rgba = null) {
rgba = Gdk.RGBA();
rgba.red = rgb.r;
rgba.green = rgb.g;
rgba.blue = rgb.b;
rgba.alpha = 1;
return rgba;
}

public inline float get_luminance (float r, float g, float b) {
return Math.sqrtf (0.299f * r * r + 0.587f * g * g + 0.114f * b * b);
}

public inline float get_luminance_photometric (float r, float g, float b) {
return 0.2126f * r + 0.7152f * g + 0.0722f;
}

public inline float get_luminance_digital (float r, float g, float b) {
return 0.299f * r + 0.587f * g + 0.114f;
}
}
20 changes: 20 additions & 0 deletions core/Widgets/Markdown/MarkdownBuffer.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
*
* Based on Folio
* https://github.com/toolstack/Folio
*/

public class Widgets.Markdown.Buffer : GtkSource.Buffer {

public Buffer (string? text = null) {
Object ();
this.text = text;
}

public string get_all_text () {
Gtk.TextIter start, end;
get_start_iter (out start);
get_end_iter (out end);
return get_text(start, end, true);
}
}
Loading

0 comments on commit 0567a12

Please sign in to comment.