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

/*
 * Copyright © 2023 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 <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gee.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  {
	MARKDOWN_PROCESSOR_0_PROPERTY,
	MARKDOWN_PROCESSOR_NUM_PROPERTIES
};
static GParamSpec* markdown_processor_properties[MARKDOWN_PROCESSOR_NUM_PROPERTIES];
typedef enum  {
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_URL_MARKDOWN = 1,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_EMAIL = 2,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_URL = 3,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_CODE = 4,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_BOLD_UNDERLINE = 5,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_BOLD_UNDERLINE = 6,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_UNDERLINE = 7,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_BOLD = 8,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_BOLD = 9,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC = 10,
	MARKDOWN_PROCESSOR_MARKUP_PRIORITY_UNDERLINE = 11
} MarkdownProcessorMarkupPriority;

#define MARKDOWN_PROCESSOR_TYPE_MARKUP_PRIORITY (markdown_processor_markup_priority_get_type ())
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define MARKDOWN_PROCESSOR_TYPE_MARKUP_MATCH (markdown_processor_markup_match_get_type ())
typedef struct _MarkdownProcessorMarkupMatch MarkdownProcessorMarkupMatch;
#define _g_match_info_unref0(var) ((var == NULL) ? NULL : (var = (g_match_info_unref (var), NULL)))

#define MARKDOWN_PROCESSOR_TYPE_FORMAT_PATTERN (markdown_processor_format_pattern_get_type ())
typedef struct _MarkdownProcessorFormatPattern MarkdownProcessorFormatPattern;
#define _markdown_processor_format_pattern_free0(var) ((var == NULL) ? NULL : (var = (markdown_processor_format_pattern_free (var), NULL)))
#define _markdown_processor_markup_match_free0(var) ((var == NULL) ? NULL : (var = (markdown_processor_markup_match_free (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

struct _MarkdownProcessorPrivate {
	GRegex* mailto_regex;
	GRegex* url_regex;
	GRegex* url_markdown_regex;
	GRegex* code_regex;
	GRegex* italic_bold_underline_regex;
	GRegex* bold_underline_regex;
	GRegex* italic_underline_regex;
	GRegex* italic_bold_regex;
	GRegex* bold_regex;
	GRegex* italic_regex;
	GRegex* underline_regex;
};

struct _MarkdownProcessorMarkupMatch {
	gint start_pos;
	gint end_pos;
	gchar* original;
	gchar* replacement;
	gint priority;
};

struct _MarkdownProcessorFormatPattern {
	GRegex* regex;
	gchar* format_template;
	gint priority;
};

static gint MarkdownProcessor_private_offset;
static gpointer markdown_processor_parent_class = NULL;
static MarkdownProcessor* markdown_processor__instance;
static MarkdownProcessor* markdown_processor__instance = NULL;

static GType markdown_processor_markup_priority_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static void markdown_processor_compile_regexes (MarkdownProcessor* self);
static GType markdown_processor_markup_match_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static MarkdownProcessorMarkupMatch* markdown_processor_markup_match_dup (const MarkdownProcessorMarkupMatch* self);
static void markdown_processor_markup_match_free (MarkdownProcessorMarkupMatch* self);
static void markdown_processor_markup_match_copy (const MarkdownProcessorMarkupMatch* self,
                                           MarkdownProcessorMarkupMatch* dest);
static void markdown_processor_markup_match_destroy (MarkdownProcessorMarkupMatch* self);
static void markdown_processor_collect_url_markdown_matches (MarkdownProcessor* self,
                                                      const gchar* text,
                                                      GeeArrayList* matches);
static void markdown_processor_collect_email_matches (MarkdownProcessor* self,
                                               const gchar* text,
                                               GeeArrayList* matches);
static void markdown_processor_collect_url_matches (MarkdownProcessor* self,
                                             const gchar* text,
                                             GeeArrayList* matches);
static void markdown_processor_collect_code_matches (MarkdownProcessor* self,
                                              const gchar* text,
                                              GeeArrayList* matches);
static void markdown_processor_collect_formatting_matches (MarkdownProcessor* self,
                                                    const gchar* text,
                                                    GeeArrayList* matches);
static GeeArrayList* markdown_processor_filter_and_sort_matches (MarkdownProcessor* self,
                                                          GeeArrayList* matches);
static gchar* markdown_processor_apply_matches (MarkdownProcessor* self,
                                         const gchar* text,
                                         GeeArrayList* matches);
static void markdown_processor_markup_match_init (MarkdownProcessorMarkupMatch *self,
                                           gint start,
                                           gint end,
                                           const gchar* orig,
                                           const gchar* repl,
                                           gint prio);
static gboolean markdown_processor_is_position_covered_by_priority (MarkdownProcessor* self,
                                                             GeeArrayList* matches,
                                                             gint start_pos,
                                                             gint end_pos,
                                                             gint min_priority);
static GType markdown_processor_format_pattern_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static MarkdownProcessorFormatPattern* markdown_processor_format_pattern_dup (const MarkdownProcessorFormatPattern* self);
static void markdown_processor_format_pattern_free (MarkdownProcessorFormatPattern* self);
static void markdown_processor_format_pattern_copy (const MarkdownProcessorFormatPattern* self,
                                             MarkdownProcessorFormatPattern* dest);
static void markdown_processor_format_pattern_destroy (MarkdownProcessorFormatPattern* self);
static void markdown_processor_format_pattern_init (MarkdownProcessorFormatPattern *self,
                                             GRegex* r,
                                             const gchar* template,
                                             gint prio);
static void markdown_processor_collect_pattern_matches (MarkdownProcessor* self,
                                                 const gchar* text,
                                                 GeeArrayList* matches,
                                                 MarkdownProcessorFormatPattern* pattern);
static gboolean markdown_processor_ranges_overlap (MarkdownProcessor* self,
                                            gint start1,
                                            gint end1,
                                            gint start2,
                                            gint end2);
static gint __lambda349_ (MarkdownProcessor* self,
                   MarkdownProcessorMarkupMatch* a,
                   MarkdownProcessorMarkupMatch* b);
static gint ___lambda349__gcompare_data_func (gconstpointer a,
                                       gconstpointer b,
                                       gpointer self);
static gint __lambda350_ (MarkdownProcessor* self,
                   MarkdownProcessorMarkupMatch* a,
                   MarkdownProcessorMarkupMatch* b);
static gint ___lambda350__gcompare_data_func (gconstpointer a,
                                       gconstpointer b,
                                       gpointer self);
static void markdown_processor_finalize (GObject * obj);
static GType markdown_processor_get_type_once (void);

static inline gpointer
markdown_processor_get_instance_private (MarkdownProcessor* self)
{
	return G_STRUCT_MEMBER_P (self, MarkdownProcessor_private_offset);
}

static GType
markdown_processor_markup_priority_get_type_once (void)
{
	static const GEnumValue values[] = {{MARKDOWN_PROCESSOR_MARKUP_PRIORITY_URL_MARKDOWN, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_URL_MARKDOWN", "url-markdown"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_EMAIL, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_EMAIL", "email"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_URL, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_URL", "url"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_CODE, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_CODE", "code"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_BOLD_UNDERLINE, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_BOLD_UNDERLINE", "italic-bold-underline"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_BOLD_UNDERLINE, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_BOLD_UNDERLINE", "bold-underline"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_UNDERLINE, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_UNDERLINE", "italic-underline"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_BOLD, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_BOLD", "italic-bold"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_BOLD, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_BOLD", "bold"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC", "italic"}, {MARKDOWN_PROCESSOR_MARKUP_PRIORITY_UNDERLINE, "MARKDOWN_PROCESSOR_MARKUP_PRIORITY_UNDERLINE", "underline"}, {0, NULL, NULL}};
	GType markdown_processor_markup_priority_type_id;
	markdown_processor_markup_priority_type_id = g_enum_register_static ("MarkdownProcessorMarkupPriority", values);
	return markdown_processor_markup_priority_type_id;
}

static GType
markdown_processor_markup_priority_get_type (void)
{
	static volatile gsize markdown_processor_markup_priority_type_id__once = 0;
	if (g_once_init_enter (&markdown_processor_markup_priority_type_id__once)) {
		GType markdown_processor_markup_priority_type_id;
		markdown_processor_markup_priority_type_id = markdown_processor_markup_priority_get_type_once ();
		g_once_init_leave (&markdown_processor_markup_priority_type_id__once, markdown_processor_markup_priority_type_id);
	}
	return markdown_processor_markup_priority_type_id__once;
}

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

MarkdownProcessor*
markdown_processor_get_default (void)
{
	MarkdownProcessor* _tmp0_;
	MarkdownProcessor* _tmp2_;
	MarkdownProcessor* _tmp3_;
	MarkdownProcessor* result;
	_tmp0_ = markdown_processor__instance;
	if (_tmp0_ == NULL) {
		MarkdownProcessor* _tmp1_;
		_tmp1_ = markdown_processor_new ();
		_g_object_unref0 (markdown_processor__instance);
		markdown_processor__instance = _tmp1_;
	}
	_tmp2_ = markdown_processor__instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

MarkdownProcessor*
markdown_processor_construct (GType object_type)
{
	MarkdownProcessor * self = NULL;
	self = (MarkdownProcessor*) g_object_new (object_type, NULL);
	markdown_processor_compile_regexes (self);
	return self;
}

MarkdownProcessor*
markdown_processor_new (void)
{
	return markdown_processor_construct (TYPE_MARKDOWN_PROCESSOR);
}

static void
markdown_processor_compile_regexes (MarkdownProcessor* self)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	{
		GRegex* _tmp0_ = NULL;
		GRegex* _tmp1_;
		GRegex* _tmp2_;
		GRegex* _tmp3_ = NULL;
		GRegex* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_ = NULL;
		GRegex* _tmp7_;
		GRegex* _tmp8_;
		GRegex* _tmp9_ = NULL;
		GRegex* _tmp10_;
		GRegex* _tmp11_;
		GRegex* _tmp12_ = NULL;
		GRegex* _tmp13_;
		GRegex* _tmp14_;
		GRegex* _tmp15_ = NULL;
		GRegex* _tmp16_;
		GRegex* _tmp17_;
		GRegex* _tmp18_ = NULL;
		GRegex* _tmp19_;
		GRegex* _tmp20_;
		GRegex* _tmp21_ = NULL;
		GRegex* _tmp22_;
		GRegex* _tmp23_;
		GRegex* _tmp24_ = NULL;
		GRegex* _tmp25_;
		GRegex* _tmp26_;
		GRegex* _tmp27_ = NULL;
		GRegex* _tmp28_;
		GRegex* _tmp29_;
		GRegex* _tmp30_ = NULL;
		GRegex* _tmp31_;
		GRegex* _tmp32_;
		_tmp1_ = g_regex_new ("(?P<mailto>[a-zA-Z0-9][a-zA-Z0-9._%-]*[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-" \
"9.-]*\\.[a-zA-Z]{2,})", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp0_ = _tmp1_;
		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;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_g_regex_unref0 (self->priv->mailto_regex);
		self->priv->mailto_regex = _tmp2_;
		_tmp4_ = g_regex_new ("(?P<url>https?://[a-zA-Z0-9][a-zA-Z0-9.-]*\\.[a-zA-Z]{2,}(?:/[^\\s]*)?" \
")", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp3_ = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp5_ = _tmp3_;
		_tmp3_ = NULL;
		_g_regex_unref0 (self->priv->url_regex);
		self->priv->url_regex = _tmp5_;
		_tmp7_ = g_regex_new ("\\[([^\\]]+)\\]\\(([^\\)\\s]+)\\)", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp6_ = _tmp7_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp3_);
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp8_ = _tmp6_;
		_tmp6_ = NULL;
		_g_regex_unref0 (self->priv->url_markdown_regex);
		self->priv->url_markdown_regex = _tmp8_;
		_tmp10_ = g_regex_new ("`([^`\\n]+?)`", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp9_ = _tmp10_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp6_);
			_g_regex_unref0 (_tmp3_);
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp11_ = _tmp9_;
		_tmp9_ = NULL;
		_g_regex_unref0 (self->priv->code_regex);
		self->priv->code_regex = _tmp11_;
		_tmp13_ = g_regex_new ("\\*\\*\\*_([^*_\\n]+?)_\\*\\*\\*", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp12_ = _tmp13_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp9_);
			_g_regex_unref0 (_tmp6_);
			_g_regex_unref0 (_tmp3_);
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp14_ = _tmp12_;
		_tmp12_ = NULL;
		_g_regex_unref0 (self->priv->italic_bold_underline_regex);
		self->priv->italic_bold_underline_regex = _tmp14_;
		_tmp16_ = g_regex_new ("\\*\\*_([^*_\\n]+?)_\\*\\*", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp15_ = _tmp16_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp12_);
			_g_regex_unref0 (_tmp9_);
			_g_regex_unref0 (_tmp6_);
			_g_regex_unref0 (_tmp3_);
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp17_ = _tmp15_;
		_tmp15_ = NULL;
		_g_regex_unref0 (self->priv->bold_underline_regex);
		self->priv->bold_underline_regex = _tmp17_;
		_tmp19_ = g_regex_new ("\\*_([^*_\\n]+?)_\\*", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp18_ = _tmp19_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp15_);
			_g_regex_unref0 (_tmp12_);
			_g_regex_unref0 (_tmp9_);
			_g_regex_unref0 (_tmp6_);
			_g_regex_unref0 (_tmp3_);
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp20_ = _tmp18_;
		_tmp18_ = NULL;
		_g_regex_unref0 (self->priv->italic_underline_regex);
		self->priv->italic_underline_regex = _tmp20_;
		_tmp22_ = g_regex_new ("(?<!\\*)\\*\\*\\*([^*\\n]+?)\\*\\*\\*(?!\\*)", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp21_ = _tmp22_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp18_);
			_g_regex_unref0 (_tmp15_);
			_g_regex_unref0 (_tmp12_);
			_g_regex_unref0 (_tmp9_);
			_g_regex_unref0 (_tmp6_);
			_g_regex_unref0 (_tmp3_);
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp23_ = _tmp21_;
		_tmp21_ = NULL;
		_g_regex_unref0 (self->priv->italic_bold_regex);
		self->priv->italic_bold_regex = _tmp23_;
		_tmp25_ = g_regex_new ("(?<!\\*)\\*\\*([^*\\n]+?)\\*\\*(?!\\*)", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp24_ = _tmp25_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp21_);
			_g_regex_unref0 (_tmp18_);
			_g_regex_unref0 (_tmp15_);
			_g_regex_unref0 (_tmp12_);
			_g_regex_unref0 (_tmp9_);
			_g_regex_unref0 (_tmp6_);
			_g_regex_unref0 (_tmp3_);
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp26_ = _tmp24_;
		_tmp24_ = NULL;
		_g_regex_unref0 (self->priv->bold_regex);
		self->priv->bold_regex = _tmp26_;
		_tmp28_ = g_regex_new ("(?<!\\*)\\*([^*\\n]+?)\\*(?!\\*)", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp27_ = _tmp28_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp24_);
			_g_regex_unref0 (_tmp21_);
			_g_regex_unref0 (_tmp18_);
			_g_regex_unref0 (_tmp15_);
			_g_regex_unref0 (_tmp12_);
			_g_regex_unref0 (_tmp9_);
			_g_regex_unref0 (_tmp6_);
			_g_regex_unref0 (_tmp3_);
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp29_ = _tmp27_;
		_tmp27_ = NULL;
		_g_regex_unref0 (self->priv->italic_regex);
		self->priv->italic_regex = _tmp29_;
		_tmp31_ = g_regex_new ("_([^_\\n]+?)_", G_REGEX_OPTIMIZE, 0, &_inner_error0_);
		_tmp30_ = _tmp31_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (_tmp27_);
			_g_regex_unref0 (_tmp24_);
			_g_regex_unref0 (_tmp21_);
			_g_regex_unref0 (_tmp18_);
			_g_regex_unref0 (_tmp15_);
			_g_regex_unref0 (_tmp12_);
			_g_regex_unref0 (_tmp9_);
			_g_regex_unref0 (_tmp6_);
			_g_regex_unref0 (_tmp3_);
			_g_regex_unref0 (_tmp0_);
			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;
		}
		_tmp32_ = _tmp30_;
		_tmp30_ = NULL;
		_g_regex_unref0 (self->priv->underline_regex);
		self->priv->underline_regex = _tmp32_;
		_g_regex_unref0 (_tmp30_);
		_g_regex_unref0 (_tmp27_);
		_g_regex_unref0 (_tmp24_);
		_g_regex_unref0 (_tmp21_);
		_g_regex_unref0 (_tmp18_);
		_g_regex_unref0 (_tmp15_);
		_g_regex_unref0 (_tmp12_);
		_g_regex_unref0 (_tmp9_);
		_g_regex_unref0 (_tmp6_);
		_g_regex_unref0 (_tmp3_);
		_g_regex_unref0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError* e = NULL;
		GError* _tmp33_;
		const gchar* _tmp34_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp33_ = e;
		_tmp34_ = _tmp33_->message;
		g_warning ("MarkdownProcessor.vala:135: Error compiling regex: %s", _tmp34_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
}

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;
}

gchar*
markdown_processor_markup_string (MarkdownProcessor* self,
                                  const gchar* text)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gchar* escaped_text = NULL;
	gint _tmp4_;
	gint _tmp5_;
	gchar* _tmp6_;
	GeeArrayList* matches = NULL;
	GeeArrayList* _tmp7_;
	const gchar* _tmp8_;
	GeeArrayList* _tmp9_;
	const gchar* _tmp10_;
	GeeArrayList* _tmp11_;
	const gchar* _tmp12_;
	GeeArrayList* _tmp13_;
	const gchar* _tmp14_;
	GeeArrayList* _tmp15_;
	const gchar* _tmp16_;
	GeeArrayList* _tmp17_;
	GeeArrayList* filtered_matches = NULL;
	GeeArrayList* _tmp18_;
	GeeArrayList* _tmp19_;
	const gchar* _tmp20_;
	GeeArrayList* _tmp21_;
	gchar* _tmp22_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (text != NULL, NULL);
	_tmp0_ = string_strip (text);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strcmp0 (_tmp1_, "") == 0;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		gchar* _tmp3_;
		_tmp3_ = g_strdup (text);
		result = _tmp3_;
		return result;
	}
	_tmp4_ = strlen (text);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_markup_escape_text (text, (gssize) _tmp5_);
	escaped_text = _tmp6_;
	_tmp7_ = gee_array_list_new (MARKDOWN_PROCESSOR_TYPE_MARKUP_MATCH, (GBoxedCopyFunc) markdown_processor_markup_match_dup, (GDestroyNotify) markdown_processor_markup_match_free, NULL, NULL, NULL);
	matches = _tmp7_;
	_tmp8_ = escaped_text;
	_tmp9_ = matches;
	markdown_processor_collect_url_markdown_matches (self, _tmp8_, _tmp9_);
	_tmp10_ = escaped_text;
	_tmp11_ = matches;
	markdown_processor_collect_email_matches (self, _tmp10_, _tmp11_);
	_tmp12_ = escaped_text;
	_tmp13_ = matches;
	markdown_processor_collect_url_matches (self, _tmp12_, _tmp13_);
	_tmp14_ = escaped_text;
	_tmp15_ = matches;
	markdown_processor_collect_code_matches (self, _tmp14_, _tmp15_);
	_tmp16_ = escaped_text;
	_tmp17_ = matches;
	markdown_processor_collect_formatting_matches (self, _tmp16_, _tmp17_);
	_tmp18_ = matches;
	_tmp19_ = markdown_processor_filter_and_sort_matches (self, _tmp18_);
	filtered_matches = _tmp19_;
	_tmp20_ = escaped_text;
	_tmp21_ = filtered_matches;
	_tmp22_ = markdown_processor_apply_matches (self, _tmp20_, _tmp21_);
	result = _tmp22_;
	_g_object_unref0 (filtered_matches);
	_g_object_unref0 (matches);
	_g_free0 (escaped_text);
	return result;
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static void
markdown_processor_collect_url_markdown_matches (MarkdownProcessor* self,
                                                 const gchar* text,
                                                 GeeArrayList* matches)
{
	GRegex* _tmp0_;
	GMatchInfo* match_info = NULL;
	GRegex* _tmp1_;
	GMatchInfo* _tmp2_ = NULL;
	gboolean _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (matches != NULL);
	_tmp0_ = self->priv->url_markdown_regex;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->url_markdown_regex;
	_tmp3_ = g_regex_match (_tmp1_, text, 0, &_tmp2_);
	_g_match_info_unref0 (match_info);
	match_info = _tmp2_;
	if (_tmp3_) {
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				gint start_pos = 0;
				gint end_pos = 0;
				GMatchInfo* _tmp7_;
				gint _tmp8_ = 0;
				gint _tmp9_ = 0;
				gboolean _tmp10_;
				if (!_tmp4_) {
					gboolean _tmp5_ = FALSE;
					GMatchInfo* _tmp6_;
					_tmp6_ = match_info;
					_tmp5_ = g_match_info_next (_tmp6_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_match_info_unref0 (match_info);
						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;
					}
					if (!_tmp5_) {
						break;
					}
				}
				_tmp4_ = FALSE;
				_tmp7_ = match_info;
				_tmp10_ = g_match_info_fetch_pos (_tmp7_, 0, &_tmp8_, &_tmp9_);
				start_pos = _tmp8_;
				end_pos = _tmp9_;
				if (_tmp10_) {
					gchar* full_match = NULL;
					GMatchInfo* _tmp11_;
					gchar* _tmp12_;
					gchar* link_text = NULL;
					GMatchInfo* _tmp13_;
					gchar* _tmp14_;
					gchar* link_url = NULL;
					GMatchInfo* _tmp15_;
					gchar* _tmp16_;
					gchar* replacement = NULL;
					const gchar* _tmp17_;
					const gchar* _tmp18_;
					const gchar* _tmp19_;
					const gchar* _tmp20_;
					gchar* _tmp21_;
					const gchar* _tmp22_;
					const gchar* _tmp23_;
					MarkdownProcessorMarkupMatch _tmp24_ = {0};
					MarkdownProcessorMarkupMatch _tmp25_;
					MarkdownProcessorMarkupMatch _tmp26_;
					_tmp11_ = match_info;
					_tmp12_ = g_match_info_fetch (_tmp11_, 0);
					full_match = _tmp12_;
					_tmp13_ = match_info;
					_tmp14_ = g_match_info_fetch (_tmp13_, 1);
					link_text = _tmp14_;
					_tmp15_ = match_info;
					_tmp16_ = g_match_info_fetch (_tmp15_, 2);
					link_url = _tmp16_;
					_tmp17_ = link_url;
					_tmp18_ = string_to_string (_tmp17_);
					_tmp19_ = link_text;
					_tmp20_ = string_to_string (_tmp19_);
					_tmp21_ = g_strconcat ("<a href=\"", _tmp18_, "\">", _tmp20_, "</a>", NULL);
					replacement = _tmp21_;
					_tmp22_ = full_match;
					_tmp23_ = replacement;
					markdown_processor_markup_match_init (&_tmp24_, start_pos, end_pos, _tmp22_, _tmp23_, (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_URL_MARKDOWN);
					_tmp25_ = _tmp24_;
					_tmp26_ = _tmp25_;
					gee_abstract_collection_add ((GeeAbstractCollection*) matches, &_tmp26_);
					markdown_processor_markup_match_destroy (&_tmp25_);
					_g_free0 (replacement);
					_g_free0 (link_url);
					_g_free0 (link_text);
					_g_free0 (full_match);
				}
			}
		}
	}
	_g_match_info_unref0 (match_info);
}

static void
markdown_processor_collect_email_matches (MarkdownProcessor* self,
                                          const gchar* text,
                                          GeeArrayList* matches)
{
	GRegex* _tmp0_;
	GMatchInfo* match_info = NULL;
	GRegex* _tmp1_;
	GMatchInfo* _tmp2_ = NULL;
	gboolean _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (matches != NULL);
	_tmp0_ = self->priv->mailto_regex;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->mailto_regex;
	_tmp3_ = g_regex_match (_tmp1_, text, 0, &_tmp2_);
	_g_match_info_unref0 (match_info);
	match_info = _tmp2_;
	if (_tmp3_) {
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				gint start_pos = 0;
				gint end_pos = 0;
				GMatchInfo* _tmp7_;
				gint _tmp8_ = 0;
				gint _tmp9_ = 0;
				gboolean _tmp10_;
				if (!_tmp4_) {
					gboolean _tmp5_ = FALSE;
					GMatchInfo* _tmp6_;
					_tmp6_ = match_info;
					_tmp5_ = g_match_info_next (_tmp6_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_match_info_unref0 (match_info);
						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;
					}
					if (!_tmp5_) {
						break;
					}
				}
				_tmp4_ = FALSE;
				_tmp7_ = match_info;
				_tmp10_ = g_match_info_fetch_pos (_tmp7_, 0, &_tmp8_, &_tmp9_);
				start_pos = _tmp8_;
				end_pos = _tmp9_;
				if (_tmp10_) {
					gchar* email = NULL;
					GMatchInfo* _tmp11_;
					gchar* _tmp12_;
					gchar* replacement = NULL;
					const gchar* _tmp13_;
					const gchar* _tmp14_;
					const gchar* _tmp15_;
					const gchar* _tmp16_;
					gchar* _tmp17_;
					const gchar* _tmp18_;
					const gchar* _tmp19_;
					MarkdownProcessorMarkupMatch _tmp20_ = {0};
					MarkdownProcessorMarkupMatch _tmp21_;
					MarkdownProcessorMarkupMatch _tmp22_;
					_tmp11_ = match_info;
					_tmp12_ = g_match_info_fetch_named (_tmp11_, "mailto");
					email = _tmp12_;
					_tmp13_ = email;
					_tmp14_ = string_to_string (_tmp13_);
					_tmp15_ = email;
					_tmp16_ = string_to_string (_tmp15_);
					_tmp17_ = g_strconcat ("<a href=\"mailto:", _tmp14_, "\">", _tmp16_, "</a>", NULL);
					replacement = _tmp17_;
					_tmp18_ = email;
					_tmp19_ = replacement;
					markdown_processor_markup_match_init (&_tmp20_, start_pos, end_pos, _tmp18_, _tmp19_, (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_EMAIL);
					_tmp21_ = _tmp20_;
					_tmp22_ = _tmp21_;
					gee_abstract_collection_add ((GeeAbstractCollection*) matches, &_tmp22_);
					markdown_processor_markup_match_destroy (&_tmp21_);
					_g_free0 (replacement);
					_g_free0 (email);
				}
			}
		}
	}
	_g_match_info_unref0 (match_info);
}

static void
markdown_processor_collect_url_matches (MarkdownProcessor* self,
                                        const gchar* text,
                                        GeeArrayList* matches)
{
	GRegex* _tmp0_;
	GMatchInfo* match_info = NULL;
	GRegex* _tmp1_;
	GMatchInfo* _tmp2_ = NULL;
	gboolean _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (matches != NULL);
	_tmp0_ = self->priv->url_regex;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->url_regex;
	_tmp3_ = g_regex_match (_tmp1_, text, 0, &_tmp2_);
	_g_match_info_unref0 (match_info);
	match_info = _tmp2_;
	if (_tmp3_) {
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				gint start_pos = 0;
				gint end_pos = 0;
				GMatchInfo* _tmp7_;
				gint _tmp8_ = 0;
				gint _tmp9_ = 0;
				gboolean _tmp10_;
				if (!_tmp4_) {
					gboolean _tmp5_ = FALSE;
					GMatchInfo* _tmp6_;
					_tmp6_ = match_info;
					_tmp5_ = g_match_info_next (_tmp6_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_match_info_unref0 (match_info);
						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;
					}
					if (!_tmp5_) {
						break;
					}
				}
				_tmp4_ = FALSE;
				_tmp7_ = match_info;
				_tmp10_ = g_match_info_fetch_pos (_tmp7_, 0, &_tmp8_, &_tmp9_);
				start_pos = _tmp8_;
				end_pos = _tmp9_;
				if (_tmp10_) {
					gchar* url = NULL;
					GMatchInfo* _tmp11_;
					gchar* _tmp12_;
					_tmp11_ = match_info;
					_tmp12_ = g_match_info_fetch_named (_tmp11_, "url");
					url = _tmp12_;
					if (!markdown_processor_is_position_covered_by_priority (self, matches, start_pos, end_pos, (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_URL_MARKDOWN)) {
						gchar* replacement = NULL;
						const gchar* _tmp13_;
						const gchar* _tmp14_;
						const gchar* _tmp15_;
						const gchar* _tmp16_;
						gchar* _tmp17_;
						const gchar* _tmp18_;
						const gchar* _tmp19_;
						MarkdownProcessorMarkupMatch _tmp20_ = {0};
						MarkdownProcessorMarkupMatch _tmp21_;
						MarkdownProcessorMarkupMatch _tmp22_;
						_tmp13_ = url;
						_tmp14_ = string_to_string (_tmp13_);
						_tmp15_ = url;
						_tmp16_ = string_to_string (_tmp15_);
						_tmp17_ = g_strconcat ("<a href=\"", _tmp14_, "\">", _tmp16_, "</a>", NULL);
						replacement = _tmp17_;
						_tmp18_ = url;
						_tmp19_ = replacement;
						markdown_processor_markup_match_init (&_tmp20_, start_pos, end_pos, _tmp18_, _tmp19_, (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_URL);
						_tmp21_ = _tmp20_;
						_tmp22_ = _tmp21_;
						gee_abstract_collection_add ((GeeAbstractCollection*) matches, &_tmp22_);
						markdown_processor_markup_match_destroy (&_tmp21_);
						_g_free0 (replacement);
					}
					_g_free0 (url);
				}
			}
		}
	}
	_g_match_info_unref0 (match_info);
}

static void
markdown_processor_collect_code_matches (MarkdownProcessor* self,
                                         const gchar* text,
                                         GeeArrayList* matches)
{
	GRegex* _tmp0_;
	GMatchInfo* match_info = NULL;
	GRegex* _tmp1_;
	GMatchInfo* _tmp2_ = NULL;
	gboolean _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (matches != NULL);
	_tmp0_ = self->priv->code_regex;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->code_regex;
	_tmp3_ = g_regex_match (_tmp1_, text, 0, &_tmp2_);
	_g_match_info_unref0 (match_info);
	match_info = _tmp2_;
	if (_tmp3_) {
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				gint start_pos = 0;
				gint end_pos = 0;
				GMatchInfo* _tmp7_;
				gint _tmp8_ = 0;
				gint _tmp9_ = 0;
				gboolean _tmp10_;
				if (!_tmp4_) {
					gboolean _tmp5_ = FALSE;
					GMatchInfo* _tmp6_;
					_tmp6_ = match_info;
					_tmp5_ = g_match_info_next (_tmp6_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_match_info_unref0 (match_info);
						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;
					}
					if (!_tmp5_) {
						break;
					}
				}
				_tmp4_ = FALSE;
				_tmp7_ = match_info;
				_tmp10_ = g_match_info_fetch_pos (_tmp7_, 0, &_tmp8_, &_tmp9_);
				start_pos = _tmp8_;
				end_pos = _tmp9_;
				if (_tmp10_) {
					gchar* full_match = NULL;
					GMatchInfo* _tmp11_;
					gchar* _tmp12_;
					gchar* code_content = NULL;
					GMatchInfo* _tmp13_;
					gchar* _tmp14_;
					gchar* replacement = NULL;
					const gchar* _tmp15_;
					const gchar* _tmp16_;
					gchar* _tmp17_;
					const gchar* _tmp18_;
					const gchar* _tmp19_;
					MarkdownProcessorMarkupMatch _tmp20_ = {0};
					MarkdownProcessorMarkupMatch _tmp21_;
					MarkdownProcessorMarkupMatch _tmp22_;
					_tmp11_ = match_info;
					_tmp12_ = g_match_info_fetch (_tmp11_, 0);
					full_match = _tmp12_;
					_tmp13_ = match_info;
					_tmp14_ = g_match_info_fetch (_tmp13_, 1);
					code_content = _tmp14_;
					_tmp15_ = code_content;
					_tmp16_ = string_to_string (_tmp15_);
					_tmp17_ = g_strconcat ("<tt>", _tmp16_, "</tt>", NULL);
					replacement = _tmp17_;
					_tmp18_ = full_match;
					_tmp19_ = replacement;
					markdown_processor_markup_match_init (&_tmp20_, start_pos, end_pos, _tmp18_, _tmp19_, (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_CODE);
					_tmp21_ = _tmp20_;
					_tmp22_ = _tmp21_;
					gee_abstract_collection_add ((GeeAbstractCollection*) matches, &_tmp22_);
					markdown_processor_markup_match_destroy (&_tmp21_);
					_g_free0 (replacement);
					_g_free0 (code_content);
					_g_free0 (full_match);
				}
			}
		}
	}
	_g_match_info_unref0 (match_info);
}

static void
markdown_processor_collect_formatting_matches (MarkdownProcessor* self,
                                               const gchar* text,
                                               GeeArrayList* matches)
{
	GeeArrayList* format_patterns = NULL;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	GRegex* _tmp2_;
	MarkdownProcessorFormatPattern _tmp3_ = {0};
	MarkdownProcessorFormatPattern _tmp4_;
	MarkdownProcessorFormatPattern _tmp5_;
	GeeArrayList* _tmp6_;
	GRegex* _tmp7_;
	MarkdownProcessorFormatPattern _tmp8_ = {0};
	MarkdownProcessorFormatPattern _tmp9_;
	MarkdownProcessorFormatPattern _tmp10_;
	GeeArrayList* _tmp11_;
	GRegex* _tmp12_;
	MarkdownProcessorFormatPattern _tmp13_ = {0};
	MarkdownProcessorFormatPattern _tmp14_;
	MarkdownProcessorFormatPattern _tmp15_;
	GeeArrayList* _tmp16_;
	GRegex* _tmp17_;
	MarkdownProcessorFormatPattern _tmp18_ = {0};
	MarkdownProcessorFormatPattern _tmp19_;
	MarkdownProcessorFormatPattern _tmp20_;
	GeeArrayList* _tmp21_;
	GRegex* _tmp22_;
	MarkdownProcessorFormatPattern _tmp23_ = {0};
	MarkdownProcessorFormatPattern _tmp24_;
	MarkdownProcessorFormatPattern _tmp25_;
	GeeArrayList* _tmp26_;
	GRegex* _tmp27_;
	MarkdownProcessorFormatPattern _tmp28_ = {0};
	MarkdownProcessorFormatPattern _tmp29_;
	MarkdownProcessorFormatPattern _tmp30_;
	GeeArrayList* _tmp31_;
	GRegex* _tmp32_;
	MarkdownProcessorFormatPattern _tmp33_ = {0};
	MarkdownProcessorFormatPattern _tmp34_;
	MarkdownProcessorFormatPattern _tmp35_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (matches != NULL);
	_tmp0_ = gee_array_list_new (MARKDOWN_PROCESSOR_TYPE_FORMAT_PATTERN, (GBoxedCopyFunc) markdown_processor_format_pattern_dup, (GDestroyNotify) markdown_processor_format_pattern_free, NULL, NULL, NULL);
	format_patterns = _tmp0_;
	_tmp1_ = format_patterns;
	_tmp2_ = self->priv->italic_bold_underline_regex;
	markdown_processor_format_pattern_init (&_tmp3_, _tmp2_, "<i><b><u>%s</u></b></i>", (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_BOLD_UNDERLINE);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp1_, &_tmp5_);
	markdown_processor_format_pattern_destroy (&_tmp4_);
	_tmp6_ = format_patterns;
	_tmp7_ = self->priv->bold_underline_regex;
	markdown_processor_format_pattern_init (&_tmp8_, _tmp7_, "<b><u>%s</u></b>", (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_BOLD_UNDERLINE);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp6_, &_tmp10_);
	markdown_processor_format_pattern_destroy (&_tmp9_);
	_tmp11_ = format_patterns;
	_tmp12_ = self->priv->italic_underline_regex;
	markdown_processor_format_pattern_init (&_tmp13_, _tmp12_, "<i><u>%s</u></i>", (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_UNDERLINE);
	_tmp14_ = _tmp13_;
	_tmp15_ = _tmp14_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp11_, &_tmp15_);
	markdown_processor_format_pattern_destroy (&_tmp14_);
	_tmp16_ = format_patterns;
	_tmp17_ = self->priv->italic_bold_regex;
	markdown_processor_format_pattern_init (&_tmp18_, _tmp17_, "<i><b>%s</b></i>", (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC_BOLD);
	_tmp19_ = _tmp18_;
	_tmp20_ = _tmp19_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp16_, &_tmp20_);
	markdown_processor_format_pattern_destroy (&_tmp19_);
	_tmp21_ = format_patterns;
	_tmp22_ = self->priv->bold_regex;
	markdown_processor_format_pattern_init (&_tmp23_, _tmp22_, "<b>%s</b>", (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_BOLD);
	_tmp24_ = _tmp23_;
	_tmp25_ = _tmp24_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp21_, &_tmp25_);
	markdown_processor_format_pattern_destroy (&_tmp24_);
	_tmp26_ = format_patterns;
	_tmp27_ = self->priv->italic_regex;
	markdown_processor_format_pattern_init (&_tmp28_, _tmp27_, "<i>%s</i>", (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_ITALIC);
	_tmp29_ = _tmp28_;
	_tmp30_ = _tmp29_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp26_, &_tmp30_);
	markdown_processor_format_pattern_destroy (&_tmp29_);
	_tmp31_ = format_patterns;
	_tmp32_ = self->priv->underline_regex;
	markdown_processor_format_pattern_init (&_tmp33_, _tmp32_, "<u>%s</u>", (gint) MARKDOWN_PROCESSOR_MARKUP_PRIORITY_UNDERLINE);
	_tmp34_ = _tmp33_;
	_tmp35_ = _tmp34_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp31_, &_tmp35_);
	markdown_processor_format_pattern_destroy (&_tmp34_);
	{
		GeeArrayList* _pattern_list = NULL;
		GeeArrayList* _tmp36_;
		gint _pattern_size = 0;
		GeeArrayList* _tmp37_;
		gint _tmp38_;
		gint _tmp39_;
		gint _pattern_index = 0;
		_tmp36_ = format_patterns;
		_pattern_list = _tmp36_;
		_tmp37_ = _pattern_list;
		_tmp38_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp37_);
		_tmp39_ = _tmp38_;
		_pattern_size = _tmp39_;
		_pattern_index = -1;
		while (TRUE) {
			gint _tmp40_;
			gint _tmp41_;
			MarkdownProcessorFormatPattern* pattern = NULL;
			GeeArrayList* _tmp42_;
			gpointer _tmp43_;
			MarkdownProcessorFormatPattern* _tmp44_;
			MarkdownProcessorFormatPattern _tmp45_;
			_pattern_index = _pattern_index + 1;
			_tmp40_ = _pattern_index;
			_tmp41_ = _pattern_size;
			if (!(_tmp40_ < _tmp41_)) {
				break;
			}
			_tmp42_ = _pattern_list;
			_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) _tmp42_, _pattern_index);
			pattern = (MarkdownProcessorFormatPattern*) _tmp43_;
			_tmp44_ = pattern;
			_tmp45_ = *_tmp44_;
			markdown_processor_collect_pattern_matches (self, text, matches, &_tmp45_);
			_markdown_processor_format_pattern_free0 (pattern);
		}
	}
	_g_object_unref0 (format_patterns);
}

static void
markdown_processor_collect_pattern_matches (MarkdownProcessor* self,
                                            const gchar* text,
                                            GeeArrayList* matches,
                                            MarkdownProcessorFormatPattern* pattern)
{
	MarkdownProcessorFormatPattern _tmp0_;
	GRegex* _tmp1_;
	GMatchInfo* match_info = NULL;
	MarkdownProcessorFormatPattern _tmp2_;
	GRegex* _tmp3_;
	GMatchInfo* _tmp4_ = NULL;
	gboolean _tmp5_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (matches != NULL);
	g_return_if_fail (pattern != NULL);
	_tmp0_ = *pattern;
	_tmp1_ = _tmp0_.regex;
	if (_tmp1_ == NULL) {
		return;
	}
	_tmp2_ = *pattern;
	_tmp3_ = _tmp2_.regex;
	_tmp5_ = g_regex_match (_tmp3_, text, 0, &_tmp4_);
	_g_match_info_unref0 (match_info);
	match_info = _tmp4_;
	if (_tmp5_) {
		{
			gboolean _tmp6_ = FALSE;
			_tmp6_ = TRUE;
			while (TRUE) {
				gint start_pos = 0;
				gint end_pos = 0;
				GMatchInfo* _tmp9_;
				gint _tmp10_ = 0;
				gint _tmp11_ = 0;
				gboolean _tmp12_;
				if (!_tmp6_) {
					gboolean _tmp7_ = FALSE;
					GMatchInfo* _tmp8_;
					_tmp8_ = match_info;
					_tmp7_ = g_match_info_next (_tmp8_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_match_info_unref0 (match_info);
						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;
					}
					if (!_tmp7_) {
						break;
					}
				}
				_tmp6_ = FALSE;
				_tmp9_ = match_info;
				_tmp12_ = g_match_info_fetch_pos (_tmp9_, 0, &_tmp10_, &_tmp11_);
				start_pos = _tmp10_;
				end_pos = _tmp11_;
				if (_tmp12_) {
					gchar* full_match = NULL;
					GMatchInfo* _tmp13_;
					gchar* _tmp14_;
					gchar* inner_text = NULL;
					GMatchInfo* _tmp15_;
					gchar* _tmp16_;
					gchar* replacement = NULL;
					MarkdownProcessorFormatPattern _tmp17_;
					const gchar* _tmp18_;
					const gchar* _tmp19_;
					gchar* _tmp20_;
					const gchar* _tmp21_;
					const gchar* _tmp22_;
					MarkdownProcessorFormatPattern _tmp23_;
					MarkdownProcessorMarkupMatch _tmp24_ = {0};
					MarkdownProcessorMarkupMatch _tmp25_;
					MarkdownProcessorMarkupMatch _tmp26_;
					_tmp13_ = match_info;
					_tmp14_ = g_match_info_fetch (_tmp13_, 0);
					full_match = _tmp14_;
					_tmp15_ = match_info;
					_tmp16_ = g_match_info_fetch (_tmp15_, 1);
					inner_text = _tmp16_;
					_tmp17_ = *pattern;
					_tmp18_ = _tmp17_.format_template;
					_tmp19_ = inner_text;
					_tmp20_ = g_strdup_printf (_tmp18_, _tmp19_);
					replacement = _tmp20_;
					_tmp21_ = full_match;
					_tmp22_ = replacement;
					_tmp23_ = *pattern;
					markdown_processor_markup_match_init (&_tmp24_, start_pos, end_pos, _tmp21_, _tmp22_, _tmp23_.priority);
					_tmp25_ = _tmp24_;
					_tmp26_ = _tmp25_;
					gee_abstract_collection_add ((GeeAbstractCollection*) matches, &_tmp26_);
					markdown_processor_markup_match_destroy (&_tmp25_);
					_g_free0 (replacement);
					_g_free0 (inner_text);
					_g_free0 (full_match);
				}
			}
		}
	}
	_g_match_info_unref0 (match_info);
}

static gboolean
markdown_processor_is_position_covered_by_priority (MarkdownProcessor* self,
                                                    GeeArrayList* matches,
                                                    gint start_pos,
                                                    gint end_pos,
                                                    gint min_priority)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (matches != NULL, FALSE);
	{
		GeeArrayList* _match_list = NULL;
		gint _match_size = 0;
		GeeArrayList* _tmp0_;
		gint _tmp1_;
		gint _tmp2_;
		gint _match_index = 0;
		_match_list = matches;
		_tmp0_ = _match_list;
		_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
		_tmp2_ = _tmp1_;
		_match_size = _tmp2_;
		_match_index = -1;
		while (TRUE) {
			gint _tmp3_;
			gint _tmp4_;
			MarkdownProcessorMarkupMatch* match = NULL;
			GeeArrayList* _tmp5_;
			gpointer _tmp6_;
			gboolean _tmp7_ = FALSE;
			MarkdownProcessorMarkupMatch* _tmp8_;
			_match_index = _match_index + 1;
			_tmp3_ = _match_index;
			_tmp4_ = _match_size;
			if (!(_tmp3_ < _tmp4_)) {
				break;
			}
			_tmp5_ = _match_list;
			_tmp6_ = gee_abstract_list_get ((GeeAbstractList*) _tmp5_, _match_index);
			match = (MarkdownProcessorMarkupMatch*) _tmp6_;
			_tmp8_ = match;
			if ((*_tmp8_).priority <= min_priority) {
				MarkdownProcessorMarkupMatch* _tmp9_;
				MarkdownProcessorMarkupMatch* _tmp10_;
				_tmp9_ = match;
				_tmp10_ = match;
				_tmp7_ = markdown_processor_ranges_overlap (self, (*_tmp9_).start_pos, (*_tmp10_).end_pos, start_pos, end_pos);
			} else {
				_tmp7_ = FALSE;
			}
			if (_tmp7_) {
				result = TRUE;
				_markdown_processor_markup_match_free0 (match);
				return result;
			}
			_markdown_processor_markup_match_free0 (match);
		}
	}
	result = FALSE;
	return result;
}

static gboolean
markdown_processor_ranges_overlap (MarkdownProcessor* self,
                                   gint start1,
                                   gint end1,
                                   gint start2,
                                   gint end2)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (end1 <= start2) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = end2 <= start1;
	}
	result = !_tmp0_;
	return result;
}

static gint
__lambda349_ (MarkdownProcessor* self,
              MarkdownProcessorMarkupMatch* a,
              MarkdownProcessorMarkupMatch* b)
{
	gint result;
	if ((*a).priority != (*b).priority) {
		result = (*a).priority - (*b).priority;
		return result;
	}
	result = (*a).start_pos - (*b).start_pos;
	return result;
}

static gint
___lambda349__gcompare_data_func (gconstpointer a,
                                  gconstpointer b,
                                  gpointer self)
{
	gint result;
	result = __lambda349_ ((MarkdownProcessor*) self, (MarkdownProcessorMarkupMatch*) a, (MarkdownProcessorMarkupMatch*) b);
	return result;
}

static gint
__lambda350_ (MarkdownProcessor* self,
              MarkdownProcessorMarkupMatch* a,
              MarkdownProcessorMarkupMatch* b)
{
	gint result;
	result = (*b).start_pos - (*a).start_pos;
	return result;
}

static gint
___lambda350__gcompare_data_func (gconstpointer a,
                                  gconstpointer b,
                                  gpointer self)
{
	gint result;
	result = __lambda350_ ((MarkdownProcessor*) self, (MarkdownProcessorMarkupMatch*) a, (MarkdownProcessorMarkupMatch*) b);
	return result;
}

static GeeArrayList*
markdown_processor_filter_and_sort_matches (MarkdownProcessor* self,
                                            GeeArrayList* matches)
{
	GeeArrayList* filtered = NULL;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp22_;
	GeeArrayList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (matches != NULL, NULL);
	_tmp0_ = gee_array_list_new (MARKDOWN_PROCESSOR_TYPE_MARKUP_MATCH, (GBoxedCopyFunc) markdown_processor_markup_match_dup, (GDestroyNotify) markdown_processor_markup_match_free, NULL, NULL, NULL);
	filtered = _tmp0_;
	gee_list_sort ((GeeList*) matches, ___lambda349__gcompare_data_func, g_object_ref (self), g_object_unref);
	{
		GeeArrayList* _current_match_list = NULL;
		gint _current_match_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _current_match_index = 0;
		_current_match_list = matches;
		_tmp1_ = _current_match_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_current_match_size = _tmp3_;
		_current_match_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			MarkdownProcessorMarkupMatch* current_match = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			gboolean should_add = FALSE;
			_current_match_index = _current_match_index + 1;
			_tmp4_ = _current_match_index;
			_tmp5_ = _current_match_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _current_match_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _current_match_index);
			current_match = (MarkdownProcessorMarkupMatch*) _tmp7_;
			should_add = TRUE;
			{
				GeeArrayList* _existing_match_list = NULL;
				GeeArrayList* _tmp8_;
				gint _existing_match_size = 0;
				GeeArrayList* _tmp9_;
				gint _tmp10_;
				gint _tmp11_;
				gint _existing_match_index = 0;
				_tmp8_ = filtered;
				_existing_match_list = _tmp8_;
				_tmp9_ = _existing_match_list;
				_tmp10_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp9_);
				_tmp11_ = _tmp10_;
				_existing_match_size = _tmp11_;
				_existing_match_index = -1;
				while (TRUE) {
					gint _tmp12_;
					gint _tmp13_;
					MarkdownProcessorMarkupMatch* existing_match = NULL;
					GeeArrayList* _tmp14_;
					gpointer _tmp15_;
					MarkdownProcessorMarkupMatch* _tmp16_;
					MarkdownProcessorMarkupMatch* _tmp17_;
					MarkdownProcessorMarkupMatch* _tmp18_;
					MarkdownProcessorMarkupMatch* _tmp19_;
					_existing_match_index = _existing_match_index + 1;
					_tmp12_ = _existing_match_index;
					_tmp13_ = _existing_match_size;
					if (!(_tmp12_ < _tmp13_)) {
						break;
					}
					_tmp14_ = _existing_match_list;
					_tmp15_ = gee_abstract_list_get ((GeeAbstractList*) _tmp14_, _existing_match_index);
					existing_match = (MarkdownProcessorMarkupMatch*) _tmp15_;
					_tmp16_ = existing_match;
					_tmp17_ = existing_match;
					_tmp18_ = current_match;
					_tmp19_ = current_match;
					if (markdown_processor_ranges_overlap (self, (*_tmp16_).start_pos, (*_tmp17_).end_pos, (*_tmp18_).start_pos, (*_tmp19_).end_pos)) {
						should_add = FALSE;
						_markdown_processor_markup_match_free0 (existing_match);
						break;
					}
					_markdown_processor_markup_match_free0 (existing_match);
				}
			}
			if (should_add) {
				GeeArrayList* _tmp20_;
				MarkdownProcessorMarkupMatch* _tmp21_;
				_tmp20_ = filtered;
				_tmp21_ = current_match;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp20_, _tmp21_);
			}
			_markdown_processor_markup_match_free0 (current_match);
		}
	}
	_tmp22_ = filtered;
	gee_list_sort ((GeeList*) _tmp22_, ___lambda350__gcompare_data_func, g_object_ref (self), g_object_unref);
	result = filtered;
	return result;
}

static gchar*
markdown_processor_apply_matches (MarkdownProcessor* self,
                                  const gchar* text,
                                  GeeArrayList* matches)
{
	GString* _result_ = NULL;
	GString* _tmp0_;
	GString* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (text != NULL, NULL);
	g_return_val_if_fail (matches != NULL, NULL);
	_tmp0_ = g_string_new (text);
	_result_ = _tmp0_;
	{
		GeeArrayList* _match_list = NULL;
		gint _match_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _match_index = 0;
		_match_list = matches;
		_tmp1_ = _match_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_match_size = _tmp3_;
		_match_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			MarkdownProcessorMarkupMatch* match = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			GString* _tmp8_;
			MarkdownProcessorMarkupMatch* _tmp9_;
			MarkdownProcessorMarkupMatch* _tmp10_;
			MarkdownProcessorMarkupMatch* _tmp11_;
			GString* _tmp12_;
			MarkdownProcessorMarkupMatch* _tmp13_;
			MarkdownProcessorMarkupMatch* _tmp14_;
			const gchar* _tmp15_;
			_match_index = _match_index + 1;
			_tmp4_ = _match_index;
			_tmp5_ = _match_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _match_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _match_index);
			match = (MarkdownProcessorMarkupMatch*) _tmp7_;
			_tmp8_ = _result_;
			_tmp9_ = match;
			_tmp10_ = match;
			_tmp11_ = match;
			g_string_erase (_tmp8_, (gssize) (*_tmp9_).start_pos, (gssize) ((*_tmp10_).end_pos - (*_tmp11_).start_pos));
			_tmp12_ = _result_;
			_tmp13_ = match;
			_tmp14_ = match;
			_tmp15_ = (*_tmp14_).replacement;
			g_string_insert (_tmp12_, (gssize) (*_tmp13_).start_pos, _tmp15_);
			_markdown_processor_markup_match_free0 (match);
		}
	}
	_tmp16_ = _result_;
	_tmp17_ = _tmp16_->str;
	_tmp18_ = g_strdup (_tmp17_);
	result = _tmp18_;
	_g_string_free0 (_result_);
	return result;
}

static void
markdown_processor_markup_match_init (MarkdownProcessorMarkupMatch *self,
                                      gint start,
                                      gint end,
                                      const gchar* orig,
                                      const gchar* repl,
                                      gint prio)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (orig != NULL);
	g_return_if_fail (repl != NULL);
	memset (self, 0, sizeof (MarkdownProcessorMarkupMatch));
	(*self).start_pos = start;
	(*self).end_pos = end;
	_tmp0_ = g_strdup (orig);
	_g_free0 ((*self).original);
	(*self).original = _tmp0_;
	_tmp1_ = g_strdup (repl);
	_g_free0 ((*self).replacement);
	(*self).replacement = _tmp1_;
	(*self).priority = prio;
}

static void
markdown_processor_markup_match_copy (const MarkdownProcessorMarkupMatch* self,
                                      MarkdownProcessorMarkupMatch* dest)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	(*dest).start_pos = (*self).start_pos;
	(*dest).end_pos = (*self).end_pos;
	_tmp0_ = (*self).original;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 ((*dest).original);
	(*dest).original = _tmp1_;
	_tmp2_ = (*self).replacement;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 ((*dest).replacement);
	(*dest).replacement = _tmp3_;
	(*dest).priority = (*self).priority;
}

static void
markdown_processor_markup_match_destroy (MarkdownProcessorMarkupMatch* self)
{
	_g_free0 ((*self).original);
	_g_free0 ((*self).replacement);
}

static MarkdownProcessorMarkupMatch*
markdown_processor_markup_match_dup (const MarkdownProcessorMarkupMatch* self)
{
	MarkdownProcessorMarkupMatch* dup;
	dup = g_new0 (MarkdownProcessorMarkupMatch, 1);
	markdown_processor_markup_match_copy (self, dup);
	return dup;
}

static void
markdown_processor_markup_match_free (MarkdownProcessorMarkupMatch* self)
{
	markdown_processor_markup_match_destroy (self);
	g_free (self);
}

static GType
markdown_processor_markup_match_get_type_once (void)
{
	GType markdown_processor_markup_match_type_id;
	markdown_processor_markup_match_type_id = g_boxed_type_register_static ("MarkdownProcessorMarkupMatch", (GBoxedCopyFunc) markdown_processor_markup_match_dup, (GBoxedFreeFunc) markdown_processor_markup_match_free);
	return markdown_processor_markup_match_type_id;
}

static GType
markdown_processor_markup_match_get_type (void)
{
	static volatile gsize markdown_processor_markup_match_type_id__once = 0;
	if (g_once_init_enter (&markdown_processor_markup_match_type_id__once)) {
		GType markdown_processor_markup_match_type_id;
		markdown_processor_markup_match_type_id = markdown_processor_markup_match_get_type_once ();
		g_once_init_leave (&markdown_processor_markup_match_type_id__once, markdown_processor_markup_match_type_id);
	}
	return markdown_processor_markup_match_type_id__once;
}

static gpointer
_g_regex_ref0 (gpointer self)
{
	return self ? g_regex_ref (self) : NULL;
}

static void
markdown_processor_format_pattern_init (MarkdownProcessorFormatPattern *self,
                                        GRegex* r,
                                        const gchar* template,
                                        gint prio)
{
	GRegex* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (template != NULL);
	memset (self, 0, sizeof (MarkdownProcessorFormatPattern));
	_tmp0_ = _g_regex_ref0 (r);
	_g_regex_unref0 ((*self).regex);
	(*self).regex = _tmp0_;
	_tmp1_ = g_strdup (template);
	_g_free0 ((*self).format_template);
	(*self).format_template = _tmp1_;
	(*self).priority = prio;
}

static void
markdown_processor_format_pattern_copy (const MarkdownProcessorFormatPattern* self,
                                        MarkdownProcessorFormatPattern* dest)
{
	GRegex* _tmp0_;
	GRegex* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = (*self).regex;
	_tmp1_ = _g_regex_ref0 (_tmp0_);
	_g_regex_unref0 ((*dest).regex);
	(*dest).regex = _tmp1_;
	_tmp2_ = (*self).format_template;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 ((*dest).format_template);
	(*dest).format_template = _tmp3_;
	(*dest).priority = (*self).priority;
}

static void
markdown_processor_format_pattern_destroy (MarkdownProcessorFormatPattern* self)
{
	_g_regex_unref0 ((*self).regex);
	_g_free0 ((*self).format_template);
}

static MarkdownProcessorFormatPattern*
markdown_processor_format_pattern_dup (const MarkdownProcessorFormatPattern* self)
{
	MarkdownProcessorFormatPattern* dup;
	dup = g_new0 (MarkdownProcessorFormatPattern, 1);
	markdown_processor_format_pattern_copy (self, dup);
	return dup;
}

static void
markdown_processor_format_pattern_free (MarkdownProcessorFormatPattern* self)
{
	markdown_processor_format_pattern_destroy (self);
	g_free (self);
}

static GType
markdown_processor_format_pattern_get_type_once (void)
{
	GType markdown_processor_format_pattern_type_id;
	markdown_processor_format_pattern_type_id = g_boxed_type_register_static ("MarkdownProcessorFormatPattern", (GBoxedCopyFunc) markdown_processor_format_pattern_dup, (GBoxedFreeFunc) markdown_processor_format_pattern_free);
	return markdown_processor_format_pattern_type_id;
}

static GType
markdown_processor_format_pattern_get_type (void)
{
	static volatile gsize markdown_processor_format_pattern_type_id__once = 0;
	if (g_once_init_enter (&markdown_processor_format_pattern_type_id__once)) {
		GType markdown_processor_format_pattern_type_id;
		markdown_processor_format_pattern_type_id = markdown_processor_format_pattern_get_type_once ();
		g_once_init_leave (&markdown_processor_format_pattern_type_id__once, markdown_processor_format_pattern_type_id);
	}
	return markdown_processor_format_pattern_type_id__once;
}

static void
markdown_processor_class_init (MarkdownProcessorClass * klass,
                               gpointer klass_data)
{
	markdown_processor_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MarkdownProcessor_private_offset);
	G_OBJECT_CLASS (klass)->finalize = markdown_processor_finalize;
}

static void
markdown_processor_instance_init (MarkdownProcessor * self,
                                  gpointer klass)
{
	self->priv = markdown_processor_get_instance_private (self);
	self->priv->mailto_regex = NULL;
	self->priv->url_regex = NULL;
	self->priv->url_markdown_regex = NULL;
	self->priv->code_regex = NULL;
	self->priv->italic_bold_underline_regex = NULL;
	self->priv->bold_underline_regex = NULL;
	self->priv->italic_underline_regex = NULL;
	self->priv->italic_bold_regex = NULL;
	self->priv->bold_regex = NULL;
	self->priv->italic_regex = NULL;
	self->priv->underline_regex = NULL;
}

static void
markdown_processor_finalize (GObject * obj)
{
	MarkdownProcessor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MARKDOWN_PROCESSOR, MarkdownProcessor);
	_g_regex_unref0 (self->priv->mailto_regex);
	_g_regex_unref0 (self->priv->url_regex);
	_g_regex_unref0 (self->priv->url_markdown_regex);
	_g_regex_unref0 (self->priv->code_regex);
	_g_regex_unref0 (self->priv->italic_bold_underline_regex);
	_g_regex_unref0 (self->priv->bold_underline_regex);
	_g_regex_unref0 (self->priv->italic_underline_regex);
	_g_regex_unref0 (self->priv->italic_bold_regex);
	_g_regex_unref0 (self->priv->bold_regex);
	_g_regex_unref0 (self->priv->italic_regex);
	_g_regex_unref0 (self->priv->underline_regex);
	G_OBJECT_CLASS (markdown_processor_parent_class)->finalize (obj);
}

static GType
markdown_processor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MarkdownProcessorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) markdown_processor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MarkdownProcessor), 0, (GInstanceInitFunc) markdown_processor_instance_init, NULL };
	GType markdown_processor_type_id;
	markdown_processor_type_id = g_type_register_static (G_TYPE_OBJECT, "MarkdownProcessor", &g_define_type_info, 0);
	MarkdownProcessor_private_offset = g_type_add_instance_private (markdown_processor_type_id, sizeof (MarkdownProcessorPrivate));
	return markdown_processor_type_id;
}

GType
markdown_processor_get_type (void)
{
	static volatile gsize markdown_processor_type_id__once = 0;
	if (g_once_init_enter (&markdown_processor_type_id__once)) {
		GType markdown_processor_type_id;
		markdown_processor_type_id = markdown_processor_get_type_once ();
		g_once_init_leave (&markdown_processor_type_id__once, markdown_processor_type_id);
	}
	return markdown_processor_type_id__once;
}

