/* MarkdownEditor.c generated by valac 0.56.19, the Vala compiler
 * generated from MarkdownEditor.vala, do not modify */

/*
 * Copyright © 2025 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include "planify.h"
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtksourceview/gtksource.h>
#include <pango/pango.h>
#include <gdk/gdk.h>
#include <cairo-gobject.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <float.h>
#include <math.h>
#include <gio/gio.h>
#include <adwaita.h>
#include <libspelling.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	WIDGETS_MARKDOWN_EDITOR_0_PROPERTY,
	WIDGETS_MARKDOWN_EDITOR_PLACEHOLDER_TEXT_PROPERTY,
	WIDGETS_MARKDOWN_EDITOR_PROJECT_PROPERTY,
	WIDGETS_MARKDOWN_EDITOR_TEXT_MODE_PROPERTY,
	WIDGETS_MARKDOWN_EDITOR_IS_EDITABLE_PROPERTY,
	WIDGETS_MARKDOWN_EDITOR_NUM_PROPERTIES
};
static GParamSpec* widgets_markdown_editor_properties[WIDGETS_MARKDOWN_EDITOR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define WIDGETS_MARKDOWN_EDITOR_TYPE_EXPANDED_RANGE (widgets_markdown_editor_expanded_range_get_type ())
typedef struct _WidgetsMarkdownEditorExpandedRange WidgetsMarkdownEditorExpandedRange;
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_match_info_unref0(var) ((var == NULL) ? NULL : (var = (g_match_info_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _Block19Data Block19Data;
enum  {
	WIDGETS_MARKDOWN_EDITOR_TEXT_CHANGED_SIGNAL,
	WIDGETS_MARKDOWN_EDITOR_ESCAPE_PRESSED_SIGNAL,
	WIDGETS_MARKDOWN_EDITOR_RETURN_PRESSED_SIGNAL,
	WIDGETS_MARKDOWN_EDITOR_FOCUS_IN_SIGNAL,
	WIDGETS_MARKDOWN_EDITOR_FOCUS_OUT_SIGNAL,
	WIDGETS_MARKDOWN_EDITOR_NUM_SIGNALS
};
static guint widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_NUM_SIGNALS] = {0};

struct _WidgetsMarkdownEditorPrivate {
	GtkPopover* format_popover;
	GtkButton* bold_button;
	GtkButton* italic_button;
	GtkButton* strikethrough_button;
	GtkButton* h1_button;
	GtkButton* h2_button;
	GtkButton* code_button;
	GtkButton* link_button;
	GtkButton* unordered_list_button;
	GtkButton* ordered_list_button;
	GtkPopover* link_popover;
	GtkEntry* link_entry;
	GtkButton* link_apply_button;
	GtkButton* link_remove_button;
	GtkTextTag* bold_tag;
	GtkTextTag* italic_tag;
	GtkTextTag* strikethrough_tag;
	GtkTextTag* h1_tag;
	GtkTextTag* h2_tag;
	GtkTextTag* code_tag;
	GtkTextTag* link_tag;
	GtkTextTag* invisible_tag;
	GtkTextTag* placeholder_tag;
	GtkTextTag* list_tag;
	GtkTextTag* ordered_list_tag;
	gchar* selected_link_text;
	gboolean mouse_pressed;
	gboolean showing_placeholder;
	GtkGestureClick* gesture_click;
	gboolean editing_existing_link;
	gboolean updating_programmatically;
	gchar* _placeholder_text;
	ObjectsProject* _project;
};

struct _WidgetsMarkdownEditorExpandedRange {
	GtkTextIter start;
	GtkTextIter end;
};

struct _Block19Data {
	int _ref_count_;
	WidgetsMarkdownEditor* self;
	SpellingTextBufferAdapter* adapter;
};

static gint WidgetsMarkdownEditor_private_offset;
static gpointer widgets_markdown_editor_parent_class = NULL;

static void widgets_markdown_editor_create_text_tags (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_create_format_popover (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_on_bold_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_bold_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                  gpointer self);
static void widgets_markdown_editor_on_italic_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_italic_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                    gpointer self);
static void widgets_markdown_editor_on_strikethrough_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_strikethrough_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                           gpointer self);
static void widgets_markdown_editor_on_h1_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_h1_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self);
static void widgets_markdown_editor_on_h2_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_h2_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self);
static void widgets_markdown_editor_on_code_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_code_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                  gpointer self);
static void widgets_markdown_editor_on_link_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_link_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                  gpointer self);
static void widgets_markdown_editor_on_unordered_list_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_unordered_list_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                            gpointer self);
static void widgets_markdown_editor_on_ordered_list_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_ordered_list_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                          gpointer self);
static void widgets_markdown_editor_create_link_popover (WidgetsMarkdownEditor* self);
static gboolean widgets_markdown_editor_on_event (WidgetsMarkdownEditor* self,
                                           GdkEvent* event);
static void widgets_markdown_editor_show_format_popover (WidgetsMarkdownEditor* self,
                                                  GtkTextIter* start);
static gboolean widgets_markdown_editor_is_already_link (WidgetsMarkdownEditor* self,
                                                  GtkTextIter* start,
                                                  GtkTextIter* end);
static void widgets_markdown_editor_show_edit_link_popover (WidgetsMarkdownEditor* self,
                                                     GtkTextIter* iter);
static void widgets_markdown_editor_show_add_link_popover (WidgetsMarkdownEditor* self,
                                                    GtkTextIter* iter);
static gboolean widgets_markdown_editor_is_already_bold (WidgetsMarkdownEditor* self,
                                                  GtkTextIter* start,
                                                  GtkTextIter* end);
static gboolean widgets_markdown_editor_is_already_italic (WidgetsMarkdownEditor* self,
                                                    GtkTextIter* start,
                                                    GtkTextIter* end);
static void widgets_markdown_editor_remove_bold_keep_italic (WidgetsMarkdownEditor* self,
                                                      GtkTextIter* start,
                                                      GtkTextIter* end);
static void widgets_markdown_editor_remove_bold_format (WidgetsMarkdownEditor* self,
                                                 GtkTextIter* start,
                                                 GtkTextIter* end);
static void widgets_markdown_editor_add_bold_format (WidgetsMarkdownEditor* self,
                                              GtkTextIter* start,
                                              GtkTextIter* end,
                                              const gchar* text);
static void widgets_markdown_editor_remove_italic_keep_bold (WidgetsMarkdownEditor* self,
                                                      GtkTextIter* start,
                                                      GtkTextIter* end);
static void widgets_markdown_editor_remove_italic_format (WidgetsMarkdownEditor* self,
                                                   GtkTextIter* start,
                                                   GtkTextIter* end);
static void widgets_markdown_editor_add_italic_format (WidgetsMarkdownEditor* self,
                                                GtkTextIter* start,
                                                GtkTextIter* end,
                                                const gchar* text);
static gboolean widgets_markdown_editor_text_has_strikethrough_in_range (WidgetsMarkdownEditor* self,
                                                                  GtkTextIter* start,
                                                                  GtkTextIter* end);
static void widgets_markdown_editor_remove_strikethrough_format (WidgetsMarkdownEditor* self,
                                                          GtkTextIter* start,
                                                          GtkTextIter* end);
static void widgets_markdown_editor_add_strikethrough_format (WidgetsMarkdownEditor* self,
                                                       GtkTextIter* start,
                                                       GtkTextIter* end,
                                                       const gchar* text);
static gboolean widgets_markdown_editor_is_already_strikethrough (WidgetsMarkdownEditor* self,
                                                           GtkTextIter* start,
                                                           GtkTextIter* end);
static void widgets_markdown_editor_apply_markdown_formatting (WidgetsMarkdownEditor* self);
static GType widgets_markdown_editor_expanded_range_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static WidgetsMarkdownEditorExpandedRange* widgets_markdown_editor_expanded_range_dup (const WidgetsMarkdownEditorExpandedRange* self);
static void widgets_markdown_editor_expanded_range_free (WidgetsMarkdownEditorExpandedRange* self);
static void widgets_markdown_editor_expand_selection_for_asterisks (WidgetsMarkdownEditor* self,
                                                             GtkTextIter* start,
                                                             GtkTextIter* end,
                                                             WidgetsMarkdownEditorExpandedRange* result);
static gchar* widgets_markdown_editor_get_clean_text_from_range (WidgetsMarkdownEditor* self,
                                                          GtkTextIter* start,
                                                          GtkTextIter* end);
static gboolean widgets_markdown_editor_text_has_italic_in_range (WidgetsMarkdownEditor* self,
                                                           GtkTextIter* start,
                                                           GtkTextIter* end);
static gboolean widgets_markdown_editor_text_has_bold_in_range (WidgetsMarkdownEditor* self,
                                                         GtkTextIter* start,
                                                         GtkTextIter* end);
static void widgets_markdown_editor_on_selection_lost (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_on_cursor_moved (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_clear_cursor_formatting (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_handle_focus_in (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_handle_focus_out (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_update_placeholder_visibility (WidgetsMarkdownEditor* self);
static gboolean widgets_markdown_editor_on_key_pressed (WidgetsMarkdownEditor* self,
                                                 guint keyval,
                                                 guint keycode,
                                                 GdkModifierType state);
static gboolean widgets_markdown_editor_handle_list_enter (WidgetsMarkdownEditor* self);
static gchar* widgets_markdown_editor_get_real_text (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_on_buffer_changed (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_update_mode (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_buffer_changed_gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                                                         gpointer self);
static gboolean widgets_markdown_editor_is_already_code (WidgetsMarkdownEditor* self,
                                                  GtkTextIter* start,
                                                  GtkTextIter* end);
static void widgets_markdown_editor_remove_code_format (WidgetsMarkdownEditor* self,
                                                 GtkTextIter* start,
                                                 GtkTextIter* end);
static void widgets_markdown_editor_add_code_format (WidgetsMarkdownEditor* self,
                                              GtkTextIter* start,
                                              GtkTextIter* end,
                                              const gchar* text);
static void widgets_markdown_editor_apply_list_format (WidgetsMarkdownEditor* self,
                                                GtkTextIter* start,
                                                GtkTextIter* end,
                                                gboolean ordered);
static void widgets_markdown_editor_on_link_apply_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_link_apply_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                        gpointer self);
static void widgets_markdown_editor_on_link_remove_clicked (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_link_remove_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                         gpointer self);
static void _widgets_markdown_editor_on_link_apply_clicked_gtk_entry_activate (GtkEntry* _sender,
                                                                        gpointer self);
static void widgets_markdown_editor_on_link_entry_changed (WidgetsMarkdownEditor* self);
static void _widgets_markdown_editor_on_link_entry_changed_gtk_editable_changed (GtkEditable* _sender,
                                                                          gpointer self);
static void widgets_markdown_editor_show_link_popover_at_iter (WidgetsMarkdownEditor* self,
                                                        GtkTextIter* iter);
static gchar* widgets_markdown_editor_extract_url_from_link (WidgetsMarkdownEditor* self,
                                                      GtkTextIter* iter);
static void widgets_markdown_editor_apply_link_format (WidgetsMarkdownEditor* self,
                                                const gchar* url);
static void widgets_markdown_editor_remove_link_format (WidgetsMarkdownEditor* self);
static void widgets_markdown_editor_replace_link_url_at_cursor (WidgetsMarkdownEditor* self,
                                                         GtkTextIter* iter,
                                                         const gchar* new_url);
static void widgets_markdown_editor_remove_link_at_cursor (WidgetsMarkdownEditor* self,
                                                    GtkTextIter* iter);
static void widgets_markdown_editor_on_text_clicked (WidgetsMarkdownEditor* self,
                                              gint n_press,
                                              gdouble x,
                                              gdouble y);
static void widgets_markdown_editor_open_link_at_iter (WidgetsMarkdownEditor* self,
                                                GtkTextIter* iter);
static gchar* widgets_markdown_editor_normalize_url (WidgetsMarkdownEditor* self,
                                              const gchar* url);
static GObject * widgets_markdown_editor_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static Block19Data* block19_data_ref (Block19Data* _data19_);
static void block19_data_unref (void * _userdata_);
static void _widgets_markdown_editor_update_placeholder_visibility_g_object_notify (GObject* _sender,
                                                                             GParamSpec* pspec,
                                                                             gpointer self);
static void _widgets_markdown_editor___lambda94_ (Block19Data* _data19_);
static void __widgets_markdown_editor___lambda94__g_settings_changed (GSettings* _sender,
                                                               const gchar* key,
                                                               gpointer self);
static void _widgets_markdown_editor___lambda95_ (WidgetsMarkdownEditor* self);
static void __widgets_markdown_editor___lambda95__g_settings_changed (GSettings* _sender,
                                                               const gchar* key,
                                                               gpointer self);
static void _widgets_markdown_editor_on_selection_lost_g_object_notify (GObject* _sender,
                                                                 GParamSpec* pspec,
                                                                 gpointer self);
static void _widgets_markdown_editor_on_cursor_moved_g_object_notify (GObject* _sender,
                                                               GParamSpec* pspec,
                                                               gpointer self);
static gboolean _widgets_markdown_editor_on_event_gtk_event_controller_legacy_event (GtkEventControllerLegacy* _sender,
                                                                              GdkEvent* event,
                                                                              gpointer self);
static void _widgets_markdown_editor_on_text_clicked_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                                         gint n_press,
                                                                         gdouble x,
                                                                         gdouble y,
                                                                         gpointer self);
static gboolean _widgets_markdown_editor_on_key_pressed_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                                       guint keyval,
                                                                                       guint keycode,
                                                                                       GdkModifierType state,
                                                                                       gpointer self);
static void _widgets_markdown_editor_handle_focus_in_gtk_event_controller_focus_enter (GtkEventControllerFocus* _sender,
                                                                                gpointer self);
static void _widgets_markdown_editor_handle_focus_out_gtk_event_controller_focus_leave (GtkEventControllerFocus* _sender,
                                                                                 gpointer self);
static void _widgets_markdown_editor___lambda96_ (WidgetsMarkdownEditor* self);
static void __widgets_markdown_editor___lambda96__gtk_widget_destroy (GtkWidget* _sender,
                                                               gpointer self);
static void widgets_markdown_editor_finalize (GObject * obj);
static GType widgets_markdown_editor_get_type_once (void);
static void _vala_widgets_markdown_editor_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static void _vala_widgets_markdown_editor_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
widgets_markdown_editor_get_instance_private (WidgetsMarkdownEditor* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsMarkdownEditor_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
widgets_markdown_editor_create_text_tags (WidgetsMarkdownEditor* self)
{
	GtkSourceBuffer* _tmp0_;
	GtkTextTag* _tmp1_;
	GtkTextTag* _tmp2_;
	GtkSourceBuffer* _tmp3_;
	GtkTextTag* _tmp4_;
	GtkTextTag* _tmp5_;
	GtkSourceBuffer* _tmp6_;
	GtkTextTag* _tmp7_;
	GtkTextTag* _tmp8_;
	GtkSourceBuffer* _tmp9_;
	GtkTextTag* _tmp10_;
	GtkTextTag* _tmp11_;
	GtkSourceBuffer* _tmp12_;
	GtkTextTag* _tmp13_;
	GtkTextTag* _tmp14_;
	GtkSourceBuffer* _tmp15_;
	GtkTextTag* _tmp16_;
	GtkTextTag* _tmp17_;
	GtkSourceBuffer* _tmp18_;
	GtkTextTag* _tmp19_;
	GtkTextTag* _tmp20_;
	GtkSourceBuffer* _tmp21_;
	GtkTextTag* _tmp22_;
	GtkTextTag* _tmp23_;
	GtkSourceBuffer* _tmp24_;
	GtkTextTag* _tmp25_;
	GtkTextTag* _tmp26_;
	GtkSourceBuffer* _tmp27_;
	GtkTextTag* _tmp28_;
	GtkTextTag* _tmp29_;
	GtkSourceBuffer* _tmp30_;
	GtkTextTag* _tmp31_;
	GtkTextTag* _tmp32_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp1_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp0_, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_g_object_unref0 (self->priv->bold_tag);
	self->priv->bold_tag = _tmp2_;
	_tmp3_ = self->buffer;
	_tmp4_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp3_, "italic", "style", PANGO_STYLE_ITALIC, NULL);
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_g_object_unref0 (self->priv->italic_tag);
	self->priv->italic_tag = _tmp5_;
	_tmp6_ = self->buffer;
	_tmp7_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp6_, "strikethrough", "strikethrough", TRUE, NULL);
	_tmp8_ = _g_object_ref0 (_tmp7_);
	_g_object_unref0 (self->priv->strikethrough_tag);
	self->priv->strikethrough_tag = _tmp8_;
	_tmp9_ = self->buffer;
	_tmp10_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp9_, "h1", "scale", 1.2, "weight", PANGO_WEIGHT_BOLD, NULL);
	_tmp11_ = _g_object_ref0 (_tmp10_);
	_g_object_unref0 (self->priv->h1_tag);
	self->priv->h1_tag = _tmp11_;
	_tmp12_ = self->buffer;
	_tmp13_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp12_, "h2", "scale", 1.1, "weight", PANGO_WEIGHT_BOLD, NULL);
	_tmp14_ = _g_object_ref0 (_tmp13_);
	_g_object_unref0 (self->priv->h2_tag);
	self->priv->h2_tag = _tmp14_;
	_tmp15_ = self->buffer;
	_tmp16_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp15_, "code", "family", "monospace", "foreground", "#cf222e", NULL);
	_tmp17_ = _g_object_ref0 (_tmp16_);
	_g_object_unref0 (self->priv->code_tag);
	self->priv->code_tag = _tmp17_;
	_tmp18_ = self->buffer;
	_tmp19_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp18_, "link", "foreground", "#0969da", "underline", PANGO_UNDERLINE_SINGLE, NULL);
	_tmp20_ = _g_object_ref0 (_tmp19_);
	_g_object_unref0 (self->priv->link_tag);
	self->priv->link_tag = _tmp20_;
	_tmp21_ = self->buffer;
	_tmp22_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp21_, "invisible", "invisible", TRUE, NULL);
	_tmp23_ = _g_object_ref0 (_tmp22_);
	_g_object_unref0 (self->priv->invisible_tag);
	self->priv->invisible_tag = _tmp23_;
	_tmp24_ = self->buffer;
	_tmp25_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp24_, "placeholder", "foreground", "#888888", NULL);
	_tmp26_ = _g_object_ref0 (_tmp25_);
	_g_object_unref0 (self->priv->placeholder_tag);
	self->priv->placeholder_tag = _tmp26_;
	_tmp27_ = self->buffer;
	_tmp28_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp27_, "unordered-list", "left-margin", 20, NULL);
	_tmp29_ = _g_object_ref0 (_tmp28_);
	_g_object_unref0 (self->priv->list_tag);
	self->priv->list_tag = _tmp29_;
	_tmp30_ = self->buffer;
	_tmp31_ = gtk_text_buffer_create_tag ((GtkTextBuffer*) _tmp30_, "ordered-list", "left-margin", 0, NULL);
	_tmp32_ = _g_object_ref0 (_tmp31_);
	_g_object_unref0 (self->priv->ordered_list_tag);
	self->priv->ordered_list_tag = _tmp32_;
}

static void
_widgets_markdown_editor_on_bold_clicked_gtk_button_clicked (GtkButton* _sender,
                                                             gpointer self)
{
	widgets_markdown_editor_on_bold_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_italic_clicked_gtk_button_clicked (GtkButton* _sender,
                                                               gpointer self)
{
	widgets_markdown_editor_on_italic_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_strikethrough_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                      gpointer self)
{
	widgets_markdown_editor_on_strikethrough_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_h1_clicked_gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self)
{
	widgets_markdown_editor_on_h1_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_h2_clicked_gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self)
{
	widgets_markdown_editor_on_h2_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_code_clicked_gtk_button_clicked (GtkButton* _sender,
                                                             gpointer self)
{
	widgets_markdown_editor_on_code_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_link_clicked_gtk_button_clicked (GtkButton* _sender,
                                                             gpointer self)
{
	widgets_markdown_editor_on_link_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_unordered_list_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                       gpointer self)
{
	widgets_markdown_editor_on_unordered_list_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_ordered_list_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                     gpointer self)
{
	widgets_markdown_editor_on_ordered_list_clicked ((WidgetsMarkdownEditor*) self);
}

static void
widgets_markdown_editor_create_format_popover (WidgetsMarkdownEditor* self)
{
	GtkButton* _tmp0_ = NULL;
	GtkButton* _tmp1_;
	GtkButton* _tmp2_ = NULL;
	GtkButton* _tmp3_;
	GtkButton* _tmp4_ = NULL;
	GtkButton* _tmp5_;
	gchar* _tmp6_;
	GtkButton* _tmp7_ = NULL;
	GtkButton* _tmp8_;
	gchar* _tmp9_;
	GtkButton* _tmp10_ = NULL;
	GtkButton* _tmp11_;
	GtkButton* _tmp12_ = NULL;
	GtkButton* _tmp13_;
	GtkButton* _tmp14_ = NULL;
	GtkButton* _tmp15_;
	GtkButton* _tmp16_ = NULL;
	GtkButton* _tmp17_;
	GtkButton* _tmp18_ = NULL;
	GtkButton* _tmp19_;
	GtkBox* format_box = NULL;
	GtkBox* _tmp20_;
	GtkButton* _tmp21_;
	GtkButton* _tmp22_;
	GtkSeparator* _tmp23_;
	GtkSeparator* _tmp24_;
	GtkButton* _tmp25_;
	GtkButton* _tmp26_;
	GtkButton* _tmp27_;
	GtkButton* _tmp28_;
	GtkSeparator* _tmp29_;
	GtkSeparator* _tmp30_;
	GtkButton* _tmp31_;
	GtkButton* _tmp32_;
	GtkSeparator* _tmp33_;
	GtkSeparator* _tmp34_;
	GtkButton* _tmp35_;
	GtkButton* _tmp36_;
	GtkButton* _tmp37_;
	GtkButton* _tmp38_;
	GtkButton* _tmp39_;
	GtkButton* _tmp40_;
	GtkButton* _tmp41_;
	GtkButton* _tmp42_;
	GtkButton* _tmp43_;
	GtkButton* _tmp44_;
	GtkWidget* _tmp45_;
	GtkPopover* _tmp46_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = (GtkButton*) gtk_button_new_from_icon_name ("text-bold-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp0_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp0_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->bold_button);
	self->priv->bold_button = _tmp0_;
	_tmp1_ = self->priv->bold_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp1_, "flat");
	_tmp2_ = (GtkButton*) gtk_button_new_from_icon_name ("text-italic-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp2_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp2_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->italic_button);
	self->priv->italic_button = _tmp2_;
	_tmp3_ = self->priv->italic_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp3_, "flat");
	_tmp4_ = (GtkButton*) gtk_button_new_from_icon_name ("text-strikethrough-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp4_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp4_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->strikethrough_button);
	self->priv->strikethrough_button = _tmp4_;
	_tmp5_ = self->priv->strikethrough_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp5_, "flat");
	_tmp6_ = g_strdup ("h1");
	_tmp7_ = (GtkButton*) gtk_button_new ();
	gtk_button_set_label (_tmp7_, _tmp6_);
	_g_free0 (_tmp6_);
	gtk_widget_set_valign ((GtkWidget*) _tmp7_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp7_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->h1_button);
	self->priv->h1_button = _tmp7_;
	_tmp8_ = self->priv->h1_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp8_, "flat");
	_tmp9_ = g_strdup ("h2");
	_tmp10_ = (GtkButton*) gtk_button_new ();
	gtk_button_set_label (_tmp10_, _tmp9_);
	_g_free0 (_tmp9_);
	gtk_widget_set_valign ((GtkWidget*) _tmp10_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp10_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp10_);
	_g_object_unref0 (self->priv->h2_button);
	self->priv->h2_button = _tmp10_;
	_tmp11_ = self->priv->h2_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp11_, "flat");
	_tmp12_ = (GtkButton*) gtk_button_new_from_icon_name ("code-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp12_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp12_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp12_);
	_g_object_unref0 (self->priv->code_button);
	self->priv->code_button = _tmp12_;
	_tmp13_ = self->priv->code_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp13_, "flat");
	_tmp14_ = (GtkButton*) gtk_button_new_from_icon_name ("chain-link-loose-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp14_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp14_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp14_);
	_g_object_unref0 (self->priv->link_button);
	self->priv->link_button = _tmp14_;
	_tmp15_ = self->priv->link_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp15_, "flat");
	_tmp16_ = (GtkButton*) gtk_button_new_from_icon_name ("view-list-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp16_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp16_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp16_);
	_g_object_unref0 (self->priv->unordered_list_button);
	self->priv->unordered_list_button = _tmp16_;
	_tmp17_ = self->priv->unordered_list_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp17_, "flat");
	_tmp18_ = (GtkButton*) gtk_button_new_from_icon_name ("view-list-ordered-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp18_, GTK_ALIGN_CENTER);
	gtk_widget_set_halign ((GtkWidget*) _tmp18_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp18_);
	_g_object_unref0 (self->priv->ordered_list_button);
	self->priv->ordered_list_button = _tmp18_;
	_tmp19_ = self->priv->ordered_list_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp19_, "flat");
	_tmp20_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp20_);
	format_box = _tmp20_;
	_tmp21_ = self->priv->h1_button;
	gtk_box_append (format_box, (GtkWidget*) _tmp21_);
	_tmp22_ = self->priv->h2_button;
	gtk_box_append (format_box, (GtkWidget*) _tmp22_);
	_tmp23_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_VERTICAL);
	g_object_ref_sink (_tmp23_);
	_tmp24_ = _tmp23_;
	gtk_box_append (format_box, (GtkWidget*) _tmp24_);
	_g_object_unref0 (_tmp24_);
	_tmp25_ = self->priv->bold_button;
	gtk_box_append (format_box, (GtkWidget*) _tmp25_);
	_tmp26_ = self->priv->italic_button;
	gtk_box_append (format_box, (GtkWidget*) _tmp26_);
	_tmp27_ = self->priv->strikethrough_button;
	gtk_box_append (format_box, (GtkWidget*) _tmp27_);
	_tmp28_ = self->priv->code_button;
	gtk_box_append (format_box, (GtkWidget*) _tmp28_);
	_tmp29_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_VERTICAL);
	g_object_ref_sink (_tmp29_);
	_tmp30_ = _tmp29_;
	gtk_box_append (format_box, (GtkWidget*) _tmp30_);
	_g_object_unref0 (_tmp30_);
	_tmp31_ = self->priv->unordered_list_button;
	gtk_box_append (format_box, (GtkWidget*) _tmp31_);
	_tmp32_ = self->priv->ordered_list_button;
	gtk_box_append (format_box, (GtkWidget*) _tmp32_);
	_tmp33_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_VERTICAL);
	g_object_ref_sink (_tmp33_);
	_tmp34_ = _tmp33_;
	gtk_box_append (format_box, (GtkWidget*) _tmp34_);
	_g_object_unref0 (_tmp34_);
	_tmp35_ = self->priv->link_button;
	gtk_box_append (format_box, (GtkWidget*) _tmp35_);
	_tmp36_ = self->priv->bold_button;
	g_signal_connect_object (_tmp36_, "clicked", (GCallback) _widgets_markdown_editor_on_bold_clicked_gtk_button_clicked, self, 0);
	_tmp37_ = self->priv->italic_button;
	g_signal_connect_object (_tmp37_, "clicked", (GCallback) _widgets_markdown_editor_on_italic_clicked_gtk_button_clicked, self, 0);
	_tmp38_ = self->priv->strikethrough_button;
	g_signal_connect_object (_tmp38_, "clicked", (GCallback) _widgets_markdown_editor_on_strikethrough_clicked_gtk_button_clicked, self, 0);
	_tmp39_ = self->priv->h1_button;
	g_signal_connect_object (_tmp39_, "clicked", (GCallback) _widgets_markdown_editor_on_h1_clicked_gtk_button_clicked, self, 0);
	_tmp40_ = self->priv->h2_button;
	g_signal_connect_object (_tmp40_, "clicked", (GCallback) _widgets_markdown_editor_on_h2_clicked_gtk_button_clicked, self, 0);
	_tmp41_ = self->priv->code_button;
	g_signal_connect_object (_tmp41_, "clicked", (GCallback) _widgets_markdown_editor_on_code_clicked_gtk_button_clicked, self, 0);
	_tmp42_ = self->priv->link_button;
	g_signal_connect_object (_tmp42_, "clicked", (GCallback) _widgets_markdown_editor_on_link_clicked_gtk_button_clicked, self, 0);
	_tmp43_ = self->priv->unordered_list_button;
	g_signal_connect_object (_tmp43_, "clicked", (GCallback) _widgets_markdown_editor_on_unordered_list_clicked_gtk_button_clicked, self, 0);
	_tmp44_ = self->priv->ordered_list_button;
	g_signal_connect_object (_tmp44_, "clicked", (GCallback) _widgets_markdown_editor_on_ordered_list_clicked_gtk_button_clicked, self, 0);
	widgets_markdown_editor_create_link_popover (self);
	_tmp45_ = _g_object_ref0 ((GtkWidget*) format_box);
	_tmp46_ = (GtkPopover*) gtk_popover_new ();
	gtk_popover_set_has_arrow (_tmp46_, FALSE);
	gtk_popover_set_autohide (_tmp46_, FALSE);
	gtk_popover_set_child (_tmp46_, _tmp45_);
	_g_object_unref0 (_tmp45_);
	g_object_ref_sink (_tmp46_);
	_g_object_unref0 (self->priv->format_popover);
	self->priv->format_popover = _tmp46_;
	_g_object_unref0 (format_box);
}

static gboolean
widgets_markdown_editor_on_event (WidgetsMarkdownEditor* self,
                                  GdkEvent* event)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = widgets_markdown_editor_get_text_mode (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		result = FALSE;
		return result;
	}
	if (gdk_event_get_event_type (event) == GDK_BUTTON_PRESS) {
		self->priv->mouse_pressed = TRUE;
	} else {
		gboolean _tmp2_ = FALSE;
		if (gdk_event_get_event_type (event) == GDK_BUTTON_RELEASE) {
			_tmp2_ = self->priv->mouse_pressed;
		} else {
			_tmp2_ = FALSE;
		}
		if (_tmp2_) {
			GtkTextIter start = {0};
			GtkTextIter end = {0};
			GtkSourceBuffer* _tmp3_;
			GtkTextIter _tmp4_ = {0};
			GtkTextIter _tmp5_ = {0};
			gboolean _tmp6_;
			self->priv->mouse_pressed = FALSE;
			_tmp3_ = self->buffer;
			_tmp6_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp3_, &_tmp4_, &_tmp5_);
			start = _tmp4_;
			end = _tmp5_;
			if (_tmp6_) {
				GtkTextIter _tmp7_;
				_tmp7_ = start;
				widgets_markdown_editor_show_format_popover (self, &_tmp7_);
			}
		}
	}
	result = FALSE;
	return result;
}

static void
widgets_markdown_editor_show_format_popover (WidgetsMarkdownEditor* self,
                                             GtkTextIter* start)
{
	GdkRectangle rect = {0};
	GtkTextView* _tmp0_;
	GtkTextIter _tmp1_;
	GdkRectangle _tmp2_ = {0};
	gint x = 0;
	gint y = 0;
	GtkTextView* _tmp3_;
	GdkRectangle _tmp4_;
	GdkRectangle _tmp5_;
	gint _tmp6_ = 0;
	gint _tmp7_ = 0;
	GtkPopover* _tmp8_;
	GtkTextView* _tmp9_;
	GtkPopover* _tmp10_;
	GdkRectangle _tmp11_;
	GtkPopover* _tmp12_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	_tmp0_ = self->text_view;
	_tmp1_ = *start;
	gtk_text_view_get_iter_location (_tmp0_, &_tmp1_, &_tmp2_);
	rect = _tmp2_;
	_tmp3_ = self->text_view;
	_tmp4_ = rect;
	_tmp5_ = rect;
	gtk_text_view_buffer_to_window_coords (_tmp3_, GTK_TEXT_WINDOW_TEXT, _tmp4_.x, _tmp5_.y, &_tmp6_, &_tmp7_);
	x = _tmp6_;
	y = _tmp7_;
	rect.x = x;
	rect.y = y;
	_tmp8_ = self->priv->format_popover;
	_tmp9_ = self->text_view;
	gtk_widget_set_parent ((GtkWidget*) _tmp8_, (GtkWidget*) _tmp9_);
	_tmp10_ = self->priv->format_popover;
	_tmp11_ = rect;
	gtk_popover_set_pointing_to (_tmp10_, &_tmp11_);
	_tmp12_ = self->priv->format_popover;
	gtk_popover_popup (_tmp12_);
}

static void
widgets_markdown_editor_on_bold_clicked (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	g_return_if_fail (self != NULL);
	widgets_markdown_editor_toggle_bold_format (self);
	_tmp0_ = self->priv->format_popover;
	gtk_popover_popdown (_tmp0_);
}

static void
widgets_markdown_editor_on_italic_clicked (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	g_return_if_fail (self != NULL);
	widgets_markdown_editor_toggle_italic_format (self);
	_tmp0_ = self->priv->format_popover;
	gtk_popover_popdown (_tmp0_);
}

static void
widgets_markdown_editor_on_strikethrough_clicked (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	g_return_if_fail (self != NULL);
	widgets_markdown_editor_toggle_strikethrough_format (self);
	_tmp0_ = self->priv->format_popover;
	gtk_popover_popdown (_tmp0_);
}

static void
widgets_markdown_editor_on_h1_clicked (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	g_return_if_fail (self != NULL);
	widgets_markdown_editor_apply_h1_format (self);
	_tmp0_ = self->priv->format_popover;
	gtk_popover_popdown (_tmp0_);
}

static void
widgets_markdown_editor_on_h2_clicked (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	g_return_if_fail (self != NULL);
	widgets_markdown_editor_apply_h2_format (self);
	_tmp0_ = self->priv->format_popover;
	gtk_popover_popdown (_tmp0_);
}

static void
widgets_markdown_editor_on_code_clicked (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	g_return_if_fail (self != NULL);
	widgets_markdown_editor_toggle_code_format (self);
	_tmp0_ = self->priv->format_popover;
	gtk_popover_popdown (_tmp0_);
}

static void
widgets_markdown_editor_on_link_clicked (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	GtkPopover* _tmp12_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		GtkSourceBuffer* _tmp4_;
		GtkTextIter _tmp5_;
		GtkTextIter _tmp6_;
		gchar* _tmp7_;
		GtkTextIter _tmp8_;
		GtkTextIter _tmp9_;
		_tmp4_ = self->buffer;
		_tmp5_ = start;
		_tmp6_ = end;
		_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, FALSE);
		_g_free0 (self->priv->selected_link_text);
		self->priv->selected_link_text = _tmp7_;
		_tmp8_ = start;
		_tmp9_ = end;
		if (widgets_markdown_editor_is_already_link (self, &_tmp8_, &_tmp9_)) {
			GtkTextIter _tmp10_;
			_tmp10_ = start;
			widgets_markdown_editor_show_edit_link_popover (self, &_tmp10_);
		} else {
			GtkTextIter _tmp11_;
			_tmp11_ = start;
			widgets_markdown_editor_show_add_link_popover (self, &_tmp11_);
		}
	}
	_tmp12_ = self->priv->format_popover;
	gtk_popover_popdown (_tmp12_);
}

static void
widgets_markdown_editor_on_unordered_list_clicked (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	g_return_if_fail (self != NULL);
	widgets_markdown_editor_apply_unordered_list_format (self);
	_tmp0_ = self->priv->format_popover;
	gtk_popover_popdown (_tmp0_);
}

static void
widgets_markdown_editor_on_ordered_list_clicked (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	g_return_if_fail (self != NULL);
	widgets_markdown_editor_apply_ordered_list_format (self);
	_tmp0_ = self->priv->format_popover;
	gtk_popover_popdown (_tmp0_);
}

void
widgets_markdown_editor_toggle_bold_format (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		gchar* selected_text = NULL;
		GtkSourceBuffer* _tmp4_;
		GtkTextIter _tmp5_;
		GtkTextIter _tmp6_;
		gchar* _tmp7_;
		gboolean has_bold = FALSE;
		GtkTextIter _tmp8_;
		GtkTextIter _tmp9_;
		gboolean has_italic = FALSE;
		GtkTextIter _tmp10_;
		GtkTextIter _tmp11_;
		gboolean _tmp12_ = FALSE;
		_tmp4_ = self->buffer;
		_tmp5_ = start;
		_tmp6_ = end;
		_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, FALSE);
		selected_text = _tmp7_;
		_tmp8_ = start;
		_tmp9_ = end;
		has_bold = widgets_markdown_editor_is_already_bold (self, &_tmp8_, &_tmp9_);
		_tmp10_ = start;
		_tmp11_ = end;
		has_italic = widgets_markdown_editor_is_already_italic (self, &_tmp10_, &_tmp11_);
		if (has_bold) {
			_tmp12_ = has_italic;
		} else {
			_tmp12_ = FALSE;
		}
		if (_tmp12_) {
			GtkTextIter _tmp13_;
			GtkTextIter _tmp14_;
			_tmp13_ = start;
			_tmp14_ = end;
			widgets_markdown_editor_remove_bold_keep_italic (self, &_tmp13_, &_tmp14_);
		} else {
			if (has_bold) {
				GtkTextIter _tmp15_;
				GtkTextIter _tmp16_;
				_tmp15_ = start;
				_tmp16_ = end;
				widgets_markdown_editor_remove_bold_format (self, &_tmp15_, &_tmp16_);
			} else {
				GtkTextIter _tmp17_;
				GtkTextIter _tmp18_;
				const gchar* _tmp19_;
				_tmp17_ = start;
				_tmp18_ = end;
				_tmp19_ = selected_text;
				widgets_markdown_editor_add_bold_format (self, &_tmp17_, &_tmp18_, _tmp19_);
			}
		}
		_g_free0 (selected_text);
	}
}

void
widgets_markdown_editor_toggle_italic_format (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		gchar* selected_text = NULL;
		GtkSourceBuffer* _tmp4_;
		GtkTextIter _tmp5_;
		GtkTextIter _tmp6_;
		gchar* _tmp7_;
		gboolean has_bold = FALSE;
		GtkTextIter _tmp8_;
		GtkTextIter _tmp9_;
		gboolean has_italic = FALSE;
		GtkTextIter _tmp10_;
		GtkTextIter _tmp11_;
		gboolean _tmp12_ = FALSE;
		_tmp4_ = self->buffer;
		_tmp5_ = start;
		_tmp6_ = end;
		_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, FALSE);
		selected_text = _tmp7_;
		_tmp8_ = start;
		_tmp9_ = end;
		has_bold = widgets_markdown_editor_is_already_bold (self, &_tmp8_, &_tmp9_);
		_tmp10_ = start;
		_tmp11_ = end;
		has_italic = widgets_markdown_editor_is_already_italic (self, &_tmp10_, &_tmp11_);
		if (has_bold) {
			_tmp12_ = has_italic;
		} else {
			_tmp12_ = FALSE;
		}
		if (_tmp12_) {
			GtkTextIter _tmp13_;
			GtkTextIter _tmp14_;
			_tmp13_ = start;
			_tmp14_ = end;
			widgets_markdown_editor_remove_italic_keep_bold (self, &_tmp13_, &_tmp14_);
		} else {
			if (has_italic) {
				GtkTextIter _tmp15_;
				GtkTextIter _tmp16_;
				_tmp15_ = start;
				_tmp16_ = end;
				widgets_markdown_editor_remove_italic_format (self, &_tmp15_, &_tmp16_);
			} else {
				GtkTextIter _tmp17_;
				GtkTextIter _tmp18_;
				const gchar* _tmp19_;
				_tmp17_ = start;
				_tmp18_ = end;
				_tmp19_ = selected_text;
				widgets_markdown_editor_add_italic_format (self, &_tmp17_, &_tmp18_, _tmp19_);
			}
		}
		_g_free0 (selected_text);
	}
}

void
widgets_markdown_editor_toggle_strikethrough_format (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		gchar* selected_text = NULL;
		GtkSourceBuffer* _tmp4_;
		GtkTextIter _tmp5_;
		GtkTextIter _tmp6_;
		gchar* _tmp7_;
		gboolean has_strikethrough = FALSE;
		GtkTextIter _tmp8_;
		GtkTextIter _tmp9_;
		_tmp4_ = self->buffer;
		_tmp5_ = start;
		_tmp6_ = end;
		_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, FALSE);
		selected_text = _tmp7_;
		_tmp8_ = start;
		_tmp9_ = end;
		has_strikethrough = widgets_markdown_editor_text_has_strikethrough_in_range (self, &_tmp8_, &_tmp9_);
		if (has_strikethrough) {
			GtkTextIter _tmp10_;
			GtkTextIter _tmp11_;
			_tmp10_ = start;
			_tmp11_ = end;
			widgets_markdown_editor_remove_strikethrough_format (self, &_tmp10_, &_tmp11_);
		} else {
			GtkTextIter _tmp12_;
			GtkTextIter _tmp13_;
			const gchar* _tmp14_;
			_tmp12_ = start;
			_tmp13_ = end;
			_tmp14_ = selected_text;
			widgets_markdown_editor_add_strikethrough_format (self, &_tmp12_, &_tmp13_, _tmp14_);
		}
		_g_free0 (selected_text);
	}
}

static gboolean
widgets_markdown_editor_is_already_bold (WidgetsMarkdownEditor* self,
                                         GtkTextIter* start,
                                         GtkTextIter* end)
{
	GtkTextTag* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (start != NULL, FALSE);
	g_return_val_if_fail (end != NULL, FALSE);
	_tmp0_ = self->priv->bold_tag;
	result = gtk_text_iter_has_tag (start, _tmp0_);
	return result;
}

static gboolean
widgets_markdown_editor_is_already_italic (WidgetsMarkdownEditor* self,
                                           GtkTextIter* start,
                                           GtkTextIter* end)
{
	GtkTextTag* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (start != NULL, FALSE);
	g_return_val_if_fail (end != NULL, FALSE);
	_tmp0_ = self->priv->italic_tag;
	result = gtk_text_iter_has_tag (start, _tmp0_);
	return result;
}

static gboolean
widgets_markdown_editor_is_already_strikethrough (WidgetsMarkdownEditor* self,
                                                  GtkTextIter* start,
                                                  GtkTextIter* end)
{
	GtkTextTag* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (start != NULL, FALSE);
	g_return_val_if_fail (end != NULL, FALSE);
	_tmp0_ = self->priv->strikethrough_tag;
	result = gtk_text_iter_has_tag (start, _tmp0_);
	return result;
}

static void
widgets_markdown_editor_remove_bold_format (WidgetsMarkdownEditor* self,
                                            GtkTextIter* start,
                                            GtkTextIter* end)
{
	GtkTextIter search_start = {0};
	GtkTextIter _tmp0_;
	GtkTextIter search_end = {0};
	GtkTextIter _tmp1_;
	gchar* text = NULL;
	GtkSourceBuffer* _tmp4_;
	GtkTextIter _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	GtkSourceBuffer* _tmp8_;
	GtkSourceBuffer* _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	_tmp0_ = *start;
	search_start = _tmp0_;
	_tmp1_ = *end;
	search_end = _tmp1_;
	while (TRUE) {
		GtkTextTag* _tmp2_;
		if (!gtk_text_iter_backward_char (&search_start)) {
			break;
		}
		_tmp2_ = self->priv->invisible_tag;
		if (gtk_text_iter_has_tag (&search_start, _tmp2_)) {
			continue;
		} else {
			gtk_text_iter_forward_char (&search_start);
			break;
		}
	}
	while (TRUE) {
		GtkTextTag* _tmp3_;
		if (!gtk_text_iter_forward_char (&search_end)) {
			break;
		}
		_tmp3_ = self->priv->invisible_tag;
		if (gtk_text_iter_has_tag (&search_end, _tmp3_)) {
			continue;
		} else {
			gtk_text_iter_backward_char (&search_end);
			break;
		}
	}
	_tmp4_ = self->buffer;
	_tmp5_ = *start;
	_tmp6_ = *end;
	_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, FALSE);
	text = _tmp7_;
	_tmp8_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp8_, &search_start, &search_end);
	_tmp9_ = self->buffer;
	gtk_text_buffer_insert ((GtkTextBuffer*) _tmp9_, &search_start, text, -1);
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (text);
}

static void
widgets_markdown_editor_add_bold_format (WidgetsMarkdownEditor* self,
                                         GtkTextIter* start,
                                         GtkTextIter* end,
                                         const gchar* text)
{
	WidgetsMarkdownEditorExpandedRange expanded = {0};
	GtkTextIter _tmp0_;
	GtkTextIter _tmp1_;
	WidgetsMarkdownEditorExpandedRange _tmp2_ = {0};
	gchar* clean_text = NULL;
	WidgetsMarkdownEditorExpandedRange _tmp3_;
	GtkTextIter _tmp4_;
	WidgetsMarkdownEditorExpandedRange _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	gboolean has_italic = FALSE;
	GtkTextIter _tmp8_;
	GtkTextIter _tmp9_;
	GtkSourceBuffer* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	g_return_if_fail (text != NULL);
	_tmp0_ = *start;
	_tmp1_ = *end;
	widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp0_, &_tmp1_, &_tmp2_);
	expanded = _tmp2_;
	_tmp3_ = expanded;
	_tmp4_ = _tmp3_.start;
	_tmp5_ = expanded;
	_tmp6_ = _tmp5_.end;
	_tmp7_ = widgets_markdown_editor_get_clean_text_from_range (self, &_tmp4_, &_tmp6_);
	clean_text = _tmp7_;
	_tmp8_ = *start;
	_tmp9_ = *end;
	has_italic = widgets_markdown_editor_text_has_italic_in_range (self, &_tmp8_, &_tmp9_);
	_tmp10_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp10_, &expanded.start, &expanded.end);
	if (has_italic) {
		GtkSourceBuffer* _tmp11_;
		const gchar* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp11_ = self->buffer;
		_tmp12_ = clean_text;
		_tmp13_ = g_strconcat ("***", _tmp12_, NULL);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_strconcat (_tmp14_, "***", NULL);
		_tmp16_ = _tmp15_;
		gtk_text_buffer_insert ((GtkTextBuffer*) _tmp11_, &expanded.start, _tmp16_, -1);
		_g_free0 (_tmp16_);
		_g_free0 (_tmp14_);
	} else {
		GtkSourceBuffer* _tmp17_;
		const gchar* _tmp18_;
		gchar* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		gchar* _tmp22_;
		_tmp17_ = self->buffer;
		_tmp18_ = clean_text;
		_tmp19_ = g_strconcat ("**", _tmp18_, NULL);
		_tmp20_ = _tmp19_;
		_tmp21_ = g_strconcat (_tmp20_, "**", NULL);
		_tmp22_ = _tmp21_;
		gtk_text_buffer_insert ((GtkTextBuffer*) _tmp17_, &expanded.start, _tmp22_, -1);
		_g_free0 (_tmp22_);
		_g_free0 (_tmp20_);
	}
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (clean_text);
}

static void
widgets_markdown_editor_remove_bold_keep_italic (WidgetsMarkdownEditor* self,
                                                 GtkTextIter* start,
                                                 GtkTextIter* end)
{
	WidgetsMarkdownEditorExpandedRange expanded = {0};
	GtkTextIter _tmp0_;
	GtkTextIter _tmp1_;
	WidgetsMarkdownEditorExpandedRange _tmp2_ = {0};
	gchar* clean_text = NULL;
	WidgetsMarkdownEditorExpandedRange _tmp3_;
	GtkTextIter _tmp4_;
	WidgetsMarkdownEditorExpandedRange _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	GtkSourceBuffer* _tmp8_;
	GtkSourceBuffer* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	_tmp0_ = *start;
	_tmp1_ = *end;
	widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp0_, &_tmp1_, &_tmp2_);
	expanded = _tmp2_;
	_tmp3_ = expanded;
	_tmp4_ = _tmp3_.start;
	_tmp5_ = expanded;
	_tmp6_ = _tmp5_.end;
	_tmp7_ = widgets_markdown_editor_get_clean_text_from_range (self, &_tmp4_, &_tmp6_);
	clean_text = _tmp7_;
	_tmp8_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp8_, &expanded.start, &expanded.end);
	_tmp9_ = self->buffer;
	_tmp10_ = g_strconcat ("*", clean_text, NULL);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strconcat (_tmp11_, "*", NULL);
	_tmp13_ = _tmp12_;
	gtk_text_buffer_insert ((GtkTextBuffer*) _tmp9_, &expanded.start, _tmp13_, -1);
	_g_free0 (_tmp13_);
	_g_free0 (_tmp11_);
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (clean_text);
}

static void
widgets_markdown_editor_remove_italic_format (WidgetsMarkdownEditor* self,
                                              GtkTextIter* start,
                                              GtkTextIter* end)
{
	GtkTextIter search_start = {0};
	GtkTextIter _tmp0_;
	GtkTextIter search_end = {0};
	GtkTextIter _tmp1_;
	gchar* text = NULL;
	GtkSourceBuffer* _tmp4_;
	GtkTextIter _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	GtkSourceBuffer* _tmp8_;
	GtkSourceBuffer* _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	_tmp0_ = *start;
	search_start = _tmp0_;
	_tmp1_ = *end;
	search_end = _tmp1_;
	while (TRUE) {
		GtkTextTag* _tmp2_;
		if (!gtk_text_iter_backward_char (&search_start)) {
			break;
		}
		_tmp2_ = self->priv->invisible_tag;
		if (gtk_text_iter_has_tag (&search_start, _tmp2_)) {
			continue;
		} else {
			gtk_text_iter_forward_char (&search_start);
			break;
		}
	}
	while (TRUE) {
		GtkTextTag* _tmp3_;
		if (!gtk_text_iter_forward_char (&search_end)) {
			break;
		}
		_tmp3_ = self->priv->invisible_tag;
		if (gtk_text_iter_has_tag (&search_end, _tmp3_)) {
			continue;
		} else {
			gtk_text_iter_backward_char (&search_end);
			break;
		}
	}
	_tmp4_ = self->buffer;
	_tmp5_ = *start;
	_tmp6_ = *end;
	_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, FALSE);
	text = _tmp7_;
	_tmp8_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp8_, &search_start, &search_end);
	_tmp9_ = self->buffer;
	gtk_text_buffer_insert ((GtkTextBuffer*) _tmp9_, &search_start, text, -1);
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (text);
}

static void
widgets_markdown_editor_add_italic_format (WidgetsMarkdownEditor* self,
                                           GtkTextIter* start,
                                           GtkTextIter* end,
                                           const gchar* text)
{
	WidgetsMarkdownEditorExpandedRange expanded = {0};
	GtkTextIter _tmp0_;
	GtkTextIter _tmp1_;
	WidgetsMarkdownEditorExpandedRange _tmp2_ = {0};
	gchar* clean_text = NULL;
	WidgetsMarkdownEditorExpandedRange _tmp3_;
	GtkTextIter _tmp4_;
	WidgetsMarkdownEditorExpandedRange _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	gboolean has_bold = FALSE;
	GtkTextIter _tmp8_;
	GtkTextIter _tmp9_;
	GtkSourceBuffer* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	g_return_if_fail (text != NULL);
	_tmp0_ = *start;
	_tmp1_ = *end;
	widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp0_, &_tmp1_, &_tmp2_);
	expanded = _tmp2_;
	_tmp3_ = expanded;
	_tmp4_ = _tmp3_.start;
	_tmp5_ = expanded;
	_tmp6_ = _tmp5_.end;
	_tmp7_ = widgets_markdown_editor_get_clean_text_from_range (self, &_tmp4_, &_tmp6_);
	clean_text = _tmp7_;
	_tmp8_ = *start;
	_tmp9_ = *end;
	has_bold = widgets_markdown_editor_text_has_bold_in_range (self, &_tmp8_, &_tmp9_);
	_tmp10_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp10_, &expanded.start, &expanded.end);
	if (has_bold) {
		GtkSourceBuffer* _tmp11_;
		const gchar* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp11_ = self->buffer;
		_tmp12_ = clean_text;
		_tmp13_ = g_strconcat ("***", _tmp12_, NULL);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_strconcat (_tmp14_, "***", NULL);
		_tmp16_ = _tmp15_;
		gtk_text_buffer_insert ((GtkTextBuffer*) _tmp11_, &expanded.start, _tmp16_, -1);
		_g_free0 (_tmp16_);
		_g_free0 (_tmp14_);
	} else {
		GtkSourceBuffer* _tmp17_;
		const gchar* _tmp18_;
		gchar* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		gchar* _tmp22_;
		_tmp17_ = self->buffer;
		_tmp18_ = clean_text;
		_tmp19_ = g_strconcat ("*", _tmp18_, NULL);
		_tmp20_ = _tmp19_;
		_tmp21_ = g_strconcat (_tmp20_, "*", NULL);
		_tmp22_ = _tmp21_;
		gtk_text_buffer_insert ((GtkTextBuffer*) _tmp17_, &expanded.start, _tmp22_, -1);
		_g_free0 (_tmp22_);
		_g_free0 (_tmp20_);
	}
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (clean_text);
}

static void
widgets_markdown_editor_remove_italic_keep_bold (WidgetsMarkdownEditor* self,
                                                 GtkTextIter* start,
                                                 GtkTextIter* end)
{
	WidgetsMarkdownEditorExpandedRange expanded = {0};
	GtkTextIter _tmp0_;
	GtkTextIter _tmp1_;
	WidgetsMarkdownEditorExpandedRange _tmp2_ = {0};
	gchar* clean_text = NULL;
	WidgetsMarkdownEditorExpandedRange _tmp3_;
	GtkTextIter _tmp4_;
	WidgetsMarkdownEditorExpandedRange _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	GtkSourceBuffer* _tmp8_;
	GtkSourceBuffer* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	_tmp0_ = *start;
	_tmp1_ = *end;
	widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp0_, &_tmp1_, &_tmp2_);
	expanded = _tmp2_;
	_tmp3_ = expanded;
	_tmp4_ = _tmp3_.start;
	_tmp5_ = expanded;
	_tmp6_ = _tmp5_.end;
	_tmp7_ = widgets_markdown_editor_get_clean_text_from_range (self, &_tmp4_, &_tmp6_);
	clean_text = _tmp7_;
	_tmp8_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp8_, &expanded.start, &expanded.end);
	_tmp9_ = self->buffer;
	_tmp10_ = g_strconcat ("**", clean_text, NULL);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strconcat (_tmp11_, "**", NULL);
	_tmp13_ = _tmp12_;
	gtk_text_buffer_insert ((GtkTextBuffer*) _tmp9_, &expanded.start, _tmp13_, -1);
	_g_free0 (_tmp13_);
	_g_free0 (_tmp11_);
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (clean_text);
}

static void
widgets_markdown_editor_remove_strikethrough_format (WidgetsMarkdownEditor* self,
                                                     GtkTextIter* start,
                                                     GtkTextIter* end)
{
	WidgetsMarkdownEditorExpandedRange expanded = {0};
	GtkTextIter _tmp0_;
	GtkTextIter _tmp1_;
	WidgetsMarkdownEditorExpandedRange _tmp2_ = {0};
	gchar* clean_text = NULL;
	WidgetsMarkdownEditorExpandedRange _tmp3_;
	GtkTextIter _tmp4_;
	WidgetsMarkdownEditorExpandedRange _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	gboolean has_bold = FALSE;
	GtkTextIter _tmp8_;
	GtkTextIter _tmp9_;
	gboolean has_italic = FALSE;
	GtkTextIter _tmp10_;
	GtkTextIter _tmp11_;
	GtkSourceBuffer* _tmp12_;
	gchar* formatted_text = NULL;
	gboolean _tmp13_ = FALSE;
	GtkSourceBuffer* _tmp28_;
	const gchar* _tmp29_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	_tmp0_ = *start;
	_tmp1_ = *end;
	widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp0_, &_tmp1_, &_tmp2_);
	expanded = _tmp2_;
	_tmp3_ = expanded;
	_tmp4_ = _tmp3_.start;
	_tmp5_ = expanded;
	_tmp6_ = _tmp5_.end;
	_tmp7_ = widgets_markdown_editor_get_clean_text_from_range (self, &_tmp4_, &_tmp6_);
	clean_text = _tmp7_;
	_tmp8_ = *start;
	_tmp9_ = *end;
	has_bold = widgets_markdown_editor_text_has_bold_in_range (self, &_tmp8_, &_tmp9_);
	_tmp10_ = *start;
	_tmp11_ = *end;
	has_italic = widgets_markdown_editor_text_has_italic_in_range (self, &_tmp10_, &_tmp11_);
	_tmp12_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp12_, &expanded.start, &expanded.end);
	if (has_bold) {
		_tmp13_ = has_italic;
	} else {
		_tmp13_ = FALSE;
	}
	if (_tmp13_) {
		const gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		gchar* _tmp17_;
		_tmp14_ = clean_text;
		_tmp15_ = g_strconcat ("***", _tmp14_, NULL);
		_tmp16_ = _tmp15_;
		_tmp17_ = g_strconcat (_tmp16_, "***", NULL);
		_g_free0 (formatted_text);
		formatted_text = _tmp17_;
		_g_free0 (_tmp16_);
	} else {
		if (has_bold) {
			const gchar* _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			gchar* _tmp21_;
			_tmp18_ = clean_text;
			_tmp19_ = g_strconcat ("**", _tmp18_, NULL);
			_tmp20_ = _tmp19_;
			_tmp21_ = g_strconcat (_tmp20_, "**", NULL);
			_g_free0 (formatted_text);
			formatted_text = _tmp21_;
			_g_free0 (_tmp20_);
		} else {
			if (has_italic) {
				const gchar* _tmp22_;
				gchar* _tmp23_;
				gchar* _tmp24_;
				gchar* _tmp25_;
				_tmp22_ = clean_text;
				_tmp23_ = g_strconcat ("*", _tmp22_, NULL);
				_tmp24_ = _tmp23_;
				_tmp25_ = g_strconcat (_tmp24_, "*", NULL);
				_g_free0 (formatted_text);
				formatted_text = _tmp25_;
				_g_free0 (_tmp24_);
			} else {
				const gchar* _tmp26_;
				gchar* _tmp27_;
				_tmp26_ = clean_text;
				_tmp27_ = g_strdup (_tmp26_);
				_g_free0 (formatted_text);
				formatted_text = _tmp27_;
			}
		}
	}
	_tmp28_ = self->buffer;
	_tmp29_ = formatted_text;
	gtk_text_buffer_insert ((GtkTextBuffer*) _tmp28_, &expanded.start, _tmp29_, -1);
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (formatted_text);
	_g_free0 (clean_text);
}

static void
widgets_markdown_editor_add_strikethrough_format (WidgetsMarkdownEditor* self,
                                                  GtkTextIter* start,
                                                  GtkTextIter* end,
                                                  const gchar* text)
{
	WidgetsMarkdownEditorExpandedRange expanded = {0};
	GtkTextIter _tmp0_;
	GtkTextIter _tmp1_;
	WidgetsMarkdownEditorExpandedRange _tmp2_ = {0};
	gchar* clean_text = NULL;
	WidgetsMarkdownEditorExpandedRange _tmp3_;
	GtkTextIter _tmp4_;
	WidgetsMarkdownEditorExpandedRange _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	gboolean has_bold = FALSE;
	GtkTextIter _tmp8_;
	GtkTextIter _tmp9_;
	gboolean has_italic = FALSE;
	GtkTextIter _tmp10_;
	GtkTextIter _tmp11_;
	GtkSourceBuffer* _tmp12_;
	gchar* formatted_text = NULL;
	gboolean _tmp13_ = FALSE;
	GtkSourceBuffer* _tmp30_;
	const gchar* _tmp31_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	g_return_if_fail (text != NULL);
	_tmp0_ = *start;
	_tmp1_ = *end;
	widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp0_, &_tmp1_, &_tmp2_);
	expanded = _tmp2_;
	_tmp3_ = expanded;
	_tmp4_ = _tmp3_.start;
	_tmp5_ = expanded;
	_tmp6_ = _tmp5_.end;
	_tmp7_ = widgets_markdown_editor_get_clean_text_from_range (self, &_tmp4_, &_tmp6_);
	clean_text = _tmp7_;
	_tmp8_ = *start;
	_tmp9_ = *end;
	has_bold = widgets_markdown_editor_text_has_bold_in_range (self, &_tmp8_, &_tmp9_);
	_tmp10_ = *start;
	_tmp11_ = *end;
	has_italic = widgets_markdown_editor_text_has_italic_in_range (self, &_tmp10_, &_tmp11_);
	_tmp12_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp12_, &expanded.start, &expanded.end);
	if (has_bold) {
		_tmp13_ = has_italic;
	} else {
		_tmp13_ = FALSE;
	}
	if (_tmp13_) {
		const gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		gchar* _tmp17_;
		_tmp14_ = clean_text;
		_tmp15_ = g_strconcat ("~~***", _tmp14_, NULL);
		_tmp16_ = _tmp15_;
		_tmp17_ = g_strconcat (_tmp16_, "***~~", NULL);
		_g_free0 (formatted_text);
		formatted_text = _tmp17_;
		_g_free0 (_tmp16_);
	} else {
		if (has_bold) {
			const gchar* _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			gchar* _tmp21_;
			_tmp18_ = clean_text;
			_tmp19_ = g_strconcat ("~~**", _tmp18_, NULL);
			_tmp20_ = _tmp19_;
			_tmp21_ = g_strconcat (_tmp20_, "**~~", NULL);
			_g_free0 (formatted_text);
			formatted_text = _tmp21_;
			_g_free0 (_tmp20_);
		} else {
			if (has_italic) {
				const gchar* _tmp22_;
				gchar* _tmp23_;
				gchar* _tmp24_;
				gchar* _tmp25_;
				_tmp22_ = clean_text;
				_tmp23_ = g_strconcat ("~~*", _tmp22_, NULL);
				_tmp24_ = _tmp23_;
				_tmp25_ = g_strconcat (_tmp24_, "*~~", NULL);
				_g_free0 (formatted_text);
				formatted_text = _tmp25_;
				_g_free0 (_tmp24_);
			} else {
				const gchar* _tmp26_;
				gchar* _tmp27_;
				gchar* _tmp28_;
				gchar* _tmp29_;
				_tmp26_ = clean_text;
				_tmp27_ = g_strconcat ("~~", _tmp26_, NULL);
				_tmp28_ = _tmp27_;
				_tmp29_ = g_strconcat (_tmp28_, "~~", NULL);
				_g_free0 (formatted_text);
				formatted_text = _tmp29_;
				_g_free0 (_tmp28_);
			}
		}
	}
	_tmp30_ = self->buffer;
	_tmp31_ = formatted_text;
	gtk_text_buffer_insert ((GtkTextBuffer*) _tmp30_, &expanded.start, _tmp31_, -1);
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (formatted_text);
	_g_free0 (clean_text);
}

static void
widgets_markdown_editor_expand_selection_for_asterisks (WidgetsMarkdownEditor* self,
                                                        GtkTextIter* start,
                                                        GtkTextIter* end,
                                                        WidgetsMarkdownEditorExpandedRange* result)
{
	GtkTextIter expanded_start = {0};
	GtkTextIter _tmp0_;
	GtkTextIter expanded_end = {0};
	GtkTextIter _tmp1_;
	WidgetsMarkdownEditorExpandedRange range = {0};
	GtkTextIter _tmp4_;
	GtkTextIter _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	_tmp0_ = *start;
	expanded_start = _tmp0_;
	_tmp1_ = *end;
	expanded_end = _tmp1_;
	while (TRUE) {
		GtkTextTag* _tmp2_;
		if (!gtk_text_iter_backward_char (&expanded_start)) {
			break;
		}
		_tmp2_ = self->priv->invisible_tag;
		if (gtk_text_iter_has_tag (&expanded_start, _tmp2_)) {
			continue;
		} else {
			gtk_text_iter_forward_char (&expanded_start);
			break;
		}
	}
	while (TRUE) {
		GtkTextTag* _tmp3_;
		if (!gtk_text_iter_forward_char (&expanded_end)) {
			break;
		}
		_tmp3_ = self->priv->invisible_tag;
		if (gtk_text_iter_has_tag (&expanded_end, _tmp3_)) {
			continue;
		} else {
			gtk_text_iter_backward_char (&expanded_end);
			break;
		}
	}
	memset (&range, 0, sizeof (WidgetsMarkdownEditorExpandedRange));
	_tmp4_ = expanded_start;
	range.start = _tmp4_;
	_tmp5_ = expanded_end;
	range.end = _tmp5_;
	*result = range;
	return;
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static gchar*
widgets_markdown_editor_get_clean_text_from_range (WidgetsMarkdownEditor* self,
                                                   GtkTextIter* start,
                                                   GtkTextIter* end)
{
	gchar* text = NULL;
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_;
	GtkTextIter _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (start != NULL, NULL);
	g_return_val_if_fail (end != NULL, NULL);
	_tmp0_ = self->buffer;
	_tmp1_ = *start;
	_tmp2_ = *end;
	_tmp3_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_, FALSE);
	text = _tmp3_;
	_tmp4_ = string_replace (text, "*", "");
	_tmp5_ = _tmp4_;
	_tmp6_ = string_replace (_tmp5_, "~", "");
	_tmp7_ = _tmp6_;
	_tmp8_ = string_replace (_tmp7_, "`", "");
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	result = _tmp9_;
	_g_free0 (text);
	return result;
}

static gboolean
widgets_markdown_editor_text_has_bold_in_range (WidgetsMarkdownEditor* self,
                                                GtkTextIter* start,
                                                GtkTextIter* end)
{
	GtkTextIter iter = {0};
	GtkTextIter _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (start != NULL, FALSE);
	g_return_val_if_fail (end != NULL, FALSE);
	_tmp0_ = *start;
	iter = _tmp0_;
	while (TRUE) {
		GtkTextIter _tmp1_;
		GtkTextTag* _tmp2_;
		_tmp1_ = *end;
		if (!(gtk_text_iter_compare (&iter, &_tmp1_) < 0)) {
			break;
		}
		_tmp2_ = self->priv->bold_tag;
		if (gtk_text_iter_has_tag (&iter, _tmp2_)) {
			result = TRUE;
			return result;
		}
		if (!gtk_text_iter_forward_char (&iter)) {
			break;
		}
	}
	result = FALSE;
	return result;
}

static gboolean
widgets_markdown_editor_text_has_italic_in_range (WidgetsMarkdownEditor* self,
                                                  GtkTextIter* start,
                                                  GtkTextIter* end)
{
	GtkTextIter iter = {0};
	GtkTextIter _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (start != NULL, FALSE);
	g_return_val_if_fail (end != NULL, FALSE);
	_tmp0_ = *start;
	iter = _tmp0_;
	while (TRUE) {
		GtkTextIter _tmp1_;
		GtkTextTag* _tmp2_;
		_tmp1_ = *end;
		if (!(gtk_text_iter_compare (&iter, &_tmp1_) < 0)) {
			break;
		}
		_tmp2_ = self->priv->italic_tag;
		if (gtk_text_iter_has_tag (&iter, _tmp2_)) {
			result = TRUE;
			return result;
		}
		if (!gtk_text_iter_forward_char (&iter)) {
			break;
		}
	}
	result = FALSE;
	return result;
}

static gboolean
widgets_markdown_editor_text_has_strikethrough_in_range (WidgetsMarkdownEditor* self,
                                                         GtkTextIter* start,
                                                         GtkTextIter* end)
{
	GtkTextIter iter = {0};
	GtkTextIter _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (start != NULL, FALSE);
	g_return_val_if_fail (end != NULL, FALSE);
	_tmp0_ = *start;
	iter = _tmp0_;
	while (TRUE) {
		GtkTextIter _tmp1_;
		GtkTextTag* _tmp2_;
		_tmp1_ = *end;
		if (!(gtk_text_iter_compare (&iter, &_tmp1_) < 0)) {
			break;
		}
		_tmp2_ = self->priv->strikethrough_tag;
		if (gtk_text_iter_has_tag (&iter, _tmp2_)) {
			result = TRUE;
			return result;
		}
		if (!gtk_text_iter_forward_char (&iter)) {
			break;
		}
	}
	result = FALSE;
	return result;
}

static void
widgets_markdown_editor_on_selection_lost (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (!_tmp3_) {
		GtkPopover* _tmp4_;
		_tmp4_ = self->priv->format_popover;
		gtk_popover_popdown (_tmp4_);
	}
}

static void
widgets_markdown_editor_on_cursor_moved (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (!_tmp3_) {
		GtkTextMark* cursor = NULL;
		GtkSourceBuffer* _tmp4_;
		GtkTextMark* _tmp5_;
		GtkTextMark* _tmp6_;
		GtkTextIter iter = {0};
		GtkSourceBuffer* _tmp7_;
		GtkTextMark* _tmp8_;
		GtkTextIter _tmp9_ = {0};
		gboolean _tmp10_ = FALSE;
		gboolean _tmp11_ = FALSE;
		gboolean _tmp12_ = FALSE;
		gboolean _tmp13_ = FALSE;
		GtkTextTag* _tmp14_;
		gboolean _tmp19_ = FALSE;
		_tmp4_ = self->buffer;
		_tmp5_ = gtk_text_buffer_get_insert ((GtkTextBuffer*) _tmp4_);
		_tmp6_ = _g_object_ref0 (_tmp5_);
		cursor = _tmp6_;
		_tmp7_ = self->buffer;
		_tmp8_ = cursor;
		gtk_text_buffer_get_iter_at_mark ((GtkTextBuffer*) _tmp7_, &_tmp9_, _tmp8_);
		iter = _tmp9_;
		_tmp14_ = self->priv->bold_tag;
		if (!gtk_text_iter_has_tag (&iter, _tmp14_)) {
			GtkTextTag* _tmp15_;
			_tmp15_ = self->priv->italic_tag;
			_tmp13_ = !gtk_text_iter_has_tag (&iter, _tmp15_);
		} else {
			_tmp13_ = FALSE;
		}
		if (_tmp13_) {
			GtkTextTag* _tmp16_;
			_tmp16_ = self->priv->strikethrough_tag;
			_tmp12_ = !gtk_text_iter_has_tag (&iter, _tmp16_);
		} else {
			_tmp12_ = FALSE;
		}
		if (_tmp12_) {
			GtkTextTag* _tmp17_;
			_tmp17_ = self->priv->code_tag;
			_tmp11_ = !gtk_text_iter_has_tag (&iter, _tmp17_);
		} else {
			_tmp11_ = FALSE;
		}
		if (_tmp11_) {
			GtkTextTag* _tmp18_;
			_tmp18_ = self->priv->link_tag;
			_tmp10_ = !gtk_text_iter_has_tag (&iter, _tmp18_);
		} else {
			_tmp10_ = FALSE;
		}
		if (_tmp10_) {
			_g_object_unref0 (cursor);
			return;
		}
		if (gtk_text_iter_get_line_offset (&iter) == 0) {
			_tmp19_ = TRUE;
		} else {
			_tmp19_ = gtk_text_iter_ends_line (&iter);
		}
		if (_tmp19_) {
			widgets_markdown_editor_clear_cursor_formatting (self);
		}
		_g_object_unref0 (cursor);
	}
}

static void
widgets_markdown_editor_handle_focus_in (WidgetsMarkdownEditor* self)
{
	ServicesEventBus* _tmp0_;
	ServicesEventBus* _tmp1_;
	GtkTextView* _tmp12_;
	g_return_if_fail (self != NULL);
	_tmp0_ = services_event_bus_get_default ();
	_tmp1_ = _tmp0_;
	g_signal_emit_by_name (_tmp1_, "disconnect-typing-accel");
	_g_object_unref0 (_tmp1_);
	if (self->priv->showing_placeholder) {
		GtkTextIter start = {0};
		GtkTextIter end = {0};
		GtkSourceBuffer* _tmp2_;
		GtkTextIter _tmp3_ = {0};
		GtkTextIter _tmp4_ = {0};
		gchar* current_text = NULL;
		GtkSourceBuffer* _tmp5_;
		GtkTextIter _tmp6_;
		GtkTextIter _tmp7_;
		gchar* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		_tmp2_ = self->buffer;
		gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp2_, &_tmp3_, &_tmp4_);
		start = _tmp3_;
		end = _tmp4_;
		_tmp5_ = self->buffer;
		_tmp6_ = start;
		_tmp7_ = end;
		_tmp8_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp5_, &_tmp6_, &_tmp7_, FALSE);
		current_text = _tmp8_;
		_tmp9_ = current_text;
		_tmp10_ = self->priv->_placeholder_text;
		if (g_strcmp0 (_tmp9_, _tmp10_) == 0) {
			GtkSourceBuffer* _tmp11_;
			_tmp11_ = self->buffer;
			gtk_text_buffer_set_text ((GtkTextBuffer*) _tmp11_, "", -1);
		}
		self->priv->showing_placeholder = FALSE;
		_g_free0 (current_text);
	}
	_tmp12_ = self->text_view;
	gtk_widget_grab_focus ((GtkWidget*) _tmp12_);
	g_signal_emit (self, widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_FOCUS_IN_SIGNAL], 0);
}

static void
widgets_markdown_editor_handle_focus_out (WidgetsMarkdownEditor* self)
{
	ServicesEventBus* _tmp0_;
	ServicesEventBus* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = services_event_bus_get_default ();
	_tmp1_ = _tmp0_;
	g_signal_emit_by_name (_tmp1_, "connect-typing-accel");
	_g_object_unref0 (_tmp1_);
	widgets_markdown_editor_update_placeholder_visibility (self);
	g_signal_emit (self, widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_FOCUS_OUT_SIGNAL], 0);
}

static gboolean
widgets_markdown_editor_on_key_pressed (WidgetsMarkdownEditor* self,
                                        guint keyval,
                                        guint keycode,
                                        GdkModifierType state)
{
	GtkPopover* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->format_popover;
	_tmp1_ = gtk_widget_get_visible ((GtkWidget*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		GtkPopover* _tmp3_;
		_tmp3_ = self->priv->format_popover;
		gtk_popover_popdown (_tmp3_);
	}
	if (keyval == GDK_KEY_Escape) {
		g_signal_emit (self, widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_ESCAPE_PRESSED_SIGNAL], 0);
		result = TRUE;
		return result;
	}
	if (keyval == GDK_KEY_Return) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = keyval == GDK_KEY_KP_Enter;
	}
	if (_tmp4_) {
		if (widgets_markdown_editor_handle_list_enter (self)) {
			result = TRUE;
			return result;
		}
		widgets_markdown_editor_clear_cursor_formatting (self);
		g_signal_emit (self, widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_RETURN_PRESSED_SIGNAL], 0);
	}
	if (keyval == GDK_KEY_space) {
		widgets_markdown_editor_clear_cursor_formatting (self);
	}
	if (keyval >= ((guint) 32)) {
		_tmp5_ = keyval <= ((guint) 126);
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		widgets_markdown_editor_clear_cursor_formatting (self);
	}
	result = FALSE;
	return result;
}

static void
widgets_markdown_editor_clear_cursor_formatting (WidgetsMarkdownEditor* self)
{
	GtkTextMark* cursor = NULL;
	GtkSourceBuffer* _tmp0_;
	GtkTextMark* _tmp1_;
	GtkTextMark* _tmp2_;
	GtkTextIter iter = {0};
	GtkSourceBuffer* _tmp3_;
	GtkTextMark* _tmp4_;
	GtkTextIter _tmp5_ = {0};
	gboolean _tmp6_ = FALSE;
	gboolean _tmp7_ = FALSE;
	gboolean _tmp8_ = FALSE;
	gboolean _tmp9_ = FALSE;
	GtkTextTag* _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp1_ = gtk_text_buffer_get_insert ((GtkTextBuffer*) _tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	cursor = _tmp2_;
	_tmp3_ = self->buffer;
	_tmp4_ = cursor;
	gtk_text_buffer_get_iter_at_mark ((GtkTextBuffer*) _tmp3_, &_tmp5_, _tmp4_);
	iter = _tmp5_;
	_tmp10_ = self->priv->bold_tag;
	if (gtk_text_iter_has_tag (&iter, _tmp10_)) {
		_tmp9_ = TRUE;
	} else {
		GtkTextTag* _tmp11_;
		_tmp11_ = self->priv->italic_tag;
		_tmp9_ = gtk_text_iter_has_tag (&iter, _tmp11_);
	}
	if (_tmp9_) {
		_tmp8_ = TRUE;
	} else {
		GtkTextTag* _tmp12_;
		_tmp12_ = self->priv->strikethrough_tag;
		_tmp8_ = gtk_text_iter_has_tag (&iter, _tmp12_);
	}
	if (_tmp8_) {
		_tmp7_ = TRUE;
	} else {
		GtkTextTag* _tmp13_;
		_tmp13_ = self->priv->code_tag;
		_tmp7_ = gtk_text_iter_has_tag (&iter, _tmp13_);
	}
	if (_tmp7_) {
		_tmp6_ = TRUE;
	} else {
		GtkTextTag* _tmp14_;
		_tmp14_ = self->priv->link_tag;
		_tmp6_ = gtk_text_iter_has_tag (&iter, _tmp14_);
	}
	if (_tmp6_) {
		GtkTextIter next_iter = {0};
		GtkTextIter _tmp15_;
		GtkSourceBuffer* _tmp16_;
		GtkTextTag* _tmp17_;
		GtkTextIter _tmp18_;
		GtkTextIter _tmp19_;
		GtkSourceBuffer* _tmp20_;
		GtkTextTag* _tmp21_;
		GtkTextIter _tmp22_;
		GtkTextIter _tmp23_;
		GtkSourceBuffer* _tmp24_;
		GtkTextTag* _tmp25_;
		GtkTextIter _tmp26_;
		GtkTextIter _tmp27_;
		GtkSourceBuffer* _tmp28_;
		GtkTextTag* _tmp29_;
		GtkTextIter _tmp30_;
		GtkTextIter _tmp31_;
		GtkSourceBuffer* _tmp32_;
		GtkTextTag* _tmp33_;
		GtkTextIter _tmp34_;
		GtkTextIter _tmp35_;
		_tmp15_ = iter;
		next_iter = _tmp15_;
		gtk_text_iter_forward_char (&next_iter);
		_tmp16_ = self->buffer;
		_tmp17_ = self->priv->bold_tag;
		_tmp18_ = iter;
		_tmp19_ = next_iter;
		gtk_text_buffer_remove_tag ((GtkTextBuffer*) _tmp16_, _tmp17_, &_tmp18_, &_tmp19_);
		_tmp20_ = self->buffer;
		_tmp21_ = self->priv->italic_tag;
		_tmp22_ = iter;
		_tmp23_ = next_iter;
		gtk_text_buffer_remove_tag ((GtkTextBuffer*) _tmp20_, _tmp21_, &_tmp22_, &_tmp23_);
		_tmp24_ = self->buffer;
		_tmp25_ = self->priv->strikethrough_tag;
		_tmp26_ = iter;
		_tmp27_ = next_iter;
		gtk_text_buffer_remove_tag ((GtkTextBuffer*) _tmp24_, _tmp25_, &_tmp26_, &_tmp27_);
		_tmp28_ = self->buffer;
		_tmp29_ = self->priv->code_tag;
		_tmp30_ = iter;
		_tmp31_ = next_iter;
		gtk_text_buffer_remove_tag ((GtkTextBuffer*) _tmp28_, _tmp29_, &_tmp30_, &_tmp31_);
		_tmp32_ = self->buffer;
		_tmp33_ = self->priv->link_tag;
		_tmp34_ = iter;
		_tmp35_ = next_iter;
		gtk_text_buffer_remove_tag ((GtkTextBuffer*) _tmp32_, _tmp33_, &_tmp34_, &_tmp35_);
	}
	_g_object_unref0 (cursor);
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static gboolean
widgets_markdown_editor_handle_list_enter (WidgetsMarkdownEditor* self)
{
	GtkTextMark* cursor = NULL;
	GtkSourceBuffer* _tmp0_;
	GtkTextMark* _tmp1_;
	GtkTextMark* _tmp2_;
	GtkTextIter iter = {0};
	GtkSourceBuffer* _tmp3_;
	GtkTextMark* _tmp4_;
	GtkTextIter _tmp5_ = {0};
	gint line_num = 0;
	GtkTextIter line_start = {0};
	GtkTextIter line_end = {0};
	GtkSourceBuffer* _tmp6_;
	GtkTextIter _tmp7_ = {0};
	GtkTextIter _tmp8_;
	gchar* line_text = NULL;
	GtkSourceBuffer* _tmp9_;
	GtkTextIter _tmp10_;
	GtkTextIter _tmp11_;
	gchar* _tmp12_;
	gboolean _tmp13_ = FALSE;
	const gchar* _tmp14_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->buffer;
	_tmp1_ = gtk_text_buffer_get_insert ((GtkTextBuffer*) _tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	cursor = _tmp2_;
	_tmp3_ = self->buffer;
	_tmp4_ = cursor;
	gtk_text_buffer_get_iter_at_mark ((GtkTextBuffer*) _tmp3_, &_tmp5_, _tmp4_);
	iter = _tmp5_;
	line_num = gtk_text_iter_get_line (&iter);
	_tmp6_ = self->buffer;
	gtk_text_buffer_get_iter_at_line ((GtkTextBuffer*) _tmp6_, &_tmp7_, line_num);
	line_start = _tmp7_;
	_tmp8_ = line_start;
	line_end = _tmp8_;
	if (!gtk_text_iter_ends_line (&line_end)) {
		gtk_text_iter_forward_to_line_end (&line_end);
	}
	_tmp9_ = self->buffer;
	_tmp10_ = line_start;
	_tmp11_ = line_end;
	_tmp12_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp9_, &_tmp10_, &_tmp11_, FALSE);
	line_text = _tmp12_;
	_tmp14_ = line_text;
	if (g_str_has_prefix (_tmp14_, "- ")) {
		_tmp13_ = TRUE;
	} else {
		const gchar* _tmp15_;
		_tmp15_ = line_text;
		_tmp13_ = g_str_has_prefix (_tmp15_, "• ");
	}
	if (_tmp13_) {
		gchar* content = NULL;
		const gchar* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		gchar* _tmp19_;
		gchar* _tmp20_;
		const gchar* _tmp21_;
		_tmp16_ = line_text;
		_tmp17_ = string_substring (_tmp16_, (glong) 2, (glong) -1);
		_tmp18_ = _tmp17_;
		_tmp19_ = string_strip (_tmp18_);
		_tmp20_ = _tmp19_;
		_g_free0 (_tmp18_);
		content = _tmp20_;
		_tmp21_ = content;
		if (g_strcmp0 (_tmp21_, "") == 0) {
			GtkSourceBuffer* _tmp22_;
			_tmp22_ = self->buffer;
			gtk_text_buffer_delete ((GtkTextBuffer*) _tmp22_, &line_start, &line_end);
		} else {
			GtkSourceBuffer* _tmp23_;
			_tmp23_ = self->buffer;
			gtk_text_buffer_insert_at_cursor ((GtkTextBuffer*) _tmp23_, "\n- ", -1);
		}
		result = TRUE;
		_g_free0 (content);
		_g_free0 (line_text);
		_g_object_unref0 (cursor);
		return result;
	}
	{
		GRegex* regex = NULL;
		GRegex* _tmp24_;
		GMatchInfo* match_info = NULL;
		GRegex* _tmp26_;
		const gchar* _tmp27_;
		GMatchInfo* _tmp28_ = NULL;
		gboolean _tmp29_;
		_tmp24_ = g_regex_new ("^(\\d+)\\. (.*)$", 0, 0, &_inner_error0_);
		regex = _tmp24_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp25_ = FALSE;
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (line_text);
			_g_object_unref0 (cursor);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp25_;
		}
		_tmp26_ = regex;
		_tmp27_ = line_text;
		_tmp29_ = g_regex_match (_tmp26_, _tmp27_, 0, &_tmp28_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp28_;
		if (_tmp29_) {
			gchar* number_str = NULL;
			GMatchInfo* _tmp30_;
			gchar* _tmp31_;
			gchar* content = NULL;
			GMatchInfo* _tmp32_;
			gchar* _tmp33_;
			gchar* _tmp34_;
			gchar* _tmp35_;
			gchar* _tmp36_;
			gint number = 0;
			const gchar* _tmp37_;
			const gchar* _tmp38_;
			_tmp30_ = match_info;
			_tmp31_ = g_match_info_fetch (_tmp30_, 1);
			number_str = _tmp31_;
			_tmp32_ = match_info;
			_tmp33_ = g_match_info_fetch (_tmp32_, 2);
			_tmp34_ = _tmp33_;
			_tmp35_ = string_strip (_tmp34_);
			_tmp36_ = _tmp35_;
			_g_free0 (_tmp34_);
			content = _tmp36_;
			_tmp37_ = number_str;
			number = atoi (_tmp37_);
			_tmp38_ = content;
			if (g_strcmp0 (_tmp38_, "") == 0) {
				GtkSourceBuffer* _tmp39_;
				_tmp39_ = self->buffer;
				gtk_text_buffer_delete ((GtkTextBuffer*) _tmp39_, &line_start, &line_end);
			} else {
				gchar* next_item = NULL;
				gchar* _tmp40_;
				GtkSourceBuffer* _tmp41_;
				const gchar* _tmp42_;
				_tmp40_ = g_strdup_printf ("\n%d. ", number + 1);
				next_item = _tmp40_;
				_tmp41_ = self->buffer;
				_tmp42_ = next_item;
				gtk_text_buffer_insert_at_cursor ((GtkTextBuffer*) _tmp41_, _tmp42_, -1);
				_g_free0 (next_item);
			}
			result = TRUE;
			_g_free0 (content);
			_g_free0 (number_str);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (regex);
			_g_free0 (line_text);
			_g_object_unref0 (cursor);
			return result;
		}
		_g_match_info_unref0 (match_info);
		_g_regex_unref0 (regex);
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError* e = NULL;
		GError* _tmp43_;
		const gchar* _tmp44_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp43_ = e;
		_tmp44_ = _tmp43_->message;
		g_warning ("MarkdownEditor.vala:821: Error in list regex: %s", _tmp44_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp45_ = FALSE;
		_g_free0 (line_text);
		_g_object_unref0 (cursor);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp45_;
	}
	result = FALSE;
	_g_free0 (line_text);
	_g_object_unref0 (cursor);
	return result;
}

static void
widgets_markdown_editor_update_placeholder_visibility (WidgetsMarkdownEditor* self)
{
	gchar* real_text = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	gboolean _tmp6_ = FALSE;
	GtkTextView* _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = widgets_markdown_editor_get_real_text (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = string_strip (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	real_text = _tmp3_;
	_tmp7_ = self->text_view;
	g_object_get ((GtkWidget*) _tmp7_, "has-focus", &_tmp8_, NULL);
	_tmp9_ = _tmp8_;
	if (!_tmp9_) {
		const gchar* _tmp10_;
		_tmp10_ = real_text;
		_tmp6_ = g_strcmp0 (_tmp10_, "") == 0;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		const gchar* _tmp11_;
		_tmp11_ = self->priv->_placeholder_text;
		_tmp5_ = g_strcmp0 (_tmp11_, "") != 0;
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		_tmp4_ = !self->priv->showing_placeholder;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		GtkSourceBuffer* _tmp12_;
		const gchar* _tmp13_;
		GtkTextIter start = {0};
		GtkTextIter end = {0};
		GtkSourceBuffer* _tmp14_;
		GtkTextIter _tmp15_ = {0};
		GtkTextIter _tmp16_ = {0};
		GtkSourceBuffer* _tmp17_;
		GtkTextTag* _tmp18_;
		GtkTextIter _tmp19_;
		GtkTextIter _tmp20_;
		self->priv->showing_placeholder = TRUE;
		_tmp12_ = self->buffer;
		_tmp13_ = self->priv->_placeholder_text;
		gtk_text_buffer_set_text ((GtkTextBuffer*) _tmp12_, _tmp13_, -1);
		_tmp14_ = self->buffer;
		gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp14_, &_tmp15_, &_tmp16_);
		start = _tmp15_;
		end = _tmp16_;
		_tmp17_ = self->buffer;
		_tmp18_ = self->priv->placeholder_tag;
		_tmp19_ = start;
		_tmp20_ = end;
		gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp17_, _tmp18_, &_tmp19_, &_tmp20_);
	} else {
		gboolean _tmp21_ = FALSE;
		if (self->priv->showing_placeholder) {
			gboolean _tmp22_ = FALSE;
			GtkTextView* _tmp23_;
			gboolean _tmp24_;
			gboolean _tmp25_;
			_tmp23_ = self->text_view;
			g_object_get ((GtkWidget*) _tmp23_, "has-focus", &_tmp24_, NULL);
			_tmp25_ = _tmp24_;
			if (_tmp25_) {
				_tmp22_ = TRUE;
			} else {
				const gchar* _tmp26_;
				_tmp26_ = real_text;
				_tmp22_ = g_strcmp0 (_tmp26_, "") != 0;
			}
			_tmp21_ = _tmp22_;
		} else {
			_tmp21_ = FALSE;
		}
		if (_tmp21_) {
			GtkTextView* _tmp27_;
			gboolean _tmp28_;
			gboolean _tmp29_;
			self->priv->showing_placeholder = FALSE;
			_tmp27_ = self->text_view;
			g_object_get ((GtkWidget*) _tmp27_, "has-focus", &_tmp28_, NULL);
			_tmp29_ = _tmp28_;
			if (_tmp29_) {
				GtkSourceBuffer* _tmp30_;
				_tmp30_ = self->buffer;
				gtk_text_buffer_set_text ((GtkTextBuffer*) _tmp30_, "", -1);
			}
		}
	}
	_g_free0 (real_text);
}

static gchar*
widgets_markdown_editor_get_real_text (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp1_;
	GtkTextIter _tmp2_ = {0};
	GtkTextIter _tmp3_ = {0};
	GtkSourceBuffer* _tmp4_;
	GtkTextIter _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (self->priv->showing_placeholder) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("");
		result = _tmp0_;
		return result;
	}
	_tmp1_ = self->buffer;
	gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp1_, &_tmp2_, &_tmp3_);
	start = _tmp2_;
	end = _tmp3_;
	_tmp4_ = self->buffer;
	_tmp5_ = start;
	_tmp6_ = end;
	_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, TRUE);
	result = _tmp7_;
	return result;
}

static void
widgets_markdown_editor_on_buffer_changed (WidgetsMarkdownEditor* self)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (!self->priv->showing_placeholder) {
		_tmp0_ = !self->priv->updating_programmatically;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gboolean _tmp1_;
		gboolean _tmp2_;
		GtkTextIter start = {0};
		GtkTextIter end = {0};
		GtkSourceBuffer* _tmp3_;
		GtkTextIter _tmp4_ = {0};
		GtkTextIter _tmp5_ = {0};
		GtkSourceBuffer* _tmp6_;
		GtkTextIter _tmp7_;
		GtkTextIter _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp1_ = widgets_markdown_editor_get_text_mode (self);
		_tmp2_ = _tmp1_;
		if (!_tmp2_) {
			widgets_markdown_editor_apply_markdown_formatting (self);
		}
		_tmp3_ = self->buffer;
		gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp3_, &_tmp4_, &_tmp5_);
		start = _tmp4_;
		end = _tmp5_;
		_tmp6_ = self->buffer;
		_tmp7_ = start;
		_tmp8_ = end;
		_tmp9_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp6_, &_tmp7_, &_tmp8_, TRUE);
		_tmp10_ = _tmp9_;
		g_signal_emit (self, widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_TEXT_CHANGED_SIGNAL], 0, _tmp10_);
		_g_free0 (_tmp10_);
	}
}

static void
widgets_markdown_editor_update_mode (WidgetsMarkdownEditor* self)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = widgets_markdown_editor_get_text_mode (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		GtkTextIter start = {0};
		GtkTextIter end = {0};
		GtkSourceBuffer* _tmp2_;
		GtkTextIter _tmp3_ = {0};
		GtkTextIter _tmp4_ = {0};
		GtkSourceBuffer* _tmp5_;
		GtkTextIter _tmp6_;
		GtkTextIter _tmp7_;
		GtkPopover* _tmp8_;
		_tmp2_ = self->buffer;
		gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp2_, &_tmp3_, &_tmp4_);
		start = _tmp3_;
		end = _tmp4_;
		_tmp5_ = self->buffer;
		_tmp6_ = start;
		_tmp7_ = end;
		gtk_text_buffer_remove_all_tags ((GtkTextBuffer*) _tmp5_, &_tmp6_, &_tmp7_);
		_tmp8_ = self->priv->format_popover;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp8_, FALSE);
	} else {
		GtkPopover* _tmp9_;
		_tmp9_ = self->priv->format_popover;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp9_, TRUE);
		widgets_markdown_editor_apply_markdown_formatting (self);
	}
}

static void
_widgets_markdown_editor_on_buffer_changed_gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                                                    gpointer self)
{
	widgets_markdown_editor_on_buffer_changed ((WidgetsMarkdownEditor*) self);
}

static void
widgets_markdown_editor_apply_markdown_formatting (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	GtkSourceBuffer* _tmp3_;
	GtkTextIter _tmp4_;
	GtkTextIter _tmp5_;
	gchar* text = NULL;
	GtkSourceBuffer* _tmp6_;
	GtkTextIter _tmp7_;
	GtkTextIter _tmp8_;
	gchar* _tmp9_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	_tmp3_ = self->buffer;
	_tmp4_ = start;
	_tmp5_ = end;
	gtk_text_buffer_remove_all_tags ((GtkTextBuffer*) _tmp3_, &_tmp4_, &_tmp5_);
	_tmp6_ = self->buffer;
	_tmp7_ = start;
	_tmp8_ = end;
	_tmp9_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp6_, &_tmp7_, &_tmp8_, TRUE);
	text = _tmp9_;
	{
		GRegex* bold_italic_regex = NULL;
		GRegex* _tmp10_;
		GMatchInfo* match_info = NULL;
		GRegex* _tmp11_;
		const gchar* _tmp12_;
		GMatchInfo* _tmp13_ = NULL;
		gboolean _tmp14_;
		GRegex* bold_regex = NULL;
		GRegex* _tmp53_;
		GRegex* _tmp54_;
		const gchar* _tmp55_;
		GMatchInfo* _tmp56_ = NULL;
		gboolean _tmp57_;
		GRegex* italic_regex = NULL;
		GRegex* _tmp92_;
		GRegex* _tmp93_;
		const gchar* _tmp94_;
		GMatchInfo* _tmp95_ = NULL;
		gboolean _tmp96_;
		GRegex* strikethrough_regex = NULL;
		GRegex* _tmp131_;
		GRegex* _tmp132_;
		const gchar* _tmp133_;
		GMatchInfo* _tmp134_ = NULL;
		gboolean _tmp135_;
		GRegex* h1_regex = NULL;
		GRegex* _tmp170_;
		GRegex* _tmp171_;
		const gchar* _tmp172_;
		GMatchInfo* _tmp173_ = NULL;
		gboolean _tmp174_;
		GRegex* h2_regex = NULL;
		GRegex* _tmp203_;
		GRegex* _tmp204_;
		const gchar* _tmp205_;
		GMatchInfo* _tmp206_ = NULL;
		gboolean _tmp207_;
		GRegex* code_regex = NULL;
		GRegex* _tmp236_;
		GRegex* _tmp237_;
		const gchar* _tmp238_;
		GMatchInfo* _tmp239_ = NULL;
		gboolean _tmp240_;
		GRegex* link_regex = NULL;
		GRegex* _tmp275_;
		GRegex* _tmp276_;
		const gchar* _tmp277_;
		GMatchInfo* _tmp278_ = NULL;
		gboolean _tmp279_;
		GRegex* unordered_list_regex = NULL;
		GRegex* _tmp326_;
		GRegex* _tmp327_;
		const gchar* _tmp328_;
		GMatchInfo* _tmp329_ = NULL;
		gboolean _tmp330_;
		GRegex* ordered_list_regex = NULL;
		GRegex* _tmp366_;
		GRegex* _tmp367_;
		const gchar* _tmp368_;
		GMatchInfo* _tmp369_ = NULL;
		gboolean _tmp370_;
		GRegex* plain_url_regex = NULL;
		GRegex* _tmp393_;
		GRegex* _tmp394_;
		const gchar* _tmp395_;
		GMatchInfo* _tmp396_ = NULL;
		gboolean _tmp397_;
		_tmp10_ = g_regex_new ("\\*\\*\\*([^*]+)\\*\\*\\*", 0, 0, &_inner_error0_);
		bold_italic_regex = _tmp10_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp11_ = bold_italic_regex;
		_tmp12_ = text;
		_tmp14_ = g_regex_match (_tmp11_, _tmp12_, 0, &_tmp13_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp13_;
		if (_tmp14_) {
			{
				gboolean _tmp15_ = FALSE;
				_tmp15_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp18_;
					gint _tmp19_ = 0;
					gint _tmp20_ = 0;
					gint start_chars = 0;
					const gchar* _tmp21_;
					gchar* _tmp22_;
					gchar* _tmp23_;
					gint _tmp24_;
					gint end_chars = 0;
					const gchar* _tmp25_;
					gchar* _tmp26_;
					gchar* _tmp27_;
					gint _tmp28_;
					GtkTextIter bi_start = {0};
					GtkTextIter bi_end = {0};
					GtkSourceBuffer* _tmp29_;
					GtkTextIter _tmp30_ = {0};
					GtkSourceBuffer* _tmp31_;
					GtkTextIter _tmp32_ = {0};
					GtkTextIter ast_end = {0};
					GtkTextIter _tmp33_;
					GtkSourceBuffer* _tmp34_;
					GtkTextTag* _tmp35_;
					GtkTextIter _tmp36_;
					GtkTextIter _tmp37_;
					GtkTextIter text_start = {0};
					GtkTextIter _tmp38_;
					GtkTextIter text_end = {0};
					GtkTextIter _tmp39_;
					GtkSourceBuffer* _tmp40_;
					GtkTextTag* _tmp41_;
					GtkTextIter _tmp42_;
					GtkTextIter _tmp43_;
					GtkSourceBuffer* _tmp44_;
					GtkTextTag* _tmp45_;
					GtkTextIter _tmp46_;
					GtkTextIter _tmp47_;
					GtkTextIter last_ast_start = {0};
					GtkTextIter _tmp48_;
					GtkSourceBuffer* _tmp49_;
					GtkTextTag* _tmp50_;
					GtkTextIter _tmp51_;
					GtkTextIter _tmp52_;
					if (!_tmp15_) {
						gboolean _tmp16_ = FALSE;
						GMatchInfo* _tmp17_;
						_tmp17_ = match_info;
						_tmp16_ = g_match_info_next (_tmp17_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp16_) {
							break;
						}
					}
					_tmp15_ = FALSE;
					_tmp18_ = match_info;
					g_match_info_fetch_pos (_tmp18_, 0, &_tmp19_, &_tmp20_);
					start_pos = _tmp19_;
					end_pos = _tmp20_;
					_tmp21_ = text;
					_tmp22_ = string_substring (_tmp21_, (glong) 0, (glong) start_pos);
					_tmp23_ = _tmp22_;
					_tmp24_ = g_utf8_strlen (_tmp23_, (gssize) -1);
					_g_free0 (_tmp23_);
					start_chars = _tmp24_;
					_tmp25_ = text;
					_tmp26_ = string_substring (_tmp25_, (glong) 0, (glong) end_pos);
					_tmp27_ = _tmp26_;
					_tmp28_ = g_utf8_strlen (_tmp27_, (gssize) -1);
					_g_free0 (_tmp27_);
					end_chars = _tmp28_;
					_tmp29_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp29_, &_tmp30_, start_chars);
					bi_start = _tmp30_;
					_tmp31_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp31_, &_tmp32_, end_chars);
					bi_end = _tmp32_;
					_tmp33_ = bi_start;
					ast_end = _tmp33_;
					gtk_text_iter_forward_chars (&ast_end, 3);
					_tmp34_ = self->buffer;
					_tmp35_ = self->priv->invisible_tag;
					_tmp36_ = bi_start;
					_tmp37_ = ast_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp34_, _tmp35_, &_tmp36_, &_tmp37_);
					_tmp38_ = bi_start;
					text_start = _tmp38_;
					gtk_text_iter_forward_chars (&text_start, 3);
					_tmp39_ = bi_end;
					text_end = _tmp39_;
					gtk_text_iter_backward_chars (&text_end, 3);
					_tmp40_ = self->buffer;
					_tmp41_ = self->priv->bold_tag;
					_tmp42_ = text_start;
					_tmp43_ = text_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp40_, _tmp41_, &_tmp42_, &_tmp43_);
					_tmp44_ = self->buffer;
					_tmp45_ = self->priv->italic_tag;
					_tmp46_ = text_start;
					_tmp47_ = text_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp44_, _tmp45_, &_tmp46_, &_tmp47_);
					_tmp48_ = bi_end;
					last_ast_start = _tmp48_;
					gtk_text_iter_backward_chars (&last_ast_start, 3);
					_tmp49_ = self->buffer;
					_tmp50_ = self->priv->invisible_tag;
					_tmp51_ = last_ast_start;
					_tmp52_ = bi_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp49_, _tmp50_, &_tmp51_, &_tmp52_);
				}
			}
		}
		_tmp53_ = g_regex_new ("(?<!\\*)\\*\\*([^*]+)\\*\\*(?!\\*)", 0, 0, &_inner_error0_);
		bold_regex = _tmp53_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp54_ = bold_regex;
		_tmp55_ = text;
		_tmp57_ = g_regex_match (_tmp54_, _tmp55_, 0, &_tmp56_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp56_;
		if (_tmp57_) {
			{
				gboolean _tmp58_ = FALSE;
				_tmp58_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp61_;
					gint _tmp62_ = 0;
					gint _tmp63_ = 0;
					gint start_chars = 0;
					const gchar* _tmp64_;
					gchar* _tmp65_;
					gchar* _tmp66_;
					gint _tmp67_;
					gint end_chars = 0;
					const gchar* _tmp68_;
					gchar* _tmp69_;
					gchar* _tmp70_;
					gint _tmp71_;
					GtkTextIter bold_start = {0};
					GtkTextIter bold_end = {0};
					GtkSourceBuffer* _tmp72_;
					GtkTextIter _tmp73_ = {0};
					GtkSourceBuffer* _tmp74_;
					GtkTextIter _tmp75_ = {0};
					GtkTextIter ast_end = {0};
					GtkTextIter _tmp76_;
					GtkSourceBuffer* _tmp77_;
					GtkTextTag* _tmp78_;
					GtkTextIter _tmp79_;
					GtkTextIter _tmp80_;
					GtkTextIter text_start = {0};
					GtkTextIter _tmp81_;
					GtkTextIter text_end = {0};
					GtkTextIter _tmp82_;
					GtkSourceBuffer* _tmp83_;
					GtkTextTag* _tmp84_;
					GtkTextIter _tmp85_;
					GtkTextIter _tmp86_;
					GtkTextIter last_ast_start = {0};
					GtkTextIter _tmp87_;
					GtkSourceBuffer* _tmp88_;
					GtkTextTag* _tmp89_;
					GtkTextIter _tmp90_;
					GtkTextIter _tmp91_;
					if (!_tmp58_) {
						gboolean _tmp59_ = FALSE;
						GMatchInfo* _tmp60_;
						_tmp60_ = match_info;
						_tmp59_ = g_match_info_next (_tmp60_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp59_) {
							break;
						}
					}
					_tmp58_ = FALSE;
					_tmp61_ = match_info;
					g_match_info_fetch_pos (_tmp61_, 0, &_tmp62_, &_tmp63_);
					start_pos = _tmp62_;
					end_pos = _tmp63_;
					_tmp64_ = text;
					_tmp65_ = string_substring (_tmp64_, (glong) 0, (glong) start_pos);
					_tmp66_ = _tmp65_;
					_tmp67_ = g_utf8_strlen (_tmp66_, (gssize) -1);
					_g_free0 (_tmp66_);
					start_chars = _tmp67_;
					_tmp68_ = text;
					_tmp69_ = string_substring (_tmp68_, (glong) 0, (glong) end_pos);
					_tmp70_ = _tmp69_;
					_tmp71_ = g_utf8_strlen (_tmp70_, (gssize) -1);
					_g_free0 (_tmp70_);
					end_chars = _tmp71_;
					_tmp72_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp72_, &_tmp73_, start_chars);
					bold_start = _tmp73_;
					_tmp74_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp74_, &_tmp75_, end_chars);
					bold_end = _tmp75_;
					_tmp76_ = bold_start;
					ast_end = _tmp76_;
					gtk_text_iter_forward_chars (&ast_end, 2);
					_tmp77_ = self->buffer;
					_tmp78_ = self->priv->invisible_tag;
					_tmp79_ = bold_start;
					_tmp80_ = ast_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp77_, _tmp78_, &_tmp79_, &_tmp80_);
					_tmp81_ = bold_start;
					text_start = _tmp81_;
					gtk_text_iter_forward_chars (&text_start, 2);
					_tmp82_ = bold_end;
					text_end = _tmp82_;
					gtk_text_iter_backward_chars (&text_end, 2);
					_tmp83_ = self->buffer;
					_tmp84_ = self->priv->bold_tag;
					_tmp85_ = text_start;
					_tmp86_ = text_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp83_, _tmp84_, &_tmp85_, &_tmp86_);
					_tmp87_ = bold_end;
					last_ast_start = _tmp87_;
					gtk_text_iter_backward_chars (&last_ast_start, 2);
					_tmp88_ = self->buffer;
					_tmp89_ = self->priv->invisible_tag;
					_tmp90_ = last_ast_start;
					_tmp91_ = bold_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp88_, _tmp89_, &_tmp90_, &_tmp91_);
				}
			}
		}
		_tmp92_ = g_regex_new ("(?<!\\*)\\*([^*]+)\\*(?!\\*)", 0, 0, &_inner_error0_);
		italic_regex = _tmp92_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (bold_regex);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp93_ = italic_regex;
		_tmp94_ = text;
		_tmp96_ = g_regex_match (_tmp93_, _tmp94_, 0, &_tmp95_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp95_;
		if (_tmp96_) {
			{
				gboolean _tmp97_ = FALSE;
				_tmp97_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp100_;
					gint _tmp101_ = 0;
					gint _tmp102_ = 0;
					gint start_chars = 0;
					const gchar* _tmp103_;
					gchar* _tmp104_;
					gchar* _tmp105_;
					gint _tmp106_;
					gint end_chars = 0;
					const gchar* _tmp107_;
					gchar* _tmp108_;
					gchar* _tmp109_;
					gint _tmp110_;
					GtkTextIter italic_start = {0};
					GtkTextIter italic_end = {0};
					GtkSourceBuffer* _tmp111_;
					GtkTextIter _tmp112_ = {0};
					GtkSourceBuffer* _tmp113_;
					GtkTextIter _tmp114_ = {0};
					GtkTextIter ast_end = {0};
					GtkTextIter _tmp115_;
					GtkSourceBuffer* _tmp116_;
					GtkTextTag* _tmp117_;
					GtkTextIter _tmp118_;
					GtkTextIter _tmp119_;
					GtkTextIter text_start = {0};
					GtkTextIter _tmp120_;
					GtkTextIter text_end = {0};
					GtkTextIter _tmp121_;
					GtkSourceBuffer* _tmp122_;
					GtkTextTag* _tmp123_;
					GtkTextIter _tmp124_;
					GtkTextIter _tmp125_;
					GtkTextIter last_ast_start = {0};
					GtkTextIter _tmp126_;
					GtkSourceBuffer* _tmp127_;
					GtkTextTag* _tmp128_;
					GtkTextIter _tmp129_;
					GtkTextIter _tmp130_;
					if (!_tmp97_) {
						gboolean _tmp98_ = FALSE;
						GMatchInfo* _tmp99_;
						_tmp99_ = match_info;
						_tmp98_ = g_match_info_next (_tmp99_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (italic_regex);
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp98_) {
							break;
						}
					}
					_tmp97_ = FALSE;
					_tmp100_ = match_info;
					g_match_info_fetch_pos (_tmp100_, 0, &_tmp101_, &_tmp102_);
					start_pos = _tmp101_;
					end_pos = _tmp102_;
					_tmp103_ = text;
					_tmp104_ = string_substring (_tmp103_, (glong) 0, (glong) start_pos);
					_tmp105_ = _tmp104_;
					_tmp106_ = g_utf8_strlen (_tmp105_, (gssize) -1);
					_g_free0 (_tmp105_);
					start_chars = _tmp106_;
					_tmp107_ = text;
					_tmp108_ = string_substring (_tmp107_, (glong) 0, (glong) end_pos);
					_tmp109_ = _tmp108_;
					_tmp110_ = g_utf8_strlen (_tmp109_, (gssize) -1);
					_g_free0 (_tmp109_);
					end_chars = _tmp110_;
					_tmp111_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp111_, &_tmp112_, start_chars);
					italic_start = _tmp112_;
					_tmp113_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp113_, &_tmp114_, end_chars);
					italic_end = _tmp114_;
					_tmp115_ = italic_start;
					ast_end = _tmp115_;
					gtk_text_iter_forward_chars (&ast_end, 1);
					_tmp116_ = self->buffer;
					_tmp117_ = self->priv->invisible_tag;
					_tmp118_ = italic_start;
					_tmp119_ = ast_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp116_, _tmp117_, &_tmp118_, &_tmp119_);
					_tmp120_ = italic_start;
					text_start = _tmp120_;
					gtk_text_iter_forward_chars (&text_start, 1);
					_tmp121_ = italic_end;
					text_end = _tmp121_;
					gtk_text_iter_backward_chars (&text_end, 1);
					_tmp122_ = self->buffer;
					_tmp123_ = self->priv->italic_tag;
					_tmp124_ = text_start;
					_tmp125_ = text_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp122_, _tmp123_, &_tmp124_, &_tmp125_);
					_tmp126_ = italic_end;
					last_ast_start = _tmp126_;
					gtk_text_iter_backward_chars (&last_ast_start, 1);
					_tmp127_ = self->buffer;
					_tmp128_ = self->priv->invisible_tag;
					_tmp129_ = last_ast_start;
					_tmp130_ = italic_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp127_, _tmp128_, &_tmp129_, &_tmp130_);
				}
			}
		}
		_tmp131_ = g_regex_new ("~~([^~]+)~~", 0, 0, &_inner_error0_);
		strikethrough_regex = _tmp131_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (italic_regex);
			_g_regex_unref0 (bold_regex);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp132_ = strikethrough_regex;
		_tmp133_ = text;
		_tmp135_ = g_regex_match (_tmp132_, _tmp133_, 0, &_tmp134_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp134_;
		if (_tmp135_) {
			{
				gboolean _tmp136_ = FALSE;
				_tmp136_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp139_;
					gint _tmp140_ = 0;
					gint _tmp141_ = 0;
					gint start_chars = 0;
					const gchar* _tmp142_;
					gchar* _tmp143_;
					gchar* _tmp144_;
					gint _tmp145_;
					gint end_chars = 0;
					const gchar* _tmp146_;
					gchar* _tmp147_;
					gchar* _tmp148_;
					gint _tmp149_;
					GtkTextIter strike_start = {0};
					GtkTextIter strike_end = {0};
					GtkSourceBuffer* _tmp150_;
					GtkTextIter _tmp151_ = {0};
					GtkSourceBuffer* _tmp152_;
					GtkTextIter _tmp153_ = {0};
					GtkTextIter tilde_end = {0};
					GtkTextIter _tmp154_;
					GtkSourceBuffer* _tmp155_;
					GtkTextTag* _tmp156_;
					GtkTextIter _tmp157_;
					GtkTextIter _tmp158_;
					GtkTextIter text_start = {0};
					GtkTextIter _tmp159_;
					GtkTextIter text_end = {0};
					GtkTextIter _tmp160_;
					GtkSourceBuffer* _tmp161_;
					GtkTextTag* _tmp162_;
					GtkTextIter _tmp163_;
					GtkTextIter _tmp164_;
					GtkTextIter last_tilde_start = {0};
					GtkTextIter _tmp165_;
					GtkSourceBuffer* _tmp166_;
					GtkTextTag* _tmp167_;
					GtkTextIter _tmp168_;
					GtkTextIter _tmp169_;
					if (!_tmp136_) {
						gboolean _tmp137_ = FALSE;
						GMatchInfo* _tmp138_;
						_tmp138_ = match_info;
						_tmp137_ = g_match_info_next (_tmp138_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (strikethrough_regex);
							_g_regex_unref0 (italic_regex);
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp137_) {
							break;
						}
					}
					_tmp136_ = FALSE;
					_tmp139_ = match_info;
					g_match_info_fetch_pos (_tmp139_, 0, &_tmp140_, &_tmp141_);
					start_pos = _tmp140_;
					end_pos = _tmp141_;
					_tmp142_ = text;
					_tmp143_ = string_substring (_tmp142_, (glong) 0, (glong) start_pos);
					_tmp144_ = _tmp143_;
					_tmp145_ = g_utf8_strlen (_tmp144_, (gssize) -1);
					_g_free0 (_tmp144_);
					start_chars = _tmp145_;
					_tmp146_ = text;
					_tmp147_ = string_substring (_tmp146_, (glong) 0, (glong) end_pos);
					_tmp148_ = _tmp147_;
					_tmp149_ = g_utf8_strlen (_tmp148_, (gssize) -1);
					_g_free0 (_tmp148_);
					end_chars = _tmp149_;
					_tmp150_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp150_, &_tmp151_, start_chars);
					strike_start = _tmp151_;
					_tmp152_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp152_, &_tmp153_, end_chars);
					strike_end = _tmp153_;
					_tmp154_ = strike_start;
					tilde_end = _tmp154_;
					gtk_text_iter_forward_chars (&tilde_end, 2);
					_tmp155_ = self->buffer;
					_tmp156_ = self->priv->invisible_tag;
					_tmp157_ = strike_start;
					_tmp158_ = tilde_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp155_, _tmp156_, &_tmp157_, &_tmp158_);
					_tmp159_ = strike_start;
					text_start = _tmp159_;
					gtk_text_iter_forward_chars (&text_start, 2);
					_tmp160_ = strike_end;
					text_end = _tmp160_;
					gtk_text_iter_backward_chars (&text_end, 2);
					_tmp161_ = self->buffer;
					_tmp162_ = self->priv->strikethrough_tag;
					_tmp163_ = text_start;
					_tmp164_ = text_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp161_, _tmp162_, &_tmp163_, &_tmp164_);
					_tmp165_ = strike_end;
					last_tilde_start = _tmp165_;
					gtk_text_iter_backward_chars (&last_tilde_start, 2);
					_tmp166_ = self->buffer;
					_tmp167_ = self->priv->invisible_tag;
					_tmp168_ = last_tilde_start;
					_tmp169_ = strike_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp166_, _tmp167_, &_tmp168_, &_tmp169_);
				}
			}
		}
		_tmp170_ = g_regex_new ("^# (.+)$", G_REGEX_MULTILINE, 0, &_inner_error0_);
		h1_regex = _tmp170_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (strikethrough_regex);
			_g_regex_unref0 (italic_regex);
			_g_regex_unref0 (bold_regex);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp171_ = h1_regex;
		_tmp172_ = text;
		_tmp174_ = g_regex_match (_tmp171_, _tmp172_, 0, &_tmp173_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp173_;
		if (_tmp174_) {
			{
				gboolean _tmp175_ = FALSE;
				_tmp175_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp178_;
					gint _tmp179_ = 0;
					gint _tmp180_ = 0;
					gint start_chars = 0;
					const gchar* _tmp181_;
					gchar* _tmp182_;
					gchar* _tmp183_;
					gint _tmp184_;
					gint end_chars = 0;
					const gchar* _tmp185_;
					gchar* _tmp186_;
					gchar* _tmp187_;
					gint _tmp188_;
					GtkTextIter h1_start = {0};
					GtkTextIter h1_end = {0};
					GtkSourceBuffer* _tmp189_;
					GtkTextIter _tmp190_ = {0};
					GtkSourceBuffer* _tmp191_;
					GtkTextIter _tmp192_ = {0};
					GtkTextIter hash_end = {0};
					GtkTextIter _tmp193_;
					GtkSourceBuffer* _tmp194_;
					GtkTextTag* _tmp195_;
					GtkTextIter _tmp196_;
					GtkTextIter _tmp197_;
					GtkTextIter text_start = {0};
					GtkTextIter _tmp198_;
					GtkSourceBuffer* _tmp199_;
					GtkTextTag* _tmp200_;
					GtkTextIter _tmp201_;
					GtkTextIter _tmp202_;
					if (!_tmp175_) {
						gboolean _tmp176_ = FALSE;
						GMatchInfo* _tmp177_;
						_tmp177_ = match_info;
						_tmp176_ = g_match_info_next (_tmp177_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (h1_regex);
							_g_regex_unref0 (strikethrough_regex);
							_g_regex_unref0 (italic_regex);
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp176_) {
							break;
						}
					}
					_tmp175_ = FALSE;
					_tmp178_ = match_info;
					g_match_info_fetch_pos (_tmp178_, 0, &_tmp179_, &_tmp180_);
					start_pos = _tmp179_;
					end_pos = _tmp180_;
					_tmp181_ = text;
					_tmp182_ = string_substring (_tmp181_, (glong) 0, (glong) start_pos);
					_tmp183_ = _tmp182_;
					_tmp184_ = g_utf8_strlen (_tmp183_, (gssize) -1);
					_g_free0 (_tmp183_);
					start_chars = _tmp184_;
					_tmp185_ = text;
					_tmp186_ = string_substring (_tmp185_, (glong) 0, (glong) end_pos);
					_tmp187_ = _tmp186_;
					_tmp188_ = g_utf8_strlen (_tmp187_, (gssize) -1);
					_g_free0 (_tmp187_);
					end_chars = _tmp188_;
					_tmp189_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp189_, &_tmp190_, start_chars);
					h1_start = _tmp190_;
					_tmp191_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp191_, &_tmp192_, end_chars);
					h1_end = _tmp192_;
					_tmp193_ = h1_start;
					hash_end = _tmp193_;
					gtk_text_iter_forward_chars (&hash_end, 2);
					_tmp194_ = self->buffer;
					_tmp195_ = self->priv->invisible_tag;
					_tmp196_ = h1_start;
					_tmp197_ = hash_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp194_, _tmp195_, &_tmp196_, &_tmp197_);
					_tmp198_ = h1_start;
					text_start = _tmp198_;
					gtk_text_iter_forward_chars (&text_start, 2);
					_tmp199_ = self->buffer;
					_tmp200_ = self->priv->h1_tag;
					_tmp201_ = text_start;
					_tmp202_ = h1_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp199_, _tmp200_, &_tmp201_, &_tmp202_);
				}
			}
		}
		_tmp203_ = g_regex_new ("^## (.+)$", G_REGEX_MULTILINE, 0, &_inner_error0_);
		h2_regex = _tmp203_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (h1_regex);
			_g_regex_unref0 (strikethrough_regex);
			_g_regex_unref0 (italic_regex);
			_g_regex_unref0 (bold_regex);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp204_ = h2_regex;
		_tmp205_ = text;
		_tmp207_ = g_regex_match (_tmp204_, _tmp205_, 0, &_tmp206_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp206_;
		if (_tmp207_) {
			{
				gboolean _tmp208_ = FALSE;
				_tmp208_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp211_;
					gint _tmp212_ = 0;
					gint _tmp213_ = 0;
					gint start_chars = 0;
					const gchar* _tmp214_;
					gchar* _tmp215_;
					gchar* _tmp216_;
					gint _tmp217_;
					gint end_chars = 0;
					const gchar* _tmp218_;
					gchar* _tmp219_;
					gchar* _tmp220_;
					gint _tmp221_;
					GtkTextIter h2_start = {0};
					GtkTextIter h2_end = {0};
					GtkSourceBuffer* _tmp222_;
					GtkTextIter _tmp223_ = {0};
					GtkSourceBuffer* _tmp224_;
					GtkTextIter _tmp225_ = {0};
					GtkTextIter hash_end = {0};
					GtkTextIter _tmp226_;
					GtkSourceBuffer* _tmp227_;
					GtkTextTag* _tmp228_;
					GtkTextIter _tmp229_;
					GtkTextIter _tmp230_;
					GtkTextIter text_start = {0};
					GtkTextIter _tmp231_;
					GtkSourceBuffer* _tmp232_;
					GtkTextTag* _tmp233_;
					GtkTextIter _tmp234_;
					GtkTextIter _tmp235_;
					if (!_tmp208_) {
						gboolean _tmp209_ = FALSE;
						GMatchInfo* _tmp210_;
						_tmp210_ = match_info;
						_tmp209_ = g_match_info_next (_tmp210_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (h2_regex);
							_g_regex_unref0 (h1_regex);
							_g_regex_unref0 (strikethrough_regex);
							_g_regex_unref0 (italic_regex);
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp209_) {
							break;
						}
					}
					_tmp208_ = FALSE;
					_tmp211_ = match_info;
					g_match_info_fetch_pos (_tmp211_, 0, &_tmp212_, &_tmp213_);
					start_pos = _tmp212_;
					end_pos = _tmp213_;
					_tmp214_ = text;
					_tmp215_ = string_substring (_tmp214_, (glong) 0, (glong) start_pos);
					_tmp216_ = _tmp215_;
					_tmp217_ = g_utf8_strlen (_tmp216_, (gssize) -1);
					_g_free0 (_tmp216_);
					start_chars = _tmp217_;
					_tmp218_ = text;
					_tmp219_ = string_substring (_tmp218_, (glong) 0, (glong) end_pos);
					_tmp220_ = _tmp219_;
					_tmp221_ = g_utf8_strlen (_tmp220_, (gssize) -1);
					_g_free0 (_tmp220_);
					end_chars = _tmp221_;
					_tmp222_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp222_, &_tmp223_, start_chars);
					h2_start = _tmp223_;
					_tmp224_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp224_, &_tmp225_, end_chars);
					h2_end = _tmp225_;
					_tmp226_ = h2_start;
					hash_end = _tmp226_;
					gtk_text_iter_forward_chars (&hash_end, 3);
					_tmp227_ = self->buffer;
					_tmp228_ = self->priv->invisible_tag;
					_tmp229_ = h2_start;
					_tmp230_ = hash_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp227_, _tmp228_, &_tmp229_, &_tmp230_);
					_tmp231_ = h2_start;
					text_start = _tmp231_;
					gtk_text_iter_forward_chars (&text_start, 3);
					_tmp232_ = self->buffer;
					_tmp233_ = self->priv->h2_tag;
					_tmp234_ = text_start;
					_tmp235_ = h2_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp232_, _tmp233_, &_tmp234_, &_tmp235_);
				}
			}
		}
		_tmp236_ = g_regex_new ("`([^`]+)`", 0, 0, &_inner_error0_);
		code_regex = _tmp236_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (h2_regex);
			_g_regex_unref0 (h1_regex);
			_g_regex_unref0 (strikethrough_regex);
			_g_regex_unref0 (italic_regex);
			_g_regex_unref0 (bold_regex);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp237_ = code_regex;
		_tmp238_ = text;
		_tmp240_ = g_regex_match (_tmp237_, _tmp238_, 0, &_tmp239_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp239_;
		if (_tmp240_) {
			{
				gboolean _tmp241_ = FALSE;
				_tmp241_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp244_;
					gint _tmp245_ = 0;
					gint _tmp246_ = 0;
					gint start_chars = 0;
					const gchar* _tmp247_;
					gchar* _tmp248_;
					gchar* _tmp249_;
					gint _tmp250_;
					gint end_chars = 0;
					const gchar* _tmp251_;
					gchar* _tmp252_;
					gchar* _tmp253_;
					gint _tmp254_;
					GtkTextIter code_start = {0};
					GtkTextIter code_end = {0};
					GtkSourceBuffer* _tmp255_;
					GtkTextIter _tmp256_ = {0};
					GtkSourceBuffer* _tmp257_;
					GtkTextIter _tmp258_ = {0};
					GtkTextIter tick_end = {0};
					GtkTextIter _tmp259_;
					GtkSourceBuffer* _tmp260_;
					GtkTextTag* _tmp261_;
					GtkTextIter _tmp262_;
					GtkTextIter _tmp263_;
					GtkTextIter text_start = {0};
					GtkTextIter _tmp264_;
					GtkTextIter text_end = {0};
					GtkTextIter _tmp265_;
					GtkSourceBuffer* _tmp266_;
					GtkTextTag* _tmp267_;
					GtkTextIter _tmp268_;
					GtkTextIter _tmp269_;
					GtkTextIter last_tick_start = {0};
					GtkTextIter _tmp270_;
					GtkSourceBuffer* _tmp271_;
					GtkTextTag* _tmp272_;
					GtkTextIter _tmp273_;
					GtkTextIter _tmp274_;
					if (!_tmp241_) {
						gboolean _tmp242_ = FALSE;
						GMatchInfo* _tmp243_;
						_tmp243_ = match_info;
						_tmp242_ = g_match_info_next (_tmp243_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (code_regex);
							_g_regex_unref0 (h2_regex);
							_g_regex_unref0 (h1_regex);
							_g_regex_unref0 (strikethrough_regex);
							_g_regex_unref0 (italic_regex);
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp242_) {
							break;
						}
					}
					_tmp241_ = FALSE;
					_tmp244_ = match_info;
					g_match_info_fetch_pos (_tmp244_, 0, &_tmp245_, &_tmp246_);
					start_pos = _tmp245_;
					end_pos = _tmp246_;
					_tmp247_ = text;
					_tmp248_ = string_substring (_tmp247_, (glong) 0, (glong) start_pos);
					_tmp249_ = _tmp248_;
					_tmp250_ = g_utf8_strlen (_tmp249_, (gssize) -1);
					_g_free0 (_tmp249_);
					start_chars = _tmp250_;
					_tmp251_ = text;
					_tmp252_ = string_substring (_tmp251_, (glong) 0, (glong) end_pos);
					_tmp253_ = _tmp252_;
					_tmp254_ = g_utf8_strlen (_tmp253_, (gssize) -1);
					_g_free0 (_tmp253_);
					end_chars = _tmp254_;
					_tmp255_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp255_, &_tmp256_, start_chars);
					code_start = _tmp256_;
					_tmp257_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp257_, &_tmp258_, end_chars);
					code_end = _tmp258_;
					_tmp259_ = code_start;
					tick_end = _tmp259_;
					gtk_text_iter_forward_chars (&tick_end, 1);
					_tmp260_ = self->buffer;
					_tmp261_ = self->priv->invisible_tag;
					_tmp262_ = code_start;
					_tmp263_ = tick_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp260_, _tmp261_, &_tmp262_, &_tmp263_);
					_tmp264_ = code_start;
					text_start = _tmp264_;
					gtk_text_iter_forward_chars (&text_start, 1);
					_tmp265_ = code_end;
					text_end = _tmp265_;
					gtk_text_iter_backward_chars (&text_end, 1);
					_tmp266_ = self->buffer;
					_tmp267_ = self->priv->code_tag;
					_tmp268_ = text_start;
					_tmp269_ = text_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp266_, _tmp267_, &_tmp268_, &_tmp269_);
					_tmp270_ = code_end;
					last_tick_start = _tmp270_;
					gtk_text_iter_backward_chars (&last_tick_start, 1);
					_tmp271_ = self->buffer;
					_tmp272_ = self->priv->invisible_tag;
					_tmp273_ = last_tick_start;
					_tmp274_ = code_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp271_, _tmp272_, &_tmp273_, &_tmp274_);
				}
			}
		}
		_tmp275_ = g_regex_new ("\\[([^\\]]+)\\]\\(([^\\)]+)\\)", 0, 0, &_inner_error0_);
		link_regex = _tmp275_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (code_regex);
			_g_regex_unref0 (h2_regex);
			_g_regex_unref0 (h1_regex);
			_g_regex_unref0 (strikethrough_regex);
			_g_regex_unref0 (italic_regex);
			_g_regex_unref0 (bold_regex);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp276_ = link_regex;
		_tmp277_ = text;
		_tmp279_ = g_regex_match (_tmp276_, _tmp277_, 0, &_tmp278_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp278_;
		if (_tmp279_) {
			{
				gboolean _tmp280_ = FALSE;
				_tmp280_ = TRUE;
				while (TRUE) {
					gint full_start_pos = 0;
					gint full_end_pos = 0;
					GMatchInfo* _tmp283_;
					gint _tmp284_ = 0;
					gint _tmp285_ = 0;
					gint text_start_pos = 0;
					gint text_end_pos = 0;
					GMatchInfo* _tmp286_;
					gint _tmp287_ = 0;
					gint _tmp288_ = 0;
					gint full_start_chars = 0;
					const gchar* _tmp289_;
					gchar* _tmp290_;
					gchar* _tmp291_;
					gint _tmp292_;
					gint full_end_chars = 0;
					const gchar* _tmp293_;
					gchar* _tmp294_;
					gchar* _tmp295_;
					gint _tmp296_;
					gint text_start_chars = 0;
					const gchar* _tmp297_;
					gchar* _tmp298_;
					gchar* _tmp299_;
					gint _tmp300_;
					gint text_end_chars = 0;
					const gchar* _tmp301_;
					gchar* _tmp302_;
					gchar* _tmp303_;
					gint _tmp304_;
					GtkTextIter full_start = {0};
					GtkTextIter full_end = {0};
					GtkTextIter text_start = {0};
					GtkTextIter text_end = {0};
					GtkSourceBuffer* _tmp305_;
					GtkTextIter _tmp306_ = {0};
					GtkSourceBuffer* _tmp307_;
					GtkTextIter _tmp308_ = {0};
					GtkSourceBuffer* _tmp309_;
					GtkTextIter _tmp310_ = {0};
					GtkSourceBuffer* _tmp311_;
					GtkTextIter _tmp312_ = {0};
					GtkSourceBuffer* _tmp313_;
					GtkTextTag* _tmp314_;
					GtkTextIter _tmp315_;
					GtkTextIter _tmp316_;
					GtkTextIter bracket_end = {0};
					GtkTextIter _tmp317_;
					GtkSourceBuffer* _tmp318_;
					GtkTextTag* _tmp319_;
					GtkTextIter _tmp320_;
					GtkTextIter _tmp321_;
					GtkSourceBuffer* _tmp322_;
					GtkTextTag* _tmp323_;
					GtkTextIter _tmp324_;
					GtkTextIter _tmp325_;
					if (!_tmp280_) {
						gboolean _tmp281_ = FALSE;
						GMatchInfo* _tmp282_;
						_tmp282_ = match_info;
						_tmp281_ = g_match_info_next (_tmp282_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (link_regex);
							_g_regex_unref0 (code_regex);
							_g_regex_unref0 (h2_regex);
							_g_regex_unref0 (h1_regex);
							_g_regex_unref0 (strikethrough_regex);
							_g_regex_unref0 (italic_regex);
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp281_) {
							break;
						}
					}
					_tmp280_ = FALSE;
					_tmp283_ = match_info;
					g_match_info_fetch_pos (_tmp283_, 0, &_tmp284_, &_tmp285_);
					full_start_pos = _tmp284_;
					full_end_pos = _tmp285_;
					_tmp286_ = match_info;
					g_match_info_fetch_pos (_tmp286_, 1, &_tmp287_, &_tmp288_);
					text_start_pos = _tmp287_;
					text_end_pos = _tmp288_;
					_tmp289_ = text;
					_tmp290_ = string_substring (_tmp289_, (glong) 0, (glong) full_start_pos);
					_tmp291_ = _tmp290_;
					_tmp292_ = g_utf8_strlen (_tmp291_, (gssize) -1);
					_g_free0 (_tmp291_);
					full_start_chars = _tmp292_;
					_tmp293_ = text;
					_tmp294_ = string_substring (_tmp293_, (glong) 0, (glong) full_end_pos);
					_tmp295_ = _tmp294_;
					_tmp296_ = g_utf8_strlen (_tmp295_, (gssize) -1);
					_g_free0 (_tmp295_);
					full_end_chars = _tmp296_;
					_tmp297_ = text;
					_tmp298_ = string_substring (_tmp297_, (glong) 0, (glong) text_start_pos);
					_tmp299_ = _tmp298_;
					_tmp300_ = g_utf8_strlen (_tmp299_, (gssize) -1);
					_g_free0 (_tmp299_);
					text_start_chars = _tmp300_;
					_tmp301_ = text;
					_tmp302_ = string_substring (_tmp301_, (glong) 0, (glong) text_end_pos);
					_tmp303_ = _tmp302_;
					_tmp304_ = g_utf8_strlen (_tmp303_, (gssize) -1);
					_g_free0 (_tmp303_);
					text_end_chars = _tmp304_;
					_tmp305_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp305_, &_tmp306_, full_start_chars);
					full_start = _tmp306_;
					_tmp307_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp307_, &_tmp308_, full_end_chars);
					full_end = _tmp308_;
					_tmp309_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp309_, &_tmp310_, text_start_chars);
					text_start = _tmp310_;
					_tmp311_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp311_, &_tmp312_, text_end_chars);
					text_end = _tmp312_;
					_tmp313_ = self->buffer;
					_tmp314_ = self->priv->link_tag;
					_tmp315_ = full_start;
					_tmp316_ = full_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp313_, _tmp314_, &_tmp315_, &_tmp316_);
					_tmp317_ = full_start;
					bracket_end = _tmp317_;
					gtk_text_iter_forward_chars (&bracket_end, 1);
					_tmp318_ = self->buffer;
					_tmp319_ = self->priv->invisible_tag;
					_tmp320_ = full_start;
					_tmp321_ = bracket_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp318_, _tmp319_, &_tmp320_, &_tmp321_);
					_tmp322_ = self->buffer;
					_tmp323_ = self->priv->invisible_tag;
					_tmp324_ = text_end;
					_tmp325_ = full_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp322_, _tmp323_, &_tmp324_, &_tmp325_);
				}
			}
		}
		_tmp326_ = g_regex_new ("^- (?!\\[[ x]\\])(.*)$", G_REGEX_MULTILINE, 0, &_inner_error0_);
		unordered_list_regex = _tmp326_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (link_regex);
			_g_regex_unref0 (code_regex);
			_g_regex_unref0 (h2_regex);
			_g_regex_unref0 (h1_regex);
			_g_regex_unref0 (strikethrough_regex);
			_g_regex_unref0 (italic_regex);
			_g_regex_unref0 (bold_regex);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp327_ = unordered_list_regex;
		_tmp328_ = text;
		_tmp330_ = g_regex_match (_tmp327_, _tmp328_, 0, &_tmp329_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp329_;
		if (_tmp330_) {
			{
				gboolean _tmp331_ = FALSE;
				_tmp331_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp334_;
					gint _tmp335_ = 0;
					gint _tmp336_ = 0;
					gint start_chars = 0;
					const gchar* _tmp337_;
					gchar* _tmp338_;
					gchar* _tmp339_;
					gint _tmp340_;
					gint end_chars = 0;
					const gchar* _tmp341_;
					gchar* _tmp342_;
					gchar* _tmp343_;
					gint _tmp344_;
					GtkTextIter list_start = {0};
					GtkTextIter list_end = {0};
					GtkSourceBuffer* _tmp345_;
					GtkTextIter _tmp346_ = {0};
					GtkSourceBuffer* _tmp347_;
					GtkTextIter _tmp348_ = {0};
					gchar* line_text = NULL;
					GtkSourceBuffer* _tmp349_;
					GtkTextIter _tmp350_;
					GtkTextIter _tmp351_;
					gchar* _tmp352_;
					const gchar* _tmp353_;
					GtkSourceBuffer* _tmp362_;
					GtkTextTag* _tmp363_;
					GtkTextIter _tmp364_;
					GtkTextIter _tmp365_;
					if (!_tmp331_) {
						gboolean _tmp332_ = FALSE;
						GMatchInfo* _tmp333_;
						_tmp333_ = match_info;
						_tmp332_ = g_match_info_next (_tmp333_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (unordered_list_regex);
							_g_regex_unref0 (link_regex);
							_g_regex_unref0 (code_regex);
							_g_regex_unref0 (h2_regex);
							_g_regex_unref0 (h1_regex);
							_g_regex_unref0 (strikethrough_regex);
							_g_regex_unref0 (italic_regex);
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp332_) {
							break;
						}
					}
					_tmp331_ = FALSE;
					_tmp334_ = match_info;
					g_match_info_fetch_pos (_tmp334_, 0, &_tmp335_, &_tmp336_);
					start_pos = _tmp335_;
					end_pos = _tmp336_;
					_tmp337_ = text;
					_tmp338_ = string_substring (_tmp337_, (glong) 0, (glong) start_pos);
					_tmp339_ = _tmp338_;
					_tmp340_ = g_utf8_strlen (_tmp339_, (gssize) -1);
					_g_free0 (_tmp339_);
					start_chars = _tmp340_;
					_tmp341_ = text;
					_tmp342_ = string_substring (_tmp341_, (glong) 0, (glong) end_pos);
					_tmp343_ = _tmp342_;
					_tmp344_ = g_utf8_strlen (_tmp343_, (gssize) -1);
					_g_free0 (_tmp343_);
					end_chars = _tmp344_;
					_tmp345_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp345_, &_tmp346_, start_chars);
					list_start = _tmp346_;
					_tmp347_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp347_, &_tmp348_, end_chars);
					list_end = _tmp348_;
					_tmp349_ = self->buffer;
					_tmp350_ = list_start;
					_tmp351_ = list_end;
					_tmp352_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp349_, &_tmp350_, &_tmp351_, FALSE);
					line_text = _tmp352_;
					_tmp353_ = line_text;
					if (g_str_has_prefix (_tmp353_, "- ")) {
						GtkSourceBuffer* _tmp354_;
						guint _tmp355_;
						GtkTextIter dash_end = {0};
						GtkTextIter _tmp356_;
						GtkSourceBuffer* _tmp357_;
						GtkSourceBuffer* _tmp358_;
						GtkSourceBuffer* _tmp359_;
						GtkSourceBuffer* _tmp360_;
						GtkTextIter _tmp361_ = {0};
						_tmp354_ = self->buffer;
						g_signal_parse_name ("changed", gtk_text_buffer_get_type (), &_tmp355_, NULL, FALSE);
						g_signal_handlers_disconnect_matched ((GtkTextBuffer*) _tmp354_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp355_, 0, NULL, (GCallback) _widgets_markdown_editor_on_buffer_changed_gtk_text_buffer_changed, self);
						_tmp356_ = list_start;
						dash_end = _tmp356_;
						gtk_text_iter_forward_chars (&dash_end, 1);
						_tmp357_ = self->buffer;
						gtk_text_buffer_delete ((GtkTextBuffer*) _tmp357_, &list_start, &dash_end);
						_tmp358_ = self->buffer;
						gtk_text_buffer_insert ((GtkTextBuffer*) _tmp358_, &list_start, "•", -1);
						_tmp359_ = self->buffer;
						g_signal_connect_object ((GtkTextBuffer*) _tmp359_, "changed", (GCallback) _widgets_markdown_editor_on_buffer_changed_gtk_text_buffer_changed, self, 0);
						_tmp360_ = self->buffer;
						gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp360_, &_tmp361_, end_chars);
						list_end = _tmp361_;
					}
					_tmp362_ = self->buffer;
					_tmp363_ = self->priv->list_tag;
					_tmp364_ = list_start;
					_tmp365_ = list_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp362_, _tmp363_, &_tmp364_, &_tmp365_);
					_g_free0 (line_text);
				}
			}
		}
		_tmp366_ = g_regex_new ("^(\\d+)\\. (.*)$", G_REGEX_MULTILINE, 0, &_inner_error0_);
		ordered_list_regex = _tmp366_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (unordered_list_regex);
			_g_regex_unref0 (link_regex);
			_g_regex_unref0 (code_regex);
			_g_regex_unref0 (h2_regex);
			_g_regex_unref0 (h1_regex);
			_g_regex_unref0 (strikethrough_regex);
			_g_regex_unref0 (italic_regex);
			_g_regex_unref0 (bold_regex);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp367_ = ordered_list_regex;
		_tmp368_ = text;
		_tmp370_ = g_regex_match (_tmp367_, _tmp368_, 0, &_tmp369_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp369_;
		if (_tmp370_) {
			{
				gboolean _tmp371_ = FALSE;
				_tmp371_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp374_;
					gint _tmp375_ = 0;
					gint _tmp376_ = 0;
					gint start_chars = 0;
					const gchar* _tmp377_;
					gchar* _tmp378_;
					gchar* _tmp379_;
					gint _tmp380_;
					gint end_chars = 0;
					const gchar* _tmp381_;
					gchar* _tmp382_;
					gchar* _tmp383_;
					gint _tmp384_;
					GtkTextIter list_start = {0};
					GtkTextIter list_end = {0};
					GtkSourceBuffer* _tmp385_;
					GtkTextIter _tmp386_ = {0};
					GtkSourceBuffer* _tmp387_;
					GtkTextIter _tmp388_ = {0};
					GtkSourceBuffer* _tmp389_;
					GtkTextTag* _tmp390_;
					GtkTextIter _tmp391_;
					GtkTextIter _tmp392_;
					if (!_tmp371_) {
						gboolean _tmp372_ = FALSE;
						GMatchInfo* _tmp373_;
						_tmp373_ = match_info;
						_tmp372_ = g_match_info_next (_tmp373_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (ordered_list_regex);
							_g_regex_unref0 (unordered_list_regex);
							_g_regex_unref0 (link_regex);
							_g_regex_unref0 (code_regex);
							_g_regex_unref0 (h2_regex);
							_g_regex_unref0 (h1_regex);
							_g_regex_unref0 (strikethrough_regex);
							_g_regex_unref0 (italic_regex);
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp372_) {
							break;
						}
					}
					_tmp371_ = FALSE;
					_tmp374_ = match_info;
					g_match_info_fetch_pos (_tmp374_, 0, &_tmp375_, &_tmp376_);
					start_pos = _tmp375_;
					end_pos = _tmp376_;
					_tmp377_ = text;
					_tmp378_ = string_substring (_tmp377_, (glong) 0, (glong) start_pos);
					_tmp379_ = _tmp378_;
					_tmp380_ = g_utf8_strlen (_tmp379_, (gssize) -1);
					_g_free0 (_tmp379_);
					start_chars = _tmp380_;
					_tmp381_ = text;
					_tmp382_ = string_substring (_tmp381_, (glong) 0, (glong) end_pos);
					_tmp383_ = _tmp382_;
					_tmp384_ = g_utf8_strlen (_tmp383_, (gssize) -1);
					_g_free0 (_tmp383_);
					end_chars = _tmp384_;
					_tmp385_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp385_, &_tmp386_, start_chars);
					list_start = _tmp386_;
					_tmp387_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp387_, &_tmp388_, end_chars);
					list_end = _tmp388_;
					_tmp389_ = self->buffer;
					_tmp390_ = self->priv->ordered_list_tag;
					_tmp391_ = list_start;
					_tmp392_ = list_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp389_, _tmp390_, &_tmp391_, &_tmp392_);
				}
			}
		}
		_tmp393_ = g_regex_new ("(?<!\\[)(?<!\\()\\b[a-zA-Z][a-zA-Z0-9+.-]*://[^\\s)]+", 0, 0, &_inner_error0_);
		plain_url_regex = _tmp393_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (ordered_list_regex);
			_g_regex_unref0 (unordered_list_regex);
			_g_regex_unref0 (link_regex);
			_g_regex_unref0 (code_regex);
			_g_regex_unref0 (h2_regex);
			_g_regex_unref0 (h1_regex);
			_g_regex_unref0 (strikethrough_regex);
			_g_regex_unref0 (italic_regex);
			_g_regex_unref0 (bold_regex);
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (bold_italic_regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp394_ = plain_url_regex;
		_tmp395_ = text;
		_tmp397_ = g_regex_match (_tmp394_, _tmp395_, 0, &_tmp396_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp396_;
		if (_tmp397_) {
			{
				gboolean _tmp398_ = FALSE;
				_tmp398_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp401_;
					gint _tmp402_ = 0;
					gint _tmp403_ = 0;
					gint start_chars = 0;
					const gchar* _tmp404_;
					gchar* _tmp405_;
					gchar* _tmp406_;
					gint _tmp407_;
					gint end_chars = 0;
					const gchar* _tmp408_;
					gchar* _tmp409_;
					gchar* _tmp410_;
					gint _tmp411_;
					GtkTextIter url_start = {0};
					GtkTextIter url_end = {0};
					GtkSourceBuffer* _tmp412_;
					GtkTextIter _tmp413_ = {0};
					GtkSourceBuffer* _tmp414_;
					GtkTextIter _tmp415_ = {0};
					GtkSourceBuffer* _tmp416_;
					GtkTextTag* _tmp417_;
					GtkTextIter _tmp418_;
					GtkTextIter _tmp419_;
					if (!_tmp398_) {
						gboolean _tmp399_ = FALSE;
						GMatchInfo* _tmp400_;
						_tmp400_ = match_info;
						_tmp399_ = g_match_info_next (_tmp400_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (plain_url_regex);
							_g_regex_unref0 (ordered_list_regex);
							_g_regex_unref0 (unordered_list_regex);
							_g_regex_unref0 (link_regex);
							_g_regex_unref0 (code_regex);
							_g_regex_unref0 (h2_regex);
							_g_regex_unref0 (h1_regex);
							_g_regex_unref0 (strikethrough_regex);
							_g_regex_unref0 (italic_regex);
							_g_regex_unref0 (bold_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (bold_italic_regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp399_) {
							break;
						}
					}
					_tmp398_ = FALSE;
					_tmp401_ = match_info;
					g_match_info_fetch_pos (_tmp401_, 0, &_tmp402_, &_tmp403_);
					start_pos = _tmp402_;
					end_pos = _tmp403_;
					_tmp404_ = text;
					_tmp405_ = string_substring (_tmp404_, (glong) 0, (glong) start_pos);
					_tmp406_ = _tmp405_;
					_tmp407_ = g_utf8_strlen (_tmp406_, (gssize) -1);
					_g_free0 (_tmp406_);
					start_chars = _tmp407_;
					_tmp408_ = text;
					_tmp409_ = string_substring (_tmp408_, (glong) 0, (glong) end_pos);
					_tmp410_ = _tmp409_;
					_tmp411_ = g_utf8_strlen (_tmp410_, (gssize) -1);
					_g_free0 (_tmp410_);
					end_chars = _tmp411_;
					_tmp412_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp412_, &_tmp413_, start_chars);
					url_start = _tmp413_;
					_tmp414_ = self->buffer;
					gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp414_, &_tmp415_, end_chars);
					url_end = _tmp415_;
					_tmp416_ = self->buffer;
					_tmp417_ = self->priv->link_tag;
					_tmp418_ = url_start;
					_tmp419_ = url_end;
					gtk_text_buffer_apply_tag ((GtkTextBuffer*) _tmp416_, _tmp417_, &_tmp418_, &_tmp419_);
				}
			}
		}
		_g_regex_unref0 (plain_url_regex);
		_g_regex_unref0 (ordered_list_regex);
		_g_regex_unref0 (unordered_list_regex);
		_g_regex_unref0 (link_regex);
		_g_regex_unref0 (code_regex);
		_g_regex_unref0 (h2_regex);
		_g_regex_unref0 (h1_regex);
		_g_regex_unref0 (strikethrough_regex);
		_g_regex_unref0 (italic_regex);
		_g_regex_unref0 (bold_regex);
		_g_match_info_unref0 (match_info);
		_g_regex_unref0 (bold_italic_regex);
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError* e = NULL;
		GError* _tmp420_;
		const gchar* _tmp421_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp420_ = e;
		_tmp421_ = _tmp420_->message;
		g_warning ("MarkdownEditor.vala:1197: Error in regex: %s", _tmp421_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (text);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_free0 (text);
}

void
widgets_markdown_editor_apply_h1_format (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		gchar* selected_text = NULL;
		GtkSourceBuffer* _tmp4_;
		GtkTextIter _tmp5_;
		GtkTextIter _tmp6_;
		gchar* _tmp7_;
		GtkSourceBuffer* _tmp8_;
		GtkSourceBuffer* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp4_ = self->buffer;
		_tmp5_ = start;
		_tmp6_ = end;
		_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, FALSE);
		selected_text = _tmp7_;
		_tmp8_ = self->buffer;
		gtk_text_buffer_delete ((GtkTextBuffer*) _tmp8_, &start, &end);
		_tmp9_ = self->buffer;
		_tmp10_ = selected_text;
		_tmp11_ = g_strconcat ("# ", _tmp10_, NULL);
		_tmp12_ = _tmp11_;
		gtk_text_buffer_insert ((GtkTextBuffer*) _tmp9_, &start, _tmp12_, -1);
		_g_free0 (_tmp12_);
		widgets_markdown_editor_apply_markdown_formatting (self);
		_g_free0 (selected_text);
	}
}

void
widgets_markdown_editor_apply_h2_format (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		gchar* selected_text = NULL;
		GtkSourceBuffer* _tmp4_;
		GtkTextIter _tmp5_;
		GtkTextIter _tmp6_;
		gchar* _tmp7_;
		GtkSourceBuffer* _tmp8_;
		GtkSourceBuffer* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp4_ = self->buffer;
		_tmp5_ = start;
		_tmp6_ = end;
		_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, FALSE);
		selected_text = _tmp7_;
		_tmp8_ = self->buffer;
		gtk_text_buffer_delete ((GtkTextBuffer*) _tmp8_, &start, &end);
		_tmp9_ = self->buffer;
		_tmp10_ = selected_text;
		_tmp11_ = g_strconcat ("## ", _tmp10_, NULL);
		_tmp12_ = _tmp11_;
		gtk_text_buffer_insert ((GtkTextBuffer*) _tmp9_, &start, _tmp12_, -1);
		_g_free0 (_tmp12_);
		widgets_markdown_editor_apply_markdown_formatting (self);
		_g_free0 (selected_text);
	}
}

void
widgets_markdown_editor_toggle_code_format (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		gchar* selected_text = NULL;
		GtkSourceBuffer* _tmp4_;
		GtkTextIter _tmp5_;
		GtkTextIter _tmp6_;
		gchar* _tmp7_;
		GtkTextIter _tmp8_;
		GtkTextIter _tmp9_;
		_tmp4_ = self->buffer;
		_tmp5_ = start;
		_tmp6_ = end;
		_tmp7_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp4_, &_tmp5_, &_tmp6_, FALSE);
		selected_text = _tmp7_;
		_tmp8_ = start;
		_tmp9_ = end;
		if (widgets_markdown_editor_is_already_code (self, &_tmp8_, &_tmp9_)) {
			GtkTextIter _tmp10_;
			GtkTextIter _tmp11_;
			_tmp10_ = start;
			_tmp11_ = end;
			widgets_markdown_editor_remove_code_format (self, &_tmp10_, &_tmp11_);
		} else {
			GtkTextIter _tmp12_;
			GtkTextIter _tmp13_;
			const gchar* _tmp14_;
			_tmp12_ = start;
			_tmp13_ = end;
			_tmp14_ = selected_text;
			widgets_markdown_editor_add_code_format (self, &_tmp12_, &_tmp13_, _tmp14_);
		}
		_g_free0 (selected_text);
	}
}

void
widgets_markdown_editor_apply_unordered_list_format (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		GtkTextIter _tmp4_;
		GtkTextIter _tmp5_;
		_tmp4_ = start;
		_tmp5_ = end;
		widgets_markdown_editor_apply_list_format (self, &_tmp4_, &_tmp5_, FALSE);
	}
}

void
widgets_markdown_editor_apply_ordered_list_format (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		GtkTextIter _tmp4_;
		GtkTextIter _tmp5_;
		_tmp4_ = start;
		_tmp5_ = end;
		widgets_markdown_editor_apply_list_format (self, &_tmp4_, &_tmp5_, TRUE);
	}
}

static gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  gint str_array_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* result;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp16_;
		gint _tmp17_;
		const gchar* res = NULL;
		void* _tmp18_;
		const gchar* _tmp19_ = NULL;
		const gchar* _tmp20_;
		void* ptr = NULL;
		const gchar* _tmp22_;
		void* _tmp23_;
		const gchar* _tmp33_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp10_ = 0;
				const gchar* _tmp11_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					_tmp7_ = i < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp8_ = FALSE;
					if (str_array_length1 == -1) {
						const gchar* _tmp9_;
						_tmp9_ = str_array[i];
						_tmp8_ = _tmp9_ != NULL;
					} else {
						_tmp8_ = FALSE;
					}
					_tmp6_ = _tmp8_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp11_ = str_array[i];
				if (_tmp11_ != NULL) {
					const gchar* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					_tmp12_ = str_array[i];
					_tmp13_ = strlen ((const gchar*) _tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = _tmp14_;
				} else {
					_tmp10_ = 0;
				}
				len += (gsize) _tmp10_;
			}
		}
		if (i == 0) {
			gchar* _tmp15_;
			_tmp15_ = g_strdup ("");
			result = _tmp15_;
			return result;
		}
		str_array_length1 = i;
		_tmp16_ = strlen ((const gchar*) separator);
		_tmp17_ = _tmp16_;
		len += (gsize) (_tmp17_ * (i - 1));
		_tmp18_ = g_malloc (len);
		res = _tmp18_;
		_tmp20_ = str_array[0];
		if (_tmp20_ != NULL) {
			const gchar* _tmp21_;
			_tmp21_ = str_array[0];
			_tmp19_ = (const gchar*) _tmp21_;
		} else {
			_tmp19_ = "";
		}
		_tmp22_ = res;
		_tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
		ptr = _tmp23_;
		{
			gboolean _tmp24_ = FALSE;
			i = 1;
			_tmp24_ = TRUE;
			while (TRUE) {
				void* _tmp26_;
				void* _tmp27_;
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_;
				void* _tmp31_;
				void* _tmp32_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < str_array_length1)) {
					break;
				}
				_tmp26_ = ptr;
				_tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
				ptr = _tmp27_;
				_tmp29_ = str_array[i];
				if (_tmp29_ != NULL) {
					const gchar* _tmp30_;
					_tmp30_ = str_array[i];
					_tmp28_ = (const gchar*) _tmp30_;
				} else {
					_tmp28_ = "";
				}
				_tmp31_ = ptr;
				_tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
				ptr = _tmp32_;
			}
		}
		_tmp33_ = res;
		res = NULL;
		result = (gchar*) _tmp33_;
		return result;
	} else {
		gchar* _tmp34_;
		_tmp34_ = g_strdup ("");
		result = _tmp34_;
		return result;
	}
}

static void
widgets_markdown_editor_apply_list_format (WidgetsMarkdownEditor* self,
                                           GtkTextIter* start,
                                           GtkTextIter* end,
                                           gboolean ordered)
{
	gint start_line = 0;
	gint end_line = 0;
	gboolean _tmp0_ = FALSE;
	gchar** lines = NULL;
	gchar** _tmp2_;
	gint lines_length1;
	gint _lines_size_;
	GtkTextIter full_start = {0};
	GtkTextIter full_end = {0};
	GtkSourceBuffer* _tmp25_;
	GtkTextIter _tmp26_ = {0};
	GtkSourceBuffer* _tmp27_;
	GtkTextIter _tmp28_ = {0};
	gchar* new_text = NULL;
	gchar** _tmp29_;
	gint _tmp29__length1;
	gchar* _tmp30_;
	GtkSourceBuffer* _tmp31_;
	GtkSourceBuffer* _tmp32_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	start_line = gtk_text_iter_get_line (start);
	end_line = gtk_text_iter_get_line (end);
	if (gtk_text_iter_get_line_offset (end) == 0) {
		_tmp0_ = end_line > start_line;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint _tmp1_;
		_tmp1_ = end_line;
		end_line = _tmp1_ - 1;
	}
	_tmp2_ = g_new0 (gchar*, ((end_line - start_line) + 1) + 1);
	lines = _tmp2_;
	lines_length1 = (end_line - start_line) + 1;
	_lines_size_ = lines_length1;
	{
		gint i = 0;
		i = start_line;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				GtkTextIter line_start = {0};
				GtkTextIter line_end = {0};
				GtkSourceBuffer* _tmp5_;
				GtkTextIter _tmp6_ = {0};
				GtkTextIter _tmp7_;
				gchar** _tmp8_;
				gint _tmp8__length1;
				GtkSourceBuffer* _tmp9_;
				GtkTextIter _tmp10_;
				GtkTextIter _tmp11_;
				gchar* _tmp12_;
				if (!_tmp3_) {
					gint _tmp4_;
					_tmp4_ = i;
					i = _tmp4_ + 1;
				}
				_tmp3_ = FALSE;
				if (!(i <= end_line)) {
					break;
				}
				_tmp5_ = self->buffer;
				gtk_text_buffer_get_iter_at_line ((GtkTextBuffer*) _tmp5_, &_tmp6_, i);
				line_start = _tmp6_;
				_tmp7_ = line_start;
				line_end = _tmp7_;
				if (!gtk_text_iter_ends_line (&line_end)) {
					gtk_text_iter_forward_to_line_end (&line_end);
				}
				_tmp8_ = lines;
				_tmp8__length1 = lines_length1;
				_tmp9_ = self->buffer;
				_tmp10_ = line_start;
				_tmp11_ = line_end;
				_tmp12_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp9_, &_tmp10_, &_tmp11_, FALSE);
				_g_free0 (_tmp8_[i - start_line]);
				_tmp8_[i - start_line] = _tmp12_;
			}
		}
	}
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp13_ = FALSE;
			_tmp13_ = TRUE;
			while (TRUE) {
				gchar** _tmp15_;
				gint _tmp15__length1;
				gchar* line = NULL;
				gchar** _tmp16_;
				gint _tmp16__length1;
				const gchar* _tmp17_;
				gchar* _tmp18_;
				if (!_tmp13_) {
					gint _tmp14_;
					_tmp14_ = i;
					i = _tmp14_ + 1;
				}
				_tmp13_ = FALSE;
				_tmp15_ = lines;
				_tmp15__length1 = lines_length1;
				if (!(i < _tmp15__length1)) {
					break;
				}
				_tmp16_ = lines;
				_tmp16__length1 = lines_length1;
				_tmp17_ = _tmp16_[i];
				_tmp18_ = string_strip (_tmp17_);
				line = _tmp18_;
				if (ordered) {
					gchar** _tmp19_;
					gint _tmp19__length1;
					const gchar* _tmp20_;
					gchar* _tmp21_;
					_tmp19_ = lines;
					_tmp19__length1 = lines_length1;
					_tmp20_ = line;
					_tmp21_ = g_strdup_printf ("%d. %s", i + 1, _tmp20_);
					_g_free0 (_tmp19_[i]);
					_tmp19_[i] = _tmp21_;
				} else {
					gchar** _tmp22_;
					gint _tmp22__length1;
					const gchar* _tmp23_;
					gchar* _tmp24_;
					_tmp22_ = lines;
					_tmp22__length1 = lines_length1;
					_tmp23_ = line;
					_tmp24_ = g_strconcat ("- ", _tmp23_, NULL);
					_g_free0 (_tmp22_[i]);
					_tmp22_[i] = _tmp24_;
				}
				_g_free0 (line);
			}
		}
	}
	_tmp25_ = self->buffer;
	gtk_text_buffer_get_iter_at_line ((GtkTextBuffer*) _tmp25_, &_tmp26_, start_line);
	full_start = _tmp26_;
	_tmp27_ = self->buffer;
	gtk_text_buffer_get_iter_at_line ((GtkTextBuffer*) _tmp27_, &_tmp28_, end_line);
	full_end = _tmp28_;
	if (!gtk_text_iter_ends_line (&full_end)) {
		gtk_text_iter_forward_to_line_end (&full_end);
	}
	_tmp29_ = lines;
	_tmp29__length1 = lines_length1;
	_tmp30_ = _vala_g_strjoinv ("\n", _tmp29_, (gint) _tmp29__length1);
	new_text = _tmp30_;
	_tmp31_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp31_, &full_start, &full_end);
	_tmp32_ = self->buffer;
	gtk_text_buffer_insert ((GtkTextBuffer*) _tmp32_, &full_start, new_text, -1);
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (new_text);
	lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
}

static gboolean
widgets_markdown_editor_is_already_code (WidgetsMarkdownEditor* self,
                                         GtkTextIter* start,
                                         GtkTextIter* end)
{
	GtkTextTag* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (start != NULL, FALSE);
	g_return_val_if_fail (end != NULL, FALSE);
	_tmp0_ = self->priv->code_tag;
	result = gtk_text_iter_has_tag (start, _tmp0_);
	return result;
}

static void
widgets_markdown_editor_add_code_format (WidgetsMarkdownEditor* self,
                                         GtkTextIter* start,
                                         GtkTextIter* end,
                                         const gchar* text)
{
	WidgetsMarkdownEditorExpandedRange expanded = {0};
	GtkTextIter _tmp0_;
	GtkTextIter _tmp1_;
	WidgetsMarkdownEditorExpandedRange _tmp2_ = {0};
	gchar* clean_text = NULL;
	WidgetsMarkdownEditorExpandedRange _tmp3_;
	GtkTextIter _tmp4_;
	WidgetsMarkdownEditorExpandedRange _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	GtkSourceBuffer* _tmp8_;
	GtkSourceBuffer* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	g_return_if_fail (text != NULL);
	_tmp0_ = *start;
	_tmp1_ = *end;
	widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp0_, &_tmp1_, &_tmp2_);
	expanded = _tmp2_;
	_tmp3_ = expanded;
	_tmp4_ = _tmp3_.start;
	_tmp5_ = expanded;
	_tmp6_ = _tmp5_.end;
	_tmp7_ = widgets_markdown_editor_get_clean_text_from_range (self, &_tmp4_, &_tmp6_);
	clean_text = _tmp7_;
	_tmp8_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp8_, &expanded.start, &expanded.end);
	_tmp9_ = self->buffer;
	_tmp10_ = g_strconcat ("`", clean_text, NULL);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strconcat (_tmp11_, "`", NULL);
	_tmp13_ = _tmp12_;
	gtk_text_buffer_insert ((GtkTextBuffer*) _tmp9_, &expanded.start, _tmp13_, -1);
	_g_free0 (_tmp13_);
	_g_free0 (_tmp11_);
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (clean_text);
}

static void
widgets_markdown_editor_remove_code_format (WidgetsMarkdownEditor* self,
                                            GtkTextIter* start,
                                            GtkTextIter* end)
{
	WidgetsMarkdownEditorExpandedRange expanded = {0};
	GtkTextIter _tmp0_;
	GtkTextIter _tmp1_;
	WidgetsMarkdownEditorExpandedRange _tmp2_ = {0};
	gchar* clean_text = NULL;
	WidgetsMarkdownEditorExpandedRange _tmp3_;
	GtkTextIter _tmp4_;
	WidgetsMarkdownEditorExpandedRange _tmp5_;
	GtkTextIter _tmp6_;
	gchar* _tmp7_;
	GtkSourceBuffer* _tmp8_;
	GtkSourceBuffer* _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (start != NULL);
	g_return_if_fail (end != NULL);
	_tmp0_ = *start;
	_tmp1_ = *end;
	widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp0_, &_tmp1_, &_tmp2_);
	expanded = _tmp2_;
	_tmp3_ = expanded;
	_tmp4_ = _tmp3_.start;
	_tmp5_ = expanded;
	_tmp6_ = _tmp5_.end;
	_tmp7_ = widgets_markdown_editor_get_clean_text_from_range (self, &_tmp4_, &_tmp6_);
	clean_text = _tmp7_;
	_tmp8_ = self->buffer;
	gtk_text_buffer_delete ((GtkTextBuffer*) _tmp8_, &expanded.start, &expanded.end);
	_tmp9_ = self->buffer;
	gtk_text_buffer_insert ((GtkTextBuffer*) _tmp9_, &expanded.start, clean_text, -1);
	widgets_markdown_editor_apply_markdown_formatting (self);
	_g_free0 (clean_text);
}

void
widgets_markdown_editor_set_text (WidgetsMarkdownEditor* self,
                                  const gchar* text)
{
	GtkSourceBuffer* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	self->priv->updating_programmatically = TRUE;
	self->priv->showing_placeholder = FALSE;
	_tmp0_ = self->buffer;
	gtk_text_buffer_set_text ((GtkTextBuffer*) _tmp0_, text, -1);
	widgets_markdown_editor_update_placeholder_visibility (self);
	self->priv->updating_programmatically = FALSE;
	_tmp1_ = widgets_markdown_editor_get_text_mode (self);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		widgets_markdown_editor_apply_markdown_formatting (self);
	}
}

gchar*
widgets_markdown_editor_get_text (WidgetsMarkdownEditor* self)
{
	gchar* text = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = widgets_markdown_editor_get_real_text (self);
	text = _tmp0_;
	_tmp1_ = text;
	_tmp2_ = string_replace (_tmp1_, "• ", "- ");
	_g_free0 (text);
	text = _tmp2_;
	result = text;
	return result;
}

gchar*
widgets_markdown_editor_get_plain_text (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gchar* text = NULL;
	GtkSourceBuffer* _tmp3_;
	GtkTextIter _tmp4_;
	GtkTextIter _tmp5_;
	gchar* _tmp6_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->buffer;
	gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	_tmp3_ = self->buffer;
	_tmp4_ = start;
	_tmp5_ = end;
	_tmp6_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp3_, &_tmp4_, &_tmp5_, TRUE);
	text = _tmp6_;
	{
		GRegex* regex = NULL;
		GRegex* _tmp7_;
		gchar* _tmp8_ = NULL;
		GRegex* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp7_ = g_regex_new ("\\*+", 0, 0, &_inner_error0_);
		regex = _tmp7_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp9_ = regex;
		_tmp10_ = text;
		_tmp11_ = g_regex_replace (_tmp9_, _tmp10_, (gssize) -1, 0, "", 0, &_inner_error0_);
		_tmp8_ = _tmp11_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp12_ = _tmp8_;
		_tmp8_ = NULL;
		result = _tmp12_;
		_g_free0 (_tmp8_);
		_g_regex_unref0 (regex);
		_g_free0 (text);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		result = text;
		return result;
	}
	__finally0:
	_g_free0 (text);
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

void
widgets_markdown_editor_clear (WidgetsMarkdownEditor* self)
{
	GtkSourceBuffer* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	gtk_text_buffer_set_text ((GtkTextBuffer*) _tmp0_, "", -1);
}

void
widgets_markdown_editor_focus (WidgetsMarkdownEditor* self)
{
	GtkTextView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->text_view;
	gtk_widget_grab_focus ((GtkWidget*) _tmp0_);
}

void
widgets_markdown_editor_cleanup (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	GtkPopover* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->format_popover;
	if (_tmp0_ != NULL) {
		GtkPopover* _tmp1_;
		GtkWidget* _tmp2_;
		_tmp1_ = self->priv->format_popover;
		_tmp2_ = gtk_widget_get_parent ((GtkWidget*) _tmp1_);
		if (_tmp2_ != NULL) {
			GtkPopover* _tmp3_;
			GtkPopover* _tmp4_;
			_tmp3_ = self->priv->format_popover;
			gtk_popover_popdown (_tmp3_);
			_tmp4_ = self->priv->format_popover;
			gtk_widget_unparent ((GtkWidget*) _tmp4_);
		}
		_g_object_unref0 (self->priv->format_popover);
		self->priv->format_popover = NULL;
	}
	_tmp5_ = self->priv->link_popover;
	if (_tmp5_ != NULL) {
		GtkPopover* _tmp6_;
		GtkWidget* _tmp7_;
		_tmp6_ = self->priv->link_popover;
		_tmp7_ = gtk_widget_get_parent ((GtkWidget*) _tmp6_);
		if (_tmp7_ != NULL) {
			GtkPopover* _tmp8_;
			GtkPopover* _tmp9_;
			_tmp8_ = self->priv->link_popover;
			gtk_popover_popdown (_tmp8_);
			_tmp9_ = self->priv->link_popover;
			gtk_widget_unparent ((GtkWidget*) _tmp9_);
		}
		_g_object_unref0 (self->priv->link_popover);
		self->priv->link_popover = NULL;
	}
}

static void
_widgets_markdown_editor_on_link_apply_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                   gpointer self)
{
	widgets_markdown_editor_on_link_apply_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_link_remove_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                    gpointer self)
{
	widgets_markdown_editor_on_link_remove_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_link_apply_clicked_gtk_entry_activate (GtkEntry* _sender,
                                                                   gpointer self)
{
	widgets_markdown_editor_on_link_apply_clicked ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_link_entry_changed_gtk_editable_changed (GtkEditable* _sender,
                                                                     gpointer self)
{
	widgets_markdown_editor_on_link_entry_changed ((WidgetsMarkdownEditor*) self);
}

static void
widgets_markdown_editor_create_link_popover (WidgetsMarkdownEditor* self)
{
	gchar* _tmp0_;
	GtkEntry* _tmp1_ = NULL;
	gchar* _tmp2_;
	GtkButton* _tmp3_ = NULL;
	GtkButton* _tmp4_;
	gchar* _tmp5_;
	GtkButton* _tmp6_ = NULL;
	GtkButton* _tmp7_;
	GtkBox* link_box = NULL;
	GtkBox* _tmp8_ = NULL;
	GtkEntry* _tmp9_;
	GtkButton* _tmp10_;
	GtkWidget* _tmp11_;
	GtkPopover* _tmp12_ = NULL;
	GtkButton* _tmp13_;
	GtkButton* _tmp14_;
	GtkEntry* _tmp15_;
	GtkEntry* _tmp16_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup ("https://example.com");
	_tmp1_ = (GtkEntry*) gtk_entry_new ();
	gtk_entry_set_placeholder_text (_tmp1_, _tmp0_);
	_g_free0 (_tmp0_);
	g_object_set ((GtkWidget*) _tmp1_, "width-request", 320, NULL);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->link_entry);
	self->priv->link_entry = _tmp1_;
	_tmp2_ = g_strdup (_ ("Apply"));
	_tmp3_ = (GtkButton*) gtk_button_new_from_icon_name ("checkmark-small-symbolic");
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp3_, _tmp2_);
	_g_free0 (_tmp2_);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->link_apply_button);
	self->priv->link_apply_button = _tmp3_;
	_tmp4_ = self->priv->link_apply_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp4_, "suggested-action");
	_tmp5_ = g_strdup (_ ("Remove link"));
	_tmp6_ = (GtkButton*) gtk_button_new_from_icon_name ("user-trash-symbolic");
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp6_, _tmp5_);
	_g_free0 (_tmp5_);
	g_object_ref_sink (_tmp6_);
	_g_object_unref0 (self->priv->link_remove_button);
	self->priv->link_remove_button = _tmp6_;
	_tmp7_ = self->priv->link_remove_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp7_, "destructive-action");
	_tmp8_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp8_, 6);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp8_, 6);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp8_, 6);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp8_, 6);
	g_object_ref_sink (_tmp8_);
	link_box = _tmp8_;
	_tmp9_ = self->priv->link_entry;
	gtk_box_append (link_box, (GtkWidget*) _tmp9_);
	_tmp10_ = self->priv->link_apply_button;
	gtk_box_append (link_box, (GtkWidget*) _tmp10_);
	_tmp11_ = _g_object_ref0 ((GtkWidget*) link_box);
	_tmp12_ = (GtkPopover*) gtk_popover_new ();
	gtk_popover_set_has_arrow (_tmp12_, FALSE);
	gtk_popover_set_autohide (_tmp12_, TRUE);
	gtk_popover_set_child (_tmp12_, _tmp11_);
	_g_object_unref0 (_tmp11_);
	g_object_ref_sink (_tmp12_);
	_g_object_unref0 (self->priv->link_popover);
	self->priv->link_popover = _tmp12_;
	_tmp13_ = self->priv->link_apply_button;
	g_signal_connect_object (_tmp13_, "clicked", (GCallback) _widgets_markdown_editor_on_link_apply_clicked_gtk_button_clicked, self, 0);
	_tmp14_ = self->priv->link_remove_button;
	g_signal_connect_object (_tmp14_, "clicked", (GCallback) _widgets_markdown_editor_on_link_remove_clicked_gtk_button_clicked, self, 0);
	_tmp15_ = self->priv->link_entry;
	g_signal_connect_object (_tmp15_, "activate", (GCallback) _widgets_markdown_editor_on_link_apply_clicked_gtk_entry_activate, self, 0);
	_tmp16_ = self->priv->link_entry;
	g_signal_connect_object ((GtkEditable*) _tmp16_, "changed", (GCallback) _widgets_markdown_editor_on_link_entry_changed_gtk_editable_changed, self, 0);
	_g_object_unref0 (link_box);
}

static gboolean
widgets_markdown_editor_is_already_link (WidgetsMarkdownEditor* self,
                                         GtkTextIter* start,
                                         GtkTextIter* end)
{
	GtkTextTag* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (start != NULL, FALSE);
	g_return_val_if_fail (end != NULL, FALSE);
	_tmp0_ = self->priv->link_tag;
	result = gtk_text_iter_has_tag (start, _tmp0_);
	return result;
}

static void
widgets_markdown_editor_show_add_link_popover (WidgetsMarkdownEditor* self,
                                               GtkTextIter* iter)
{
	GtkEntry* _tmp0_;
	GtkBox* link_box = NULL;
	GtkPopover* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	GtkBox* _tmp4_;
	GtkBox* _tmp5_;
	GtkWidget* _tmp6_;
	GtkButton* _tmp7_;
	GtkBox* _tmp10_;
	GtkWidget* _tmp11_;
	GtkButton* _tmp12_;
	GtkTextIter _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (iter != NULL);
	self->priv->editing_existing_link = FALSE;
	_tmp0_ = self->priv->link_entry;
	gtk_editable_set_text ((GtkEditable*) _tmp0_, "");
	_tmp1_ = self->priv->link_popover;
	_tmp2_ = gtk_popover_get_child (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_box_get_type (), GtkBox));
	link_box = _tmp4_;
	_tmp5_ = link_box;
	_tmp6_ = gtk_widget_get_last_child ((GtkWidget*) _tmp5_);
	_tmp7_ = self->priv->link_remove_button;
	if (_tmp6_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, gtk_widget_get_type (), GtkWidget)) {
		GtkBox* _tmp8_;
		GtkButton* _tmp9_;
		_tmp8_ = link_box;
		_tmp9_ = self->priv->link_remove_button;
		gtk_box_remove (_tmp8_, (GtkWidget*) _tmp9_);
	}
	_tmp10_ = link_box;
	_tmp11_ = gtk_widget_get_last_child ((GtkWidget*) _tmp10_);
	_tmp12_ = self->priv->link_apply_button;
	if (_tmp11_ != G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, gtk_widget_get_type (), GtkWidget)) {
		GtkBox* _tmp13_;
		GtkButton* _tmp14_;
		_tmp13_ = link_box;
		_tmp14_ = self->priv->link_apply_button;
		gtk_box_append (_tmp13_, (GtkWidget*) _tmp14_);
	}
	_tmp15_ = *iter;
	widgets_markdown_editor_show_link_popover_at_iter (self, &_tmp15_);
	_g_object_unref0 (link_box);
}

static void
widgets_markdown_editor_show_edit_link_popover (WidgetsMarkdownEditor* self,
                                                GtkTextIter* iter)
{
	gchar* url = NULL;
	GtkTextIter _tmp0_;
	gchar* _tmp1_;
	GtkEntry* _tmp2_;
	const gchar* _tmp3_;
	GtkBox* link_box = NULL;
	GtkPopover* _tmp4_;
	GtkWidget* _tmp5_;
	GtkWidget* _tmp6_;
	GtkBox* _tmp7_;
	GtkBox* _tmp8_;
	GtkWidget* _tmp9_;
	GtkButton* _tmp10_;
	GtkBox* _tmp13_;
	GtkWidget* _tmp14_;
	GtkButton* _tmp15_;
	GtkTextIter _tmp18_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (iter != NULL);
	self->priv->editing_existing_link = TRUE;
	_tmp0_ = *iter;
	_tmp1_ = widgets_markdown_editor_extract_url_from_link (self, &_tmp0_);
	url = _tmp1_;
	_tmp2_ = self->priv->link_entry;
	_tmp3_ = url;
	gtk_editable_set_text ((GtkEditable*) _tmp2_, _tmp3_);
	_tmp4_ = self->priv->link_popover;
	_tmp5_ = gtk_popover_get_child (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gtk_box_get_type (), GtkBox));
	link_box = _tmp7_;
	_tmp8_ = link_box;
	_tmp9_ = gtk_widget_get_last_child ((GtkWidget*) _tmp8_);
	_tmp10_ = self->priv->link_apply_button;
	if (_tmp9_ == G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, gtk_widget_get_type (), GtkWidget)) {
		GtkBox* _tmp11_;
		GtkButton* _tmp12_;
		_tmp11_ = link_box;
		_tmp12_ = self->priv->link_apply_button;
		gtk_box_remove (_tmp11_, (GtkWidget*) _tmp12_);
	}
	_tmp13_ = link_box;
	_tmp14_ = gtk_widget_get_last_child ((GtkWidget*) _tmp13_);
	_tmp15_ = self->priv->link_remove_button;
	if (_tmp14_ != G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, gtk_widget_get_type (), GtkWidget)) {
		GtkBox* _tmp16_;
		GtkButton* _tmp17_;
		_tmp16_ = link_box;
		_tmp17_ = self->priv->link_remove_button;
		gtk_box_append (_tmp16_, (GtkWidget*) _tmp17_);
	}
	_tmp18_ = *iter;
	widgets_markdown_editor_show_link_popover_at_iter (self, &_tmp18_);
	_g_object_unref0 (link_box);
	_g_free0 (url);
}

static void
widgets_markdown_editor_show_link_popover_at_iter (WidgetsMarkdownEditor* self,
                                                   GtkTextIter* iter)
{
	GdkRectangle rect = {0};
	GtkTextView* _tmp0_;
	GtkTextIter _tmp1_;
	GdkRectangle _tmp2_ = {0};
	gint x = 0;
	gint y = 0;
	GtkTextView* _tmp3_;
	GdkRectangle _tmp4_;
	GdkRectangle _tmp5_;
	gint _tmp6_ = 0;
	gint _tmp7_ = 0;
	GtkPopover* _tmp8_;
	GtkTextView* _tmp9_;
	GtkPopover* _tmp10_;
	GdkRectangle _tmp11_;
	GtkPopover* _tmp12_;
	GtkEntry* _tmp13_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (iter != NULL);
	_tmp0_ = self->text_view;
	_tmp1_ = *iter;
	gtk_text_view_get_iter_location (_tmp0_, &_tmp1_, &_tmp2_);
	rect = _tmp2_;
	_tmp3_ = self->text_view;
	_tmp4_ = rect;
	_tmp5_ = rect;
	gtk_text_view_buffer_to_window_coords (_tmp3_, GTK_TEXT_WINDOW_TEXT, _tmp4_.x, _tmp5_.y, &_tmp6_, &_tmp7_);
	x = _tmp6_;
	y = _tmp7_;
	rect.x = x;
	rect.y = y - 12;
	_tmp8_ = self->priv->link_popover;
	_tmp9_ = self->text_view;
	gtk_widget_set_parent ((GtkWidget*) _tmp8_, (GtkWidget*) _tmp9_);
	_tmp10_ = self->priv->link_popover;
	_tmp11_ = rect;
	gtk_popover_set_pointing_to (_tmp10_, &_tmp11_);
	_tmp12_ = self->priv->link_popover;
	gtk_popover_popup (_tmp12_);
	_tmp13_ = self->priv->link_entry;
	gtk_widget_grab_focus ((GtkWidget*) _tmp13_);
}

static void
widgets_markdown_editor_on_link_apply_clicked (WidgetsMarkdownEditor* self)
{
	gchar* url = NULL;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	GtkPopover* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->link_entry;
	_tmp1_ = gtk_editable_get_text ((GtkEditable*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	url = _tmp3_;
	_tmp4_ = url;
	if (g_strcmp0 (_tmp4_, "") != 0) {
		const gchar* _tmp5_;
		_tmp5_ = url;
		widgets_markdown_editor_apply_link_format (self, _tmp5_);
	}
	_tmp6_ = self->priv->link_popover;
	gtk_popover_popdown (_tmp6_);
	_g_free0 (url);
}

static void
widgets_markdown_editor_on_link_remove_clicked (WidgetsMarkdownEditor* self)
{
	GtkPopover* _tmp0_;
	g_return_if_fail (self != NULL);
	widgets_markdown_editor_remove_link_format (self);
	_tmp0_ = self->priv->link_popover;
	gtk_popover_popdown (_tmp0_);
}

static void
widgets_markdown_editor_on_link_entry_changed (WidgetsMarkdownEditor* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->editing_existing_link) {
		gchar* url = NULL;
		GtkEntry* _tmp0_;
		const gchar* _tmp1_;
		const gchar* _tmp2_;
		gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp0_ = self->priv->link_entry;
		_tmp1_ = gtk_editable_get_text ((GtkEditable*) _tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = string_strip (_tmp2_);
		url = _tmp3_;
		_tmp4_ = url;
		if (g_strcmp0 (_tmp4_, "") != 0) {
			GtkTextMark* cursor = NULL;
			GtkSourceBuffer* _tmp5_;
			GtkTextMark* _tmp6_;
			GtkTextMark* _tmp7_;
			GtkTextIter iter = {0};
			GtkSourceBuffer* _tmp8_;
			GtkTextMark* _tmp9_;
			GtkTextIter _tmp10_ = {0};
			GtkTextTag* _tmp11_;
			_tmp5_ = self->buffer;
			_tmp6_ = gtk_text_buffer_get_insert ((GtkTextBuffer*) _tmp5_);
			_tmp7_ = _g_object_ref0 (_tmp6_);
			cursor = _tmp7_;
			_tmp8_ = self->buffer;
			_tmp9_ = cursor;
			gtk_text_buffer_get_iter_at_mark ((GtkTextBuffer*) _tmp8_, &_tmp10_, _tmp9_);
			iter = _tmp10_;
			_tmp11_ = self->priv->link_tag;
			if (gtk_text_iter_has_tag (&iter, _tmp11_)) {
				GtkTextIter _tmp12_;
				const gchar* _tmp13_;
				_tmp12_ = iter;
				_tmp13_ = url;
				widgets_markdown_editor_replace_link_url_at_cursor (self, &_tmp12_, _tmp13_);
			}
			_g_object_unref0 (cursor);
		}
		_g_free0 (url);
	}
}

static void
widgets_markdown_editor_apply_link_format (WidgetsMarkdownEditor* self,
                                           const gchar* url)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (url != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		WidgetsMarkdownEditorExpandedRange expanded = {0};
		GtkTextIter _tmp4_;
		GtkTextIter _tmp5_;
		WidgetsMarkdownEditorExpandedRange _tmp6_ = {0};
		gchar* clean_text = NULL;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		GtkSourceBuffer* _tmp9_;
		GtkSourceBuffer* _tmp10_;
		const gchar* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		gchar* _tmp19_;
		_tmp4_ = start;
		_tmp5_ = end;
		widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp4_, &_tmp5_, &_tmp6_);
		expanded = _tmp6_;
		_tmp7_ = self->priv->selected_link_text;
		_tmp8_ = g_strdup (_tmp7_);
		clean_text = _tmp8_;
		_tmp9_ = self->buffer;
		gtk_text_buffer_delete ((GtkTextBuffer*) _tmp9_, &expanded.start, &expanded.end);
		_tmp10_ = self->buffer;
		_tmp11_ = clean_text;
		_tmp12_ = g_strconcat ("[", _tmp11_, NULL);
		_tmp13_ = _tmp12_;
		_tmp14_ = g_strconcat (_tmp13_, "](", NULL);
		_tmp15_ = _tmp14_;
		_tmp16_ = g_strconcat (_tmp15_, url, NULL);
		_tmp17_ = _tmp16_;
		_tmp18_ = g_strconcat (_tmp17_, ")", NULL);
		_tmp19_ = _tmp18_;
		gtk_text_buffer_insert ((GtkTextBuffer*) _tmp10_, &expanded.start, _tmp19_, -1);
		_g_free0 (_tmp19_);
		_g_free0 (_tmp17_);
		_g_free0 (_tmp15_);
		_g_free0 (_tmp13_);
		widgets_markdown_editor_apply_markdown_formatting (self);
		_g_free0 (clean_text);
	} else {
		GtkTextMark* cursor = NULL;
		GtkSourceBuffer* _tmp20_;
		GtkTextMark* _tmp21_;
		GtkTextMark* _tmp22_;
		GtkTextIter iter = {0};
		GtkSourceBuffer* _tmp23_;
		GtkTextMark* _tmp24_;
		GtkTextIter _tmp25_ = {0};
		GtkTextTag* _tmp26_;
		_tmp20_ = self->buffer;
		_tmp21_ = gtk_text_buffer_get_insert ((GtkTextBuffer*) _tmp20_);
		_tmp22_ = _g_object_ref0 (_tmp21_);
		cursor = _tmp22_;
		_tmp23_ = self->buffer;
		_tmp24_ = cursor;
		gtk_text_buffer_get_iter_at_mark ((GtkTextBuffer*) _tmp23_, &_tmp25_, _tmp24_);
		iter = _tmp25_;
		_tmp26_ = self->priv->link_tag;
		if (gtk_text_iter_has_tag (&iter, _tmp26_)) {
			GtkTextIter _tmp27_;
			_tmp27_ = iter;
			widgets_markdown_editor_replace_link_url_at_cursor (self, &_tmp27_, url);
		}
		_g_object_unref0 (cursor);
	}
}

static void
widgets_markdown_editor_remove_link_format (WidgetsMarkdownEditor* self)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->buffer;
	_tmp3_ = gtk_text_buffer_get_selection_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	if (_tmp3_) {
		WidgetsMarkdownEditorExpandedRange expanded = {0};
		GtkTextIter _tmp4_;
		GtkTextIter _tmp5_;
		WidgetsMarkdownEditorExpandedRange _tmp6_ = {0};
		gchar* clean_text = NULL;
		WidgetsMarkdownEditorExpandedRange _tmp7_;
		GtkTextIter _tmp8_;
		WidgetsMarkdownEditorExpandedRange _tmp9_;
		GtkTextIter _tmp10_;
		gchar* _tmp11_;
		GtkSourceBuffer* _tmp12_;
		GtkSourceBuffer* _tmp13_;
		const gchar* _tmp14_;
		_tmp4_ = start;
		_tmp5_ = end;
		widgets_markdown_editor_expand_selection_for_asterisks (self, &_tmp4_, &_tmp5_, &_tmp6_);
		expanded = _tmp6_;
		_tmp7_ = expanded;
		_tmp8_ = _tmp7_.start;
		_tmp9_ = expanded;
		_tmp10_ = _tmp9_.end;
		_tmp11_ = widgets_markdown_editor_get_clean_text_from_range (self, &_tmp8_, &_tmp10_);
		clean_text = _tmp11_;
		_tmp12_ = self->buffer;
		gtk_text_buffer_delete ((GtkTextBuffer*) _tmp12_, &expanded.start, &expanded.end);
		_tmp13_ = self->buffer;
		_tmp14_ = clean_text;
		gtk_text_buffer_insert ((GtkTextBuffer*) _tmp13_, &expanded.start, _tmp14_, -1);
		widgets_markdown_editor_apply_markdown_formatting (self);
		_g_free0 (clean_text);
	} else {
		GtkTextMark* cursor = NULL;
		GtkSourceBuffer* _tmp15_;
		GtkTextMark* _tmp16_;
		GtkTextMark* _tmp17_;
		GtkTextIter iter = {0};
		GtkSourceBuffer* _tmp18_;
		GtkTextMark* _tmp19_;
		GtkTextIter _tmp20_ = {0};
		GtkTextTag* _tmp21_;
		_tmp15_ = self->buffer;
		_tmp16_ = gtk_text_buffer_get_insert ((GtkTextBuffer*) _tmp15_);
		_tmp17_ = _g_object_ref0 (_tmp16_);
		cursor = _tmp17_;
		_tmp18_ = self->buffer;
		_tmp19_ = cursor;
		gtk_text_buffer_get_iter_at_mark ((GtkTextBuffer*) _tmp18_, &_tmp20_, _tmp19_);
		iter = _tmp20_;
		_tmp21_ = self->priv->link_tag;
		if (gtk_text_iter_has_tag (&iter, _tmp21_)) {
			GtkTextIter _tmp22_;
			_tmp22_ = iter;
			widgets_markdown_editor_remove_link_at_cursor (self, &_tmp22_);
		}
		_g_object_unref0 (cursor);
	}
}

static gchar*
widgets_markdown_editor_extract_url_from_link (WidgetsMarkdownEditor* self,
                                               GtkTextIter* iter)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gchar* text = NULL;
	GtkSourceBuffer* _tmp3_;
	GtkTextIter _tmp4_;
	GtkTextIter _tmp5_;
	gchar* _tmp6_;
	gint cursor_offset = 0;
	gchar* _tmp53_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (iter != NULL, NULL);
	_tmp0_ = self->buffer;
	gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	_tmp3_ = self->buffer;
	_tmp4_ = start;
	_tmp5_ = end;
	_tmp6_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp3_, &_tmp4_, &_tmp5_, TRUE);
	text = _tmp6_;
	cursor_offset = gtk_text_iter_get_offset (iter);
	{
		GRegex* regex = NULL;
		GRegex* _tmp7_;
		GMatchInfo* match_info = NULL;
		GRegex* _tmp8_;
		const gchar* _tmp9_;
		GMatchInfo* _tmp10_ = NULL;
		gboolean _tmp11_;
		GRegex* plain_url_regex = NULL;
		GRegex* _tmp29_;
		GRegex* _tmp30_;
		const gchar* _tmp31_;
		GMatchInfo* _tmp32_ = NULL;
		gboolean _tmp33_;
		_tmp7_ = g_regex_new ("\\[([^\\]]+)\\]\\(([^\\)]+)\\)", 0, 0, &_inner_error0_);
		regex = _tmp7_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = text;
		_tmp11_ = g_regex_match (_tmp8_, _tmp9_, 0, &_tmp10_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp10_;
		if (_tmp11_) {
			{
				gboolean _tmp12_ = FALSE;
				_tmp12_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp15_;
					gint _tmp16_ = 0;
					gint _tmp17_ = 0;
					gint start_chars = 0;
					const gchar* _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					gint _tmp21_;
					gint end_chars = 0;
					const gchar* _tmp22_;
					gchar* _tmp23_;
					gchar* _tmp24_;
					gint _tmp25_;
					gboolean _tmp26_ = FALSE;
					if (!_tmp12_) {
						gboolean _tmp13_ = FALSE;
						GMatchInfo* _tmp14_;
						_tmp14_ = match_info;
						_tmp13_ = g_match_info_next (_tmp14_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return NULL;
						}
						if (!_tmp13_) {
							break;
						}
					}
					_tmp12_ = FALSE;
					_tmp15_ = match_info;
					g_match_info_fetch_pos (_tmp15_, 1, &_tmp16_, &_tmp17_);
					start_pos = _tmp16_;
					end_pos = _tmp17_;
					_tmp18_ = text;
					_tmp19_ = string_substring (_tmp18_, (glong) 0, (glong) start_pos);
					_tmp20_ = _tmp19_;
					_tmp21_ = g_utf8_strlen (_tmp20_, (gssize) -1);
					_g_free0 (_tmp20_);
					start_chars = _tmp21_;
					_tmp22_ = text;
					_tmp23_ = string_substring (_tmp22_, (glong) 0, (glong) end_pos);
					_tmp24_ = _tmp23_;
					_tmp25_ = g_utf8_strlen (_tmp24_, (gssize) -1);
					_g_free0 (_tmp24_);
					end_chars = _tmp25_;
					if (cursor_offset >= start_chars) {
						_tmp26_ = cursor_offset <= end_chars;
					} else {
						_tmp26_ = FALSE;
					}
					if (_tmp26_) {
						GMatchInfo* _tmp27_;
						gchar* _tmp28_;
						_tmp27_ = match_info;
						_tmp28_ = g_match_info_fetch (_tmp27_, 2);
						result = _tmp28_;
						_g_match_info_unref0 (match_info);
						_g_regex_unref0 (regex);
						_g_free0 (text);
						return result;
					}
				}
			}
		}
		_tmp29_ = g_regex_new ("\\b[a-zA-Z][a-zA-Z0-9+.-]*://[^\\s)]+", 0, 0, &_inner_error0_);
		plain_url_regex = _tmp29_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_match_info_unref0 (match_info);
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp30_ = plain_url_regex;
		_tmp31_ = text;
		_tmp33_ = g_regex_match (_tmp30_, _tmp31_, 0, &_tmp32_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp32_;
		if (_tmp33_) {
			{
				gboolean _tmp34_ = FALSE;
				_tmp34_ = TRUE;
				while (TRUE) {
					gint start_pos = 0;
					gint end_pos = 0;
					GMatchInfo* _tmp37_;
					gint _tmp38_ = 0;
					gint _tmp39_ = 0;
					gint start_chars = 0;
					const gchar* _tmp40_;
					gchar* _tmp41_;
					gchar* _tmp42_;
					gint _tmp43_;
					gint end_chars = 0;
					const gchar* _tmp44_;
					gchar* _tmp45_;
					gchar* _tmp46_;
					gint _tmp47_;
					gboolean _tmp48_ = FALSE;
					if (!_tmp34_) {
						gboolean _tmp35_ = FALSE;
						GMatchInfo* _tmp36_;
						_tmp36_ = match_info;
						_tmp35_ = g_match_info_next (_tmp36_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_regex_unref0 (plain_url_regex);
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return NULL;
						}
						if (!_tmp35_) {
							break;
						}
					}
					_tmp34_ = FALSE;
					_tmp37_ = match_info;
					g_match_info_fetch_pos (_tmp37_, 0, &_tmp38_, &_tmp39_);
					start_pos = _tmp38_;
					end_pos = _tmp39_;
					_tmp40_ = text;
					_tmp41_ = string_substring (_tmp40_, (glong) 0, (glong) start_pos);
					_tmp42_ = _tmp41_;
					_tmp43_ = g_utf8_strlen (_tmp42_, (gssize) -1);
					_g_free0 (_tmp42_);
					start_chars = _tmp43_;
					_tmp44_ = text;
					_tmp45_ = string_substring (_tmp44_, (glong) 0, (glong) end_pos);
					_tmp46_ = _tmp45_;
					_tmp47_ = g_utf8_strlen (_tmp46_, (gssize) -1);
					_g_free0 (_tmp46_);
					end_chars = _tmp47_;
					if (cursor_offset >= start_chars) {
						_tmp48_ = cursor_offset <= end_chars;
					} else {
						_tmp48_ = FALSE;
					}
					if (_tmp48_) {
						GMatchInfo* _tmp49_;
						gchar* _tmp50_;
						_tmp49_ = match_info;
						_tmp50_ = g_match_info_fetch (_tmp49_, 0);
						result = _tmp50_;
						_g_regex_unref0 (plain_url_regex);
						_g_match_info_unref0 (match_info);
						_g_regex_unref0 (regex);
						_g_free0 (text);
						return result;
					}
				}
			}
		}
		_g_regex_unref0 (plain_url_regex);
		_g_match_info_unref0 (match_info);
		_g_regex_unref0 (regex);
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError* e = NULL;
		GError* _tmp51_;
		const gchar* _tmp52_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp51_ = e;
		_tmp52_ = _tmp51_->message;
		g_warning ("MarkdownEditor.vala:1579: Error in regex: %s", _tmp52_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (text);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	_tmp53_ = g_strdup ("");
	result = _tmp53_;
	_g_free0 (text);
	return result;
}

static void
widgets_markdown_editor_replace_link_url_at_cursor (WidgetsMarkdownEditor* self,
                                                    GtkTextIter* iter,
                                                    const gchar* new_url)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gchar* text = NULL;
	GtkSourceBuffer* _tmp3_;
	GtkTextIter _tmp4_;
	GtkTextIter _tmp5_;
	gchar* _tmp6_;
	gint cursor_offset = 0;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (iter != NULL);
	g_return_if_fail (new_url != NULL);
	_tmp0_ = self->buffer;
	gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	_tmp3_ = self->buffer;
	_tmp4_ = start;
	_tmp5_ = end;
	_tmp6_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp3_, &_tmp4_, &_tmp5_, TRUE);
	text = _tmp6_;
	cursor_offset = gtk_text_iter_get_offset (iter);
	{
		GRegex* regex = NULL;
		GRegex* _tmp7_;
		GMatchInfo* match_info = NULL;
		GRegex* _tmp8_;
		const gchar* _tmp9_;
		GMatchInfo* _tmp10_ = NULL;
		gboolean _tmp11_;
		_tmp7_ = g_regex_new ("\\[([^\\]]+)\\]\\(([^\\)]+)\\)", 0, 0, &_inner_error0_);
		regex = _tmp7_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp8_ = regex;
		_tmp9_ = text;
		_tmp11_ = g_regex_match (_tmp8_, _tmp9_, 0, &_tmp10_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp10_;
		if (_tmp11_) {
			{
				gboolean _tmp12_ = FALSE;
				_tmp12_ = TRUE;
				while (TRUE) {
					gint text_start_pos = 0;
					gint text_end_pos = 0;
					GMatchInfo* _tmp15_;
					gint _tmp16_ = 0;
					gint _tmp17_ = 0;
					gint text_start_chars = 0;
					const gchar* _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					gint _tmp21_;
					gint text_end_chars = 0;
					const gchar* _tmp22_;
					gchar* _tmp23_;
					gchar* _tmp24_;
					gint _tmp25_;
					gboolean _tmp26_ = FALSE;
					if (!_tmp12_) {
						gboolean _tmp13_ = FALSE;
						GMatchInfo* _tmp14_;
						_tmp14_ = match_info;
						_tmp13_ = g_match_info_next (_tmp14_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp13_) {
							break;
						}
					}
					_tmp12_ = FALSE;
					_tmp15_ = match_info;
					g_match_info_fetch_pos (_tmp15_, 1, &_tmp16_, &_tmp17_);
					text_start_pos = _tmp16_;
					text_end_pos = _tmp17_;
					_tmp18_ = text;
					_tmp19_ = string_substring (_tmp18_, (glong) 0, (glong) text_start_pos);
					_tmp20_ = _tmp19_;
					_tmp21_ = g_utf8_strlen (_tmp20_, (gssize) -1);
					_g_free0 (_tmp20_);
					text_start_chars = _tmp21_;
					_tmp22_ = text;
					_tmp23_ = string_substring (_tmp22_, (glong) 0, (glong) text_end_pos);
					_tmp24_ = _tmp23_;
					_tmp25_ = g_utf8_strlen (_tmp24_, (gssize) -1);
					_g_free0 (_tmp24_);
					text_end_chars = _tmp25_;
					if (cursor_offset >= text_start_chars) {
						_tmp26_ = cursor_offset <= text_end_chars;
					} else {
						_tmp26_ = FALSE;
					}
					if (_tmp26_) {
						gint full_start_pos = 0;
						gint full_end_pos = 0;
						GMatchInfo* _tmp27_;
						gint _tmp28_ = 0;
						gint _tmp29_ = 0;
						gint full_start_chars = 0;
						const gchar* _tmp30_;
						gchar* _tmp31_;
						gchar* _tmp32_;
						gint _tmp33_;
						gint full_end_chars = 0;
						const gchar* _tmp34_;
						gchar* _tmp35_;
						gchar* _tmp36_;
						gint _tmp37_;
						GtkTextIter link_start = {0};
						GtkTextIter link_end = {0};
						GtkSourceBuffer* _tmp38_;
						GtkTextIter _tmp39_ = {0};
						GtkSourceBuffer* _tmp40_;
						GtkTextIter _tmp41_ = {0};
						gchar* link_text = NULL;
						GMatchInfo* _tmp42_;
						gchar* _tmp43_;
						GtkSourceBuffer* _tmp44_;
						GtkSourceBuffer* _tmp45_;
						const gchar* _tmp46_;
						gchar* _tmp47_;
						gchar* _tmp48_;
						gchar* _tmp49_;
						gchar* _tmp50_;
						gchar* _tmp51_;
						gchar* _tmp52_;
						gchar* _tmp53_;
						gchar* _tmp54_;
						_tmp27_ = match_info;
						g_match_info_fetch_pos (_tmp27_, 0, &_tmp28_, &_tmp29_);
						full_start_pos = _tmp28_;
						full_end_pos = _tmp29_;
						_tmp30_ = text;
						_tmp31_ = string_substring (_tmp30_, (glong) 0, (glong) full_start_pos);
						_tmp32_ = _tmp31_;
						_tmp33_ = g_utf8_strlen (_tmp32_, (gssize) -1);
						_g_free0 (_tmp32_);
						full_start_chars = _tmp33_;
						_tmp34_ = text;
						_tmp35_ = string_substring (_tmp34_, (glong) 0, (glong) full_end_pos);
						_tmp36_ = _tmp35_;
						_tmp37_ = g_utf8_strlen (_tmp36_, (gssize) -1);
						_g_free0 (_tmp36_);
						full_end_chars = _tmp37_;
						_tmp38_ = self->buffer;
						gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp38_, &_tmp39_, full_start_chars);
						link_start = _tmp39_;
						_tmp40_ = self->buffer;
						gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp40_, &_tmp41_, full_end_chars);
						link_end = _tmp41_;
						_tmp42_ = match_info;
						_tmp43_ = g_match_info_fetch (_tmp42_, 1);
						link_text = _tmp43_;
						_tmp44_ = self->buffer;
						gtk_text_buffer_delete ((GtkTextBuffer*) _tmp44_, &link_start, &link_end);
						_tmp45_ = self->buffer;
						_tmp46_ = link_text;
						_tmp47_ = g_strconcat ("[", _tmp46_, NULL);
						_tmp48_ = _tmp47_;
						_tmp49_ = g_strconcat (_tmp48_, "](", NULL);
						_tmp50_ = _tmp49_;
						_tmp51_ = g_strconcat (_tmp50_, new_url, NULL);
						_tmp52_ = _tmp51_;
						_tmp53_ = g_strconcat (_tmp52_, ")", NULL);
						_tmp54_ = _tmp53_;
						gtk_text_buffer_insert ((GtkTextBuffer*) _tmp45_, &link_start, _tmp54_, -1);
						_g_free0 (_tmp54_);
						_g_free0 (_tmp52_);
						_g_free0 (_tmp50_);
						_g_free0 (_tmp48_);
						widgets_markdown_editor_apply_markdown_formatting (self);
						_g_free0 (link_text);
						_g_match_info_unref0 (match_info);
						_g_regex_unref0 (regex);
						_g_free0 (text);
						return;
					}
				}
			}
		}
		_g_match_info_unref0 (match_info);
		_g_regex_unref0 (regex);
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError* e = NULL;
		GError* _tmp55_;
		const gchar* _tmp56_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp55_ = e;
		_tmp56_ = _tmp55_->message;
		g_warning ("MarkdownEditor.vala:1626: Error in regex: %s", _tmp56_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (text);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_free0 (text);
}

static void
widgets_markdown_editor_remove_link_at_cursor (WidgetsMarkdownEditor* self,
                                               GtkTextIter* iter)
{
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkSourceBuffer* _tmp0_;
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp2_ = {0};
	gchar* text = NULL;
	GtkSourceBuffer* _tmp3_;
	GtkTextIter _tmp4_;
	GtkTextIter _tmp5_;
	gchar* _tmp6_;
	gint cursor_offset = 0;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (iter != NULL);
	_tmp0_ = self->buffer;
	gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp0_, &_tmp1_, &_tmp2_);
	start = _tmp1_;
	end = _tmp2_;
	_tmp3_ = self->buffer;
	_tmp4_ = start;
	_tmp5_ = end;
	_tmp6_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp3_, &_tmp4_, &_tmp5_, TRUE);
	text = _tmp6_;
	cursor_offset = gtk_text_iter_get_offset (iter);
	{
		GRegex* regex = NULL;
		GRegex* _tmp7_;
		GMatchInfo* match_info = NULL;
		GRegex* _tmp8_;
		const gchar* _tmp9_;
		GMatchInfo* _tmp10_ = NULL;
		gboolean _tmp11_;
		_tmp7_ = g_regex_new ("\\[([^\\]]+)\\]\\(([^\\)]+)\\)", 0, 0, &_inner_error0_);
		regex = _tmp7_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (text);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp8_ = regex;
		_tmp9_ = text;
		_tmp11_ = g_regex_match (_tmp8_, _tmp9_, 0, &_tmp10_);
		_g_match_info_unref0 (match_info);
		match_info = _tmp10_;
		if (_tmp11_) {
			{
				gboolean _tmp12_ = FALSE;
				_tmp12_ = TRUE;
				while (TRUE) {
					gint text_start_pos = 0;
					gint text_end_pos = 0;
					GMatchInfo* _tmp15_;
					gint _tmp16_ = 0;
					gint _tmp17_ = 0;
					gint text_start_chars = 0;
					const gchar* _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					gint _tmp21_;
					gint text_end_chars = 0;
					const gchar* _tmp22_;
					gchar* _tmp23_;
					gchar* _tmp24_;
					gint _tmp25_;
					gboolean _tmp26_ = FALSE;
					if (!_tmp12_) {
						gboolean _tmp13_ = FALSE;
						GMatchInfo* _tmp14_;
						_tmp14_ = match_info;
						_tmp13_ = g_match_info_next (_tmp14_, &_inner_error0_);
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_g_match_info_unref0 (match_info);
							_g_regex_unref0 (regex);
							if (_inner_error0_->domain == G_REGEX_ERROR) {
								goto __catch0_g_regex_error;
							}
							_g_free0 (text);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return;
						}
						if (!_tmp13_) {
							break;
						}
					}
					_tmp12_ = FALSE;
					_tmp15_ = match_info;
					g_match_info_fetch_pos (_tmp15_, 1, &_tmp16_, &_tmp17_);
					text_start_pos = _tmp16_;
					text_end_pos = _tmp17_;
					_tmp18_ = text;
					_tmp19_ = string_substring (_tmp18_, (glong) 0, (glong) text_start_pos);
					_tmp20_ = _tmp19_;
					_tmp21_ = g_utf8_strlen (_tmp20_, (gssize) -1);
					_g_free0 (_tmp20_);
					text_start_chars = _tmp21_;
					_tmp22_ = text;
					_tmp23_ = string_substring (_tmp22_, (glong) 0, (glong) text_end_pos);
					_tmp24_ = _tmp23_;
					_tmp25_ = g_utf8_strlen (_tmp24_, (gssize) -1);
					_g_free0 (_tmp24_);
					text_end_chars = _tmp25_;
					if (cursor_offset >= text_start_chars) {
						_tmp26_ = cursor_offset <= text_end_chars;
					} else {
						_tmp26_ = FALSE;
					}
					if (_tmp26_) {
						gint full_start_pos = 0;
						gint full_end_pos = 0;
						GMatchInfo* _tmp27_;
						gint _tmp28_ = 0;
						gint _tmp29_ = 0;
						gint full_start_chars = 0;
						const gchar* _tmp30_;
						gchar* _tmp31_;
						gchar* _tmp32_;
						gint _tmp33_;
						gint full_end_chars = 0;
						const gchar* _tmp34_;
						gchar* _tmp35_;
						gchar* _tmp36_;
						gint _tmp37_;
						GtkTextIter link_start = {0};
						GtkTextIter link_end = {0};
						GtkSourceBuffer* _tmp38_;
						GtkTextIter _tmp39_ = {0};
						GtkSourceBuffer* _tmp40_;
						GtkTextIter _tmp41_ = {0};
						gchar* link_text = NULL;
						GMatchInfo* _tmp42_;
						gchar* _tmp43_;
						GtkSourceBuffer* _tmp44_;
						GtkSourceBuffer* _tmp45_;
						const gchar* _tmp46_;
						_tmp27_ = match_info;
						g_match_info_fetch_pos (_tmp27_, 0, &_tmp28_, &_tmp29_);
						full_start_pos = _tmp28_;
						full_end_pos = _tmp29_;
						_tmp30_ = text;
						_tmp31_ = string_substring (_tmp30_, (glong) 0, (glong) full_start_pos);
						_tmp32_ = _tmp31_;
						_tmp33_ = g_utf8_strlen (_tmp32_, (gssize) -1);
						_g_free0 (_tmp32_);
						full_start_chars = _tmp33_;
						_tmp34_ = text;
						_tmp35_ = string_substring (_tmp34_, (glong) 0, (glong) full_end_pos);
						_tmp36_ = _tmp35_;
						_tmp37_ = g_utf8_strlen (_tmp36_, (gssize) -1);
						_g_free0 (_tmp36_);
						full_end_chars = _tmp37_;
						_tmp38_ = self->buffer;
						gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp38_, &_tmp39_, full_start_chars);
						link_start = _tmp39_;
						_tmp40_ = self->buffer;
						gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp40_, &_tmp41_, full_end_chars);
						link_end = _tmp41_;
						_tmp42_ = match_info;
						_tmp43_ = g_match_info_fetch (_tmp42_, 1);
						link_text = _tmp43_;
						_tmp44_ = self->buffer;
						gtk_text_buffer_delete ((GtkTextBuffer*) _tmp44_, &link_start, &link_end);
						_tmp45_ = self->buffer;
						_tmp46_ = link_text;
						gtk_text_buffer_insert ((GtkTextBuffer*) _tmp45_, &link_start, _tmp46_, -1);
						widgets_markdown_editor_apply_markdown_formatting (self);
						_g_free0 (link_text);
						_g_match_info_unref0 (match_info);
						_g_regex_unref0 (regex);
						_g_free0 (text);
						return;
					}
				}
			}
		}
		_g_match_info_unref0 (match_info);
		_g_regex_unref0 (regex);
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError* e = NULL;
		GError* _tmp47_;
		const gchar* _tmp48_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp47_ = e;
		_tmp48_ = _tmp47_->message;
		g_warning ("MarkdownEditor.vala:1671: Error in regex: %s", _tmp48_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (text);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_free0 (text);
}

static void
widgets_markdown_editor_on_text_clicked (WidgetsMarkdownEditor* self,
                                         gint n_press,
                                         gdouble x,
                                         gdouble y)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	gint buffer_x = 0;
	gint buffer_y = 0;
	GtkTextView* _tmp2_;
	gint _tmp3_ = 0;
	gint _tmp4_ = 0;
	GtkTextIter iter = {0};
	GtkTextView* _tmp5_;
	GtkTextIter _tmp6_ = {0};
	GtkTextTag* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = widgets_markdown_editor_get_text_mode (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		return;
	}
	_tmp2_ = self->text_view;
	gtk_text_view_window_to_buffer_coords (_tmp2_, GTK_TEXT_WINDOW_TEXT, (gint) x, (gint) y, &_tmp3_, &_tmp4_);
	buffer_x = _tmp3_;
	buffer_y = _tmp4_;
	_tmp5_ = self->text_view;
	gtk_text_view_get_iter_at_location (_tmp5_, &_tmp6_, buffer_x, buffer_y);
	iter = _tmp6_;
	_tmp7_ = self->priv->link_tag;
	if (gtk_text_iter_has_tag (&iter, _tmp7_)) {
		GdkModifierType current_state = 0U;
		GtkGestureClick* _tmp8_;
		_tmp8_ = self->priv->gesture_click;
		current_state = gtk_event_controller_get_current_event_state ((GtkEventController*) _tmp8_);
		if ((current_state & GDK_CONTROL_MASK) != 0) {
			GtkTextIter _tmp9_;
			_tmp9_ = iter;
			widgets_markdown_editor_open_link_at_iter (self, &_tmp9_);
		} else {
			GtkSourceBuffer* _tmp10_;
			GtkTextIter _tmp11_;
			GtkTextIter _tmp12_;
			_tmp10_ = self->buffer;
			_tmp11_ = iter;
			gtk_text_buffer_place_cursor ((GtkTextBuffer*) _tmp10_, &_tmp11_);
			_tmp12_ = iter;
			widgets_markdown_editor_show_edit_link_popover (self, &_tmp12_);
		}
	}
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static gchar*
widgets_markdown_editor_normalize_url (WidgetsMarkdownEditor* self,
                                       const gchar* url)
{
	gchar* trimmed_url = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_ = FALSE;
	const gchar* _tmp6_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (url != NULL, NULL);
	_tmp0_ = string_strip (url);
	trimmed_url = _tmp0_;
	_tmp1_ = trimmed_url;
	_tmp2_ = g_uri_parse_scheme (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_ != NULL;
	_g_free0 (_tmp3_);
	if (_tmp4_) {
		result = trimmed_url;
		return result;
	}
	_tmp6_ = trimmed_url;
	if (string_contains (_tmp6_, ".")) {
		const gchar* _tmp7_;
		_tmp7_ = trimmed_url;
		_tmp5_ = !string_contains (_tmp7_, " ");
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		const gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp8_ = trimmed_url;
		_tmp9_ = g_strconcat ("https://", _tmp8_, NULL);
		result = _tmp9_;
		_g_free0 (trimmed_url);
		return result;
	}
	result = trimmed_url;
	return result;
}

static void
widgets_markdown_editor_open_link_at_iter (WidgetsMarkdownEditor* self,
                                           GtkTextIter* iter)
{
	gchar* url = NULL;
	GtkTextIter _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (iter != NULL);
	_tmp0_ = *iter;
	_tmp1_ = widgets_markdown_editor_extract_url_from_link (self, &_tmp0_);
	url = _tmp1_;
	_tmp2_ = url;
	if (g_strcmp0 (_tmp2_, "") != 0) {
		gchar* normalized_url = NULL;
		const gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = url;
		_tmp4_ = widgets_markdown_editor_normalize_url (self, _tmp3_);
		normalized_url = _tmp4_;
		{
			const gchar* _tmp5_;
			_tmp5_ = normalized_url;
			g_app_info_launch_default_for_uri (_tmp5_, NULL, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			ServicesEventBus* _tmp6_;
			ServicesEventBus* _tmp7_;
			Util* _tmp8_;
			Util* _tmp9_;
			GError* _tmp10_;
			const gchar* _tmp11_;
			AdwToast* _tmp12_;
			AdwToast* _tmp13_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp6_ = services_event_bus_get_default ();
			_tmp7_ = _tmp6_;
			_tmp8_ = util_get_default ();
			_tmp9_ = _tmp8_;
			_tmp10_ = e;
			_tmp11_ = _tmp10_->message;
			_tmp12_ = util_create_toast (_tmp9_, _tmp11_, (guint) 2, ADW_TOAST_PRIORITY_NORMAL);
			_tmp13_ = _tmp12_;
			g_signal_emit_by_name (_tmp7_, "send-toast", _tmp13_);
			_g_object_unref0 (_tmp13_);
			_g_object_unref0 (_tmp9_);
			_g_object_unref0 (_tmp7_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (normalized_url);
			_g_free0 (url);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_g_free0 (normalized_url);
	}
	_g_free0 (url);
}

void
widgets_markdown_editor_view_focus (WidgetsMarkdownEditor* self)
{
	GtkTextView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->text_view;
	gtk_widget_grab_focus ((GtkWidget*) _tmp0_);
}

WidgetsMarkdownEditor*
widgets_markdown_editor_construct (GType object_type)
{
	WidgetsMarkdownEditor * self = NULL;
	self = (WidgetsMarkdownEditor*) g_object_new (object_type, NULL);
	return self;
}

WidgetsMarkdownEditor*
widgets_markdown_editor_new (void)
{
	return widgets_markdown_editor_construct (WIDGETS_TYPE_MARKDOWN_EDITOR);
}

const gchar*
widgets_markdown_editor_get_placeholder_text (WidgetsMarkdownEditor* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_placeholder_text;
	result = _tmp0_;
	return result;
}

void
widgets_markdown_editor_set_placeholder_text (WidgetsMarkdownEditor* self,
                                              const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_markdown_editor_get_placeholder_text (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_placeholder_text);
		self->priv->_placeholder_text = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, widgets_markdown_editor_properties[WIDGETS_MARKDOWN_EDITOR_PLACEHOLDER_TEXT_PROPERTY]);
	}
}

ObjectsProject*
widgets_markdown_editor_get_project (WidgetsMarkdownEditor* self)
{
	ObjectsProject* result;
	ObjectsProject* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_project;
	result = _tmp0_;
	return result;
}

void
widgets_markdown_editor_set_project (WidgetsMarkdownEditor* self,
                                     ObjectsProject* value)
{
	ObjectsProject* old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_markdown_editor_get_project (self);
	if (old_value != value) {
		ObjectsProject* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_project);
		self->priv->_project = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, widgets_markdown_editor_properties[WIDGETS_MARKDOWN_EDITOR_PROJECT_PROPERTY]);
	}
}

gboolean
widgets_markdown_editor_get_text_mode (WidgetsMarkdownEditor* self)
{
	gboolean result;
	ObjectsProject* _tmp0_;
	ServicesSettings* _tmp4_;
	ServicesSettings* _tmp5_;
	GSettings* _tmp6_;
	gboolean _tmp7_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_project;
	if (_tmp0_ != NULL) {
		ObjectsProject* _tmp1_;
		gboolean _tmp2_;
		gboolean _tmp3_;
		_tmp1_ = self->priv->_project;
		_tmp2_ = objects_project_get_is_markdown_enabled (_tmp1_);
		_tmp3_ = _tmp2_;
		result = !_tmp3_;
		return result;
	}
	_tmp4_ = services_settings_get_default ();
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_->settings;
	_tmp7_ = !g_settings_get_boolean (_tmp6_, "enable-markdown-formatting");
	_g_object_unref0 (_tmp5_);
	result = _tmp7_;
	return result;
}

gboolean
widgets_markdown_editor_get_is_editable (WidgetsMarkdownEditor* self)
{
	gboolean result;
	GtkTextView* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->text_view;
	_tmp1_ = gtk_text_view_get_editable (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

void
widgets_markdown_editor_set_is_editable (WidgetsMarkdownEditor* self,
                                         gboolean value)
{
	GtkTextView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->text_view;
	gtk_text_view_set_editable (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, widgets_markdown_editor_properties[WIDGETS_MARKDOWN_EDITOR_IS_EDITABLE_PROPERTY]);
}

static WidgetsMarkdownEditorExpandedRange*
widgets_markdown_editor_expanded_range_dup (const WidgetsMarkdownEditorExpandedRange* self)
{
	WidgetsMarkdownEditorExpandedRange* dup;
	dup = g_new0 (WidgetsMarkdownEditorExpandedRange, 1);
	memcpy (dup, self, sizeof (WidgetsMarkdownEditorExpandedRange));
	return dup;
}

static void
widgets_markdown_editor_expanded_range_free (WidgetsMarkdownEditorExpandedRange* self)
{
	g_free (self);
}

static GType
widgets_markdown_editor_expanded_range_get_type_once (void)
{
	GType widgets_markdown_editor_expanded_range_type_id;
	widgets_markdown_editor_expanded_range_type_id = g_boxed_type_register_static ("WidgetsMarkdownEditorExpandedRange", (GBoxedCopyFunc) widgets_markdown_editor_expanded_range_dup, (GBoxedFreeFunc) widgets_markdown_editor_expanded_range_free);
	return widgets_markdown_editor_expanded_range_type_id;
}

static GType
widgets_markdown_editor_expanded_range_get_type (void)
{
	static volatile gsize widgets_markdown_editor_expanded_range_type_id__once = 0;
	if (g_once_init_enter (&widgets_markdown_editor_expanded_range_type_id__once)) {
		GType widgets_markdown_editor_expanded_range_type_id;
		widgets_markdown_editor_expanded_range_type_id = widgets_markdown_editor_expanded_range_get_type_once ();
		g_once_init_leave (&widgets_markdown_editor_expanded_range_type_id__once, widgets_markdown_editor_expanded_range_type_id);
	}
	return widgets_markdown_editor_expanded_range_type_id__once;
}

static Block19Data*
block19_data_ref (Block19Data* _data19_)
{
	g_atomic_int_inc (&_data19_->_ref_count_);
	return _data19_;
}

static void
block19_data_unref (void * _userdata_)
{
	Block19Data* _data19_;
	_data19_ = (Block19Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data19_->_ref_count_)) {
		WidgetsMarkdownEditor* self;
		self = _data19_->self;
		_g_object_unref0 (_data19_->adapter);
		_g_object_unref0 (self);
		g_slice_free (Block19Data, _data19_);
	}
}

static void
_widgets_markdown_editor_update_placeholder_visibility_g_object_notify (GObject* _sender,
                                                                        GParamSpec* pspec,
                                                                        gpointer self)
{
	widgets_markdown_editor_update_placeholder_visibility ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor___lambda94_ (Block19Data* _data19_)
{
	WidgetsMarkdownEditor* self;
	SpellingTextBufferAdapter* _tmp0_;
	ServicesSettings* _tmp1_;
	ServicesSettings* _tmp2_;
	GSettings* _tmp3_;
	self = _data19_->self;
	_tmp0_ = _data19_->adapter;
	_tmp1_ = services_settings_get_default ();
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_->settings;
	spelling_text_buffer_adapter_set_enabled (_tmp0_, g_settings_get_boolean (_tmp3_, "spell-checking-enabled"));
	_g_object_unref0 (_tmp2_);
}

static void
__widgets_markdown_editor___lambda94__g_settings_changed (GSettings* _sender,
                                                          const gchar* key,
                                                          gpointer self)
{
	_widgets_markdown_editor___lambda94_ (self);
}

static void
_widgets_markdown_editor___lambda95_ (WidgetsMarkdownEditor* self)
{
	widgets_markdown_editor_update_mode (self);
}

static void
__widgets_markdown_editor___lambda95__g_settings_changed (GSettings* _sender,
                                                          const gchar* key,
                                                          gpointer self)
{
	_widgets_markdown_editor___lambda95_ ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_selection_lost_g_object_notify (GObject* _sender,
                                                            GParamSpec* pspec,
                                                            gpointer self)
{
	widgets_markdown_editor_on_selection_lost ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_on_cursor_moved_g_object_notify (GObject* _sender,
                                                          GParamSpec* pspec,
                                                          gpointer self)
{
	widgets_markdown_editor_on_cursor_moved ((WidgetsMarkdownEditor*) self);
}

static gboolean
_widgets_markdown_editor_on_event_gtk_event_controller_legacy_event (GtkEventControllerLegacy* _sender,
                                                                     GdkEvent* event,
                                                                     gpointer self)
{
	gboolean result;
	result = widgets_markdown_editor_on_event ((WidgetsMarkdownEditor*) self, event);
	return result;
}

static void
_widgets_markdown_editor_on_text_clicked_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                                    gint n_press,
                                                                    gdouble x,
                                                                    gdouble y,
                                                                    gpointer self)
{
	widgets_markdown_editor_on_text_clicked ((WidgetsMarkdownEditor*) self, n_press, x, y);
}

static gboolean
_widgets_markdown_editor_on_key_pressed_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                              guint keyval,
                                                                              guint keycode,
                                                                              GdkModifierType state,
                                                                              gpointer self)
{
	gboolean result;
	result = widgets_markdown_editor_on_key_pressed ((WidgetsMarkdownEditor*) self, keyval, keycode, state);
	return result;
}

static void
_widgets_markdown_editor_handle_focus_in_gtk_event_controller_focus_enter (GtkEventControllerFocus* _sender,
                                                                           gpointer self)
{
	widgets_markdown_editor_handle_focus_in ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor_handle_focus_out_gtk_event_controller_focus_leave (GtkEventControllerFocus* _sender,
                                                                            gpointer self)
{
	widgets_markdown_editor_handle_focus_out ((WidgetsMarkdownEditor*) self);
}

static void
_widgets_markdown_editor___lambda96_ (WidgetsMarkdownEditor* self)
{
	widgets_markdown_editor_cleanup (self);
}

static void
__widgets_markdown_editor___lambda96__gtk_widget_destroy (GtkWidget* _sender,
                                                          gpointer self)
{
	_widgets_markdown_editor___lambda96_ ((WidgetsMarkdownEditor*) self);
}

static GObject *
widgets_markdown_editor_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsMarkdownEditor * self;
	Block19Data* _data19_;
	GtkSourceBuffer* _tmp0_;
	GtkSourceBuffer* _tmp1_;
	GtkTextView* _tmp2_ = NULL;
	GtkTextView* _tmp3_;
	GtkTextView* _tmp4_;
	GtkSourceBuffer* _tmp5_;
	SpellingChecker* _tmp6_;
	SpellingTextBufferAdapter* _tmp7_;
	GtkTextView* _tmp8_;
	SpellingTextBufferAdapter* _tmp9_;
	GMenuModel* _tmp10_;
	GtkTextView* _tmp11_;
	SpellingTextBufferAdapter* _tmp12_;
	SpellingTextBufferAdapter* _tmp13_;
	ServicesSettings* _tmp14_;
	ServicesSettings* _tmp15_;
	GSettings* _tmp16_;
	ServicesSettings* _tmp17_;
	ServicesSettings* _tmp18_;
	GSettings* _tmp19_;
	ServicesSettings* _tmp20_;
	ServicesSettings* _tmp21_;
	GSettings* _tmp22_;
	GtkSourceBuffer* _tmp23_;
	GtkSourceBuffer* _tmp24_;
	GtkSourceBuffer* _tmp25_;
	GtkEventControllerLegacy* click_controller = NULL;
	GtkEventControllerLegacy* _tmp26_;
	GtkEventControllerLegacy* _tmp27_;
	GtkTextView* _tmp28_;
	GtkEventControllerLegacy* _tmp29_;
	GtkEventController* _tmp30_;
	GtkGestureClick* _tmp31_;
	GtkGestureClick* _tmp32_;
	GtkTextView* _tmp33_;
	GtkGestureClick* _tmp34_;
	GtkEventController* _tmp35_;
	GtkEventControllerKey* key_controller = NULL;
	GtkEventControllerKey* _tmp36_;
	GtkEventControllerKey* _tmp37_;
	GtkTextView* _tmp38_;
	GtkEventControllerKey* _tmp39_;
	GtkEventController* _tmp40_;
	GtkEventControllerFocus* focus_controller = NULL;
	GtkEventControllerFocus* _tmp41_;
	GtkEventControllerFocus* _tmp42_;
	GtkEventControllerFocus* _tmp43_;
	GtkTextView* _tmp44_;
	GtkEventControllerFocus* _tmp45_;
	GtkEventController* _tmp46_;
	GtkTextView* _tmp47_;
	parent_class = G_OBJECT_CLASS (widgets_markdown_editor_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_MARKDOWN_EDITOR, WidgetsMarkdownEditor);
	_data19_ = g_slice_new0 (Block19Data);
	_data19_->_ref_count_ = 1;
	_data19_->self = g_object_ref (self);
	_tmp0_ = gtk_source_buffer_new (NULL);
	_g_object_unref0 (self->buffer);
	self->buffer = _tmp0_;
	_tmp1_ = self->buffer;
	_tmp2_ = (GtkTextView*) gtk_text_view_new_with_buffer ((GtkTextBuffer*) _tmp1_);
	gtk_text_view_set_wrap_mode (_tmp2_, GTK_WRAP_WORD);
	gtk_text_view_set_accepts_tab (_tmp2_, FALSE);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->text_view);
	self->text_view = _tmp2_;
	_tmp3_ = self->text_view;
	gtk_accessible_update_property ((GtkAccessible*) _tmp3_, GTK_ACCESSIBLE_PROPERTY_LABEL, _ ("Task description"), -1, -1);
	_tmp4_ = self->text_view;
	gtk_widget_remove_css_class ((GtkWidget*) _tmp4_, "view");
	widgets_markdown_editor_create_text_tags (self);
	g_signal_connect_object ((GObject*) self, "notify::placeholder-text", (GCallback) _widgets_markdown_editor_update_placeholder_visibility_g_object_notify, self, 0);
	widgets_markdown_editor_update_placeholder_visibility (self);
	widgets_markdown_editor_create_format_popover (self);
	widgets_markdown_editor_update_mode (self);
	_tmp5_ = self->buffer;
	_tmp6_ = spelling_checker_get_default ();
	_tmp7_ = spelling_text_buffer_adapter_new (_tmp5_, _tmp6_);
	_data19_->adapter = _tmp7_;
	_tmp8_ = self->text_view;
	_tmp9_ = _data19_->adapter;
	_tmp10_ = spelling_text_buffer_adapter_get_menu_model (_tmp9_);
	gtk_text_view_set_extra_menu (_tmp8_, _tmp10_);
	_tmp11_ = self->text_view;
	_tmp12_ = _data19_->adapter;
	gtk_widget_insert_action_group ((GtkWidget*) _tmp11_, "spelling", (GActionGroup*) _tmp12_);
	_tmp13_ = _data19_->adapter;
	_tmp14_ = services_settings_get_default ();
	_tmp15_ = _tmp14_;
	_tmp16_ = _tmp15_->settings;
	spelling_text_buffer_adapter_set_enabled (_tmp13_, g_settings_get_boolean (_tmp16_, "spell-checking-enabled"));
	_g_object_unref0 (_tmp15_);
	_tmp17_ = services_settings_get_default ();
	_tmp18_ = _tmp17_;
	_tmp19_ = _tmp18_->settings;
	g_signal_connect_data (_tmp19_, "changed::spell-checking-enabled", (GCallback) __widgets_markdown_editor___lambda94__g_settings_changed, block19_data_ref (_data19_), (GClosureNotify) block19_data_unref, 0);
	_g_object_unref0 (_tmp18_);
	_tmp20_ = services_settings_get_default ();
	_tmp21_ = _tmp20_;
	_tmp22_ = _tmp21_->settings;
	g_signal_connect_object (_tmp22_, "changed::enable-markdown-formatting", (GCallback) __widgets_markdown_editor___lambda95__g_settings_changed, self, 0);
	_g_object_unref0 (_tmp21_);
	_tmp23_ = self->buffer;
	g_signal_connect_object ((GtkTextBuffer*) _tmp23_, "changed", (GCallback) _widgets_markdown_editor_on_buffer_changed_gtk_text_buffer_changed, self, 0);
	_tmp24_ = self->buffer;
	g_signal_connect_object ((GObject*) _tmp24_, "notify::has-selection", (GCallback) _widgets_markdown_editor_on_selection_lost_g_object_notify, self, 0);
	_tmp25_ = self->buffer;
	g_signal_connect_object ((GObject*) _tmp25_, "notify::cursor-position", (GCallback) _widgets_markdown_editor_on_cursor_moved_g_object_notify, self, 0);
	_tmp26_ = (GtkEventControllerLegacy*) gtk_event_controller_legacy_new ();
	click_controller = _tmp26_;
	_tmp27_ = click_controller;
	g_signal_connect_object (_tmp27_, "event", (GCallback) _widgets_markdown_editor_on_event_gtk_event_controller_legacy_event, self, 0);
	_tmp28_ = self->text_view;
	_tmp29_ = click_controller;
	_tmp30_ = _g_object_ref0 ((GtkEventController*) _tmp29_);
	gtk_widget_add_controller ((GtkWidget*) _tmp28_, _tmp30_);
	_tmp31_ = (GtkGestureClick*) gtk_gesture_click_new ();
	_g_object_unref0 (self->priv->gesture_click);
	self->priv->gesture_click = _tmp31_;
	_tmp32_ = self->priv->gesture_click;
	g_signal_connect_object (_tmp32_, "pressed", (GCallback) _widgets_markdown_editor_on_text_clicked_gtk_gesture_click_pressed, self, 0);
	_tmp33_ = self->text_view;
	_tmp34_ = self->priv->gesture_click;
	_tmp35_ = _g_object_ref0 ((GtkEventController*) _tmp34_);
	gtk_widget_add_controller ((GtkWidget*) _tmp33_, _tmp35_);
	_tmp36_ = (GtkEventControllerKey*) gtk_event_controller_key_new ();
	key_controller = _tmp36_;
	_tmp37_ = key_controller;
	g_signal_connect_object (_tmp37_, "key-pressed", (GCallback) _widgets_markdown_editor_on_key_pressed_gtk_event_controller_key_key_pressed, self, 0);
	_tmp38_ = self->text_view;
	_tmp39_ = key_controller;
	_tmp40_ = _g_object_ref0 ((GtkEventController*) _tmp39_);
	gtk_widget_add_controller ((GtkWidget*) _tmp38_, _tmp40_);
	_tmp41_ = (GtkEventControllerFocus*) gtk_event_controller_focus_new ();
	focus_controller = _tmp41_;
	_tmp42_ = focus_controller;
	g_signal_connect_object (_tmp42_, "enter", (GCallback) _widgets_markdown_editor_handle_focus_in_gtk_event_controller_focus_enter, self, 0);
	_tmp43_ = focus_controller;
	g_signal_connect_object (_tmp43_, "leave", (GCallback) _widgets_markdown_editor_handle_focus_out_gtk_event_controller_focus_leave, self, 0);
	_tmp44_ = self->text_view;
	_tmp45_ = focus_controller;
	_tmp46_ = _g_object_ref0 ((GtkEventController*) _tmp45_);
	gtk_widget_add_controller ((GtkWidget*) _tmp44_, _tmp46_);
	_tmp47_ = self->text_view;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp47_);
	g_signal_connect_object ((GtkWidget*) self, "destroy", (GCallback) __widgets_markdown_editor___lambda96__gtk_widget_destroy, self, 0);
	_g_object_unref0 (focus_controller);
	_g_object_unref0 (key_controller);
	_g_object_unref0 (click_controller);
	block19_data_unref (_data19_);
	_data19_ = NULL;
	return obj;
}

static void
widgets_markdown_editor_class_init (WidgetsMarkdownEditorClass * klass,
                                    gpointer klass_data)
{
	widgets_markdown_editor_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsMarkdownEditor_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_widgets_markdown_editor_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_markdown_editor_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_markdown_editor_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_markdown_editor_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_MARKDOWN_EDITOR_PLACEHOLDER_TEXT_PROPERTY, widgets_markdown_editor_properties[WIDGETS_MARKDOWN_EDITOR_PLACEHOLDER_TEXT_PROPERTY] = g_param_spec_string ("placeholder-text", "placeholder-text", "placeholder-text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_MARKDOWN_EDITOR_PROJECT_PROPERTY, widgets_markdown_editor_properties[WIDGETS_MARKDOWN_EDITOR_PROJECT_PROPERTY] = g_param_spec_object ("project", "project", "project", OBJECTS_TYPE_PROJECT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_MARKDOWN_EDITOR_TEXT_MODE_PROPERTY, widgets_markdown_editor_properties[WIDGETS_MARKDOWN_EDITOR_TEXT_MODE_PROPERTY] = g_param_spec_boolean ("text-mode", "text-mode", "text-mode", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_MARKDOWN_EDITOR_IS_EDITABLE_PROPERTY, widgets_markdown_editor_properties[WIDGETS_MARKDOWN_EDITOR_IS_EDITABLE_PROPERTY] = g_param_spec_boolean ("is-editable", "is-editable", "is-editable", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_TEXT_CHANGED_SIGNAL] = g_signal_new ("text-changed", WIDGETS_TYPE_MARKDOWN_EDITOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
	widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_ESCAPE_PRESSED_SIGNAL] = g_signal_new ("escape-pressed", WIDGETS_TYPE_MARKDOWN_EDITOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_RETURN_PRESSED_SIGNAL] = g_signal_new ("return-pressed", WIDGETS_TYPE_MARKDOWN_EDITOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_FOCUS_IN_SIGNAL] = g_signal_new ("focus-in", WIDGETS_TYPE_MARKDOWN_EDITOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	widgets_markdown_editor_signals[WIDGETS_MARKDOWN_EDITOR_FOCUS_OUT_SIGNAL] = g_signal_new ("focus-out", WIDGETS_TYPE_MARKDOWN_EDITOR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
widgets_markdown_editor_instance_init (WidgetsMarkdownEditor * self,
                                       gpointer klass)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	self->priv = widgets_markdown_editor_get_instance_private (self);
	_tmp0_ = g_strdup ("");
	self->priv->selected_link_text = _tmp0_;
	self->priv->mouse_pressed = FALSE;
	self->priv->showing_placeholder = FALSE;
	self->priv->editing_existing_link = FALSE;
	self->priv->updating_programmatically = FALSE;
	_tmp1_ = g_strdup ("");
	self->priv->_placeholder_text = _tmp1_;
	self->priv->_project = NULL;
}

static void
widgets_markdown_editor_finalize (GObject * obj)
{
	WidgetsMarkdownEditor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_MARKDOWN_EDITOR, WidgetsMarkdownEditor);
	g_debug ("MarkdownEditor.vala:89: Destroying - Layouts.Widgets.MarkdownEditor\n");
	_g_object_unref0 (self->text_view);
	_g_object_unref0 (self->buffer);
	_g_object_unref0 (self->priv->format_popover);
	_g_object_unref0 (self->priv->bold_button);
	_g_object_unref0 (self->priv->italic_button);
	_g_object_unref0 (self->priv->strikethrough_button);
	_g_object_unref0 (self->priv->h1_button);
	_g_object_unref0 (self->priv->h2_button);
	_g_object_unref0 (self->priv->code_button);
	_g_object_unref0 (self->priv->link_button);
	_g_object_unref0 (self->priv->unordered_list_button);
	_g_object_unref0 (self->priv->ordered_list_button);
	_g_object_unref0 (self->priv->link_popover);
	_g_object_unref0 (self->priv->link_entry);
	_g_object_unref0 (self->priv->link_apply_button);
	_g_object_unref0 (self->priv->link_remove_button);
	_g_object_unref0 (self->priv->bold_tag);
	_g_object_unref0 (self->priv->italic_tag);
	_g_object_unref0 (self->priv->strikethrough_tag);
	_g_object_unref0 (self->priv->h1_tag);
	_g_object_unref0 (self->priv->h2_tag);
	_g_object_unref0 (self->priv->code_tag);
	_g_object_unref0 (self->priv->link_tag);
	_g_object_unref0 (self->priv->invisible_tag);
	_g_object_unref0 (self->priv->placeholder_tag);
	_g_object_unref0 (self->priv->list_tag);
	_g_object_unref0 (self->priv->ordered_list_tag);
	_g_free0 (self->priv->selected_link_text);
	_g_object_unref0 (self->priv->gesture_click);
	_g_free0 (self->priv->_placeholder_text);
	_g_object_unref0 (self->priv->_project);
	G_OBJECT_CLASS (widgets_markdown_editor_parent_class)->finalize (obj);
}

static GType
widgets_markdown_editor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsMarkdownEditorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_markdown_editor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsMarkdownEditor), 0, (GInstanceInitFunc) widgets_markdown_editor_instance_init, NULL };
	GType widgets_markdown_editor_type_id;
	widgets_markdown_editor_type_id = g_type_register_static (adw_bin_get_type (), "WidgetsMarkdownEditor", &g_define_type_info, 0);
	WidgetsMarkdownEditor_private_offset = g_type_add_instance_private (widgets_markdown_editor_type_id, sizeof (WidgetsMarkdownEditorPrivate));
	return widgets_markdown_editor_type_id;
}

GType
widgets_markdown_editor_get_type (void)
{
	static volatile gsize widgets_markdown_editor_type_id__once = 0;
	if (g_once_init_enter (&widgets_markdown_editor_type_id__once)) {
		GType widgets_markdown_editor_type_id;
		widgets_markdown_editor_type_id = widgets_markdown_editor_get_type_once ();
		g_once_init_leave (&widgets_markdown_editor_type_id__once, widgets_markdown_editor_type_id);
	}
	return widgets_markdown_editor_type_id__once;
}

static void
_vala_widgets_markdown_editor_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	WidgetsMarkdownEditor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_MARKDOWN_EDITOR, WidgetsMarkdownEditor);
	switch (property_id) {
		case WIDGETS_MARKDOWN_EDITOR_PLACEHOLDER_TEXT_PROPERTY:
		g_value_set_string (value, widgets_markdown_editor_get_placeholder_text (self));
		break;
		case WIDGETS_MARKDOWN_EDITOR_PROJECT_PROPERTY:
		g_value_set_object (value, widgets_markdown_editor_get_project (self));
		break;
		case WIDGETS_MARKDOWN_EDITOR_TEXT_MODE_PROPERTY:
		g_value_set_boolean (value, widgets_markdown_editor_get_text_mode (self));
		break;
		case WIDGETS_MARKDOWN_EDITOR_IS_EDITABLE_PROPERTY:
		g_value_set_boolean (value, widgets_markdown_editor_get_is_editable (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_widgets_markdown_editor_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec)
{
	WidgetsMarkdownEditor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_MARKDOWN_EDITOR, WidgetsMarkdownEditor);
	switch (property_id) {
		case WIDGETS_MARKDOWN_EDITOR_PLACEHOLDER_TEXT_PROPERTY:
		widgets_markdown_editor_set_placeholder_text (self, g_value_get_string (value));
		break;
		case WIDGETS_MARKDOWN_EDITOR_PROJECT_PROPERTY:
		widgets_markdown_editor_set_project (self, g_value_get_object (value));
		break;
		case WIDGETS_MARKDOWN_EDITOR_IS_EDITABLE_PROPERTY:
		widgets_markdown_editor_set_is_editable (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

