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

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_TYPE_MARKDOWN (dc_markdown_get_type ())
#define DC_MARKDOWN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_MARKDOWN, DcMarkdown))
#define DC_MARKDOWN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_MARKDOWN, DcMarkdownClass))
#define DC_IS_MARKDOWN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_MARKDOWN))
#define DC_IS_MARKDOWN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_MARKDOWN))
#define DC_MARKDOWN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_MARKDOWN, DcMarkdownClass))

typedef struct _DcMarkdown DcMarkdown;
typedef struct _DcMarkdownClass DcMarkdownClass;
typedef struct _DcMarkdownPrivate DcMarkdownPrivate;
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))
typedef struct _Block16Data Block16Data;
typedef struct _DcParamSpecMarkdown DcParamSpecMarkdown;

struct _DcMarkdown {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DcMarkdownPrivate * priv;
};

struct _DcMarkdownClass {
	GTypeClass parent_class;
	void (*finalize) (DcMarkdown *self);
};

struct _Block16Data {
	int _ref_count_;
	GPtrArray* segments;
};

struct _DcParamSpecMarkdown {
	GParamSpec parent_instance;
};

static gpointer dc_markdown_parent_class = NULL;
VALA_EXTERN gboolean dc_markdown_enabled;
gboolean dc_markdown_enabled = FALSE;
static GRegex* dc_markdown_cb_re;
static GRegex* dc_markdown_cb_re = NULL;
static GRegex* dc_markdown_ic_re;
static GRegex* dc_markdown_ic_re = NULL;
static GRegex* dc_markdown_bold_re;
static GRegex* dc_markdown_bold_re = NULL;
static GRegex* dc_markdown_italic_re;
static GRegex* dc_markdown_italic_re = NULL;
static GRegex* dc_markdown_italic2_re;
static GRegex* dc_markdown_italic2_re = NULL;
static GRegex* dc_markdown_strike_re;
static GRegex* dc_markdown_strike_re = NULL;
static GRegex* dc_markdown_heading_re;
static GRegex* dc_markdown_heading_re = NULL;
static GRegex* dc_markdown_link_re;
static GRegex* dc_markdown_link_re = NULL;

VALA_EXTERN gpointer dc_markdown_ref (gpointer instance);
VALA_EXTERN void dc_markdown_unref (gpointer instance);
VALA_EXTERN GParamSpec* dc_param_spec_markdown (const gchar* name,
                                    const gchar* nick,
                                    const gchar* blurb,
                                    GType object_type,
                                    GParamFlags flags);
VALA_EXTERN void dc_value_set_markdown (GValue* value,
                            gpointer v_object);
VALA_EXTERN void dc_value_take_markdown (GValue* value,
                             gpointer v_object);
VALA_EXTERN gpointer dc_value_get_markdown (const GValue* value);
VALA_EXTERN GType dc_markdown_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcMarkdown, dc_markdown_unref)
static void dc_markdown_ensure_regexes (GError** error);
VALA_EXTERN gchar* dc_markdown_format (const gchar* input);
static gchar* dc_markdown_linkify (const gchar* escaped);
static gchar* dc_markdown_format_markdown (const gchar* escaped,
                                    GError** error);
static void _g_free0_ (gpointer var);
static gchar* dc_markdown_extract_code (GRegex* re,
                                 const gchar* input,
                                 GPtrArray* segments,
                                 GError** error);
static gboolean __lambda7_ (GMatchInfo* mi,
                     GString* sb);
static gboolean ___lambda7__gregex_eval_callback (GMatchInfo* match_info,
                                           GString* _result_,
                                           gpointer self);
static Block16Data* block16_data_ref (Block16Data* _data16_);
static void block16_data_unref (void * _userdata_);
static gboolean __lambda6_ (Block16Data* _data16_,
                     GMatchInfo* mi,
                     GString* sb);
static gboolean ___lambda6__gregex_eval_callback (GMatchInfo* match_info,
                                           GString* _result_,
                                           gpointer self);
static gboolean ___lambda5_ (GMatchInfo* mi,
                      GString* sb);
static gboolean ____lambda5__gregex_eval_callback (GMatchInfo* match_info,
                                            GString* _result_,
                                            gpointer self);
VALA_EXTERN DcMarkdown* dc_markdown_new (void);
VALA_EXTERN DcMarkdown* dc_markdown_construct (GType object_type);
static void dc_markdown_finalize (DcMarkdown * obj);
static GType dc_markdown_get_type_once (void);

static void
dc_markdown_ensure_regexes (GError** error)
{
	GRegex* _tmp0_;
	GRegex* _tmp1_ = NULL;
	GRegex* _tmp2_;
	GRegex* _tmp3_;
	GRegex* _tmp4_ = NULL;
	GRegex* _tmp5_;
	GRegex* _tmp6_;
	GRegex* _tmp7_ = NULL;
	GRegex* _tmp8_;
	GRegex* _tmp9_;
	GRegex* _tmp10_ = NULL;
	GRegex* _tmp11_;
	GRegex* _tmp12_;
	GRegex* _tmp13_ = NULL;
	GRegex* _tmp14_;
	GRegex* _tmp15_;
	GRegex* _tmp16_ = NULL;
	GRegex* _tmp17_;
	GRegex* _tmp18_;
	GRegex* _tmp19_ = NULL;
	GRegex* _tmp20_;
	GRegex* _tmp21_;
	GRegex* _tmp22_ = NULL;
	GRegex* _tmp23_;
	GRegex* _tmp24_;
	GError* _inner_error0_ = NULL;
	_tmp0_ = dc_markdown_cb_re;
	if (_tmp0_ != NULL) {
		return;
	}
	_tmp2_ = g_regex_new ("```(?:[a-zA-Z]*)\\n?([\\s\\S]*?)```", 0, 0, &_inner_error0_);
	_tmp1_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return;
		} else {
			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;
		}
	}
	_tmp3_ = _tmp1_;
	_tmp1_ = NULL;
	_g_regex_unref0 (dc_markdown_cb_re);
	dc_markdown_cb_re = _tmp3_;
	_tmp5_ = g_regex_new ("`([^`\\n]+)`", 0, 0, &_inner_error0_);
	_tmp4_ = _tmp5_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_regex_unref0 (_tmp1_);
			return;
		} else {
			_g_regex_unref0 (_tmp1_);
			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;
		}
	}
	_tmp6_ = _tmp4_;
	_tmp4_ = NULL;
	_g_regex_unref0 (dc_markdown_ic_re);
	dc_markdown_ic_re = _tmp6_;
	_tmp8_ = g_regex_new ("(\\*\\*|__)(.+?)\\1", 0, 0, &_inner_error0_);
	_tmp7_ = _tmp8_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			return;
		} else {
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			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;
		}
	}
	_tmp9_ = _tmp7_;
	_tmp7_ = NULL;
	_g_regex_unref0 (dc_markdown_bold_re);
	dc_markdown_bold_re = _tmp9_;
	_tmp11_ = g_regex_new ("\\*([^\\*\\n]+)\\*", 0, 0, &_inner_error0_);
	_tmp10_ = _tmp11_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			return;
		} else {
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			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;
		}
	}
	_tmp12_ = _tmp10_;
	_tmp10_ = NULL;
	_g_regex_unref0 (dc_markdown_italic_re);
	dc_markdown_italic_re = _tmp12_;
	_tmp14_ = g_regex_new ("(?<!\\w)_([^_\\n]+)_(?!\\w)", 0, 0, &_inner_error0_);
	_tmp13_ = _tmp14_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_regex_unref0 (_tmp10_);
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			return;
		} else {
			_g_regex_unref0 (_tmp10_);
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			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;
		}
	}
	_tmp15_ = _tmp13_;
	_tmp13_ = NULL;
	_g_regex_unref0 (dc_markdown_italic2_re);
	dc_markdown_italic2_re = _tmp15_;
	_tmp17_ = g_regex_new ("~~(.+?)~~", 0, 0, &_inner_error0_);
	_tmp16_ = _tmp17_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_regex_unref0 (_tmp13_);
			_g_regex_unref0 (_tmp10_);
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			return;
		} else {
			_g_regex_unref0 (_tmp13_);
			_g_regex_unref0 (_tmp10_);
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			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;
		}
	}
	_tmp18_ = _tmp16_;
	_tmp16_ = NULL;
	_g_regex_unref0 (dc_markdown_strike_re);
	dc_markdown_strike_re = _tmp18_;
	_tmp20_ = g_regex_new ("^(#{1,3}) +(.+)$", G_REGEX_MULTILINE, 0, &_inner_error0_);
	_tmp19_ = _tmp20_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_regex_unref0 (_tmp16_);
			_g_regex_unref0 (_tmp13_);
			_g_regex_unref0 (_tmp10_);
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			return;
		} else {
			_g_regex_unref0 (_tmp16_);
			_g_regex_unref0 (_tmp13_);
			_g_regex_unref0 (_tmp10_);
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			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;
		}
	}
	_tmp21_ = _tmp19_;
	_tmp19_ = NULL;
	_g_regex_unref0 (dc_markdown_heading_re);
	dc_markdown_heading_re = _tmp21_;
	_tmp23_ = g_regex_new ("(https?://[^\\s<>\"]+)", 0, 0, &_inner_error0_);
	_tmp22_ = _tmp23_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_regex_unref0 (_tmp19_);
			_g_regex_unref0 (_tmp16_);
			_g_regex_unref0 (_tmp13_);
			_g_regex_unref0 (_tmp10_);
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			return;
		} else {
			_g_regex_unref0 (_tmp19_);
			_g_regex_unref0 (_tmp16_);
			_g_regex_unref0 (_tmp13_);
			_g_regex_unref0 (_tmp10_);
			_g_regex_unref0 (_tmp7_);
			_g_regex_unref0 (_tmp4_);
			_g_regex_unref0 (_tmp1_);
			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;
		}
	}
	_tmp24_ = _tmp22_;
	_tmp22_ = NULL;
	_g_regex_unref0 (dc_markdown_link_re);
	dc_markdown_link_re = _tmp24_;
	_g_regex_unref0 (_tmp22_);
	_g_regex_unref0 (_tmp19_);
	_g_regex_unref0 (_tmp16_);
	_g_regex_unref0 (_tmp13_);
	_g_regex_unref0 (_tmp10_);
	_g_regex_unref0 (_tmp7_);
	_g_regex_unref0 (_tmp4_);
	_g_regex_unref0 (_tmp1_);
}

/**
         * Format message text. Always linkifies URLs.
         * When enabled, also converts markdown syntax to Pango markup.
         */
gchar*
dc_markdown_format (const gchar* input)
{
	gchar* escaped = NULL;
	gchar* _tmp0_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (input != NULL, NULL);
	_tmp0_ = g_markup_escape_text (input, (gssize) -1);
	escaped = _tmp0_;
	if (!dc_markdown_enabled) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = escaped;
		_tmp2_ = dc_markdown_linkify (_tmp1_);
		result = _tmp2_;
		_g_free0 (escaped);
		return result;
	}
	{
		gchar* _tmp3_ = NULL;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp4_ = escaped;
		_tmp5_ = dc_markdown_format_markdown (_tmp4_, &_inner_error0_);
		_tmp3_ = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_free0 (escaped);
			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;
		}
		_tmp6_ = _tmp3_;
		_tmp3_ = NULL;
		result = _tmp6_;
		_g_free0 (_tmp3_);
		_g_free0 (escaped);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		const gchar* _tmp7_;
		gchar* _tmp8_;
		g_clear_error (&_inner_error0_);
		_tmp7_ = escaped;
		_tmp8_ = dc_markdown_linkify (_tmp7_);
		result = _tmp8_;
		_g_free0 (escaped);
		return result;
	}
	__finally0:
	_g_free0 (escaped);
	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 void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static gboolean
__lambda7_ (GMatchInfo* mi,
            GString* sb)
{
	gchar* text = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	gboolean result;
	g_return_val_if_fail (mi != NULL, FALSE);
	g_return_val_if_fail (sb != NULL, FALSE);
	_tmp0_ = g_match_info_fetch (mi, 2);
	text = _tmp0_;
	_tmp1_ = g_match_info_fetch (mi, 1);
	_tmp2_ = _tmp1_;
	_tmp3_ = strlen (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp2_);
	switch (_tmp5_) {
		case 1:
		{
			const gchar* _tmp6_;
			gchar* _tmp7_;
			gchar* _tmp8_;
			gchar* _tmp9_;
			gchar* _tmp10_;
			_tmp6_ = text;
			_tmp7_ = g_strconcat ("<span size=\"x-large\"><b>", _tmp6_, NULL);
			_tmp8_ = _tmp7_;
			_tmp9_ = g_strconcat (_tmp8_, "</b></span>", NULL);
			_tmp10_ = _tmp9_;
			g_string_append (sb, _tmp10_);
			_g_free0 (_tmp10_);
			_g_free0 (_tmp8_);
			break;
		}
		case 2:
		{
			const gchar* _tmp11_;
			gchar* _tmp12_;
			gchar* _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			_tmp11_ = text;
			_tmp12_ = g_strconcat ("<span size=\"large\"><b>", _tmp11_, NULL);
			_tmp13_ = _tmp12_;
			_tmp14_ = g_strconcat (_tmp13_, "</b></span>", NULL);
			_tmp15_ = _tmp14_;
			g_string_append (sb, _tmp15_);
			_g_free0 (_tmp15_);
			_g_free0 (_tmp13_);
			break;
		}
		default:
		{
			const gchar* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			_tmp16_ = text;
			_tmp17_ = g_strconcat ("<b>", _tmp16_, NULL);
			_tmp18_ = _tmp17_;
			_tmp19_ = g_strconcat (_tmp18_, "</b>", NULL);
			_tmp20_ = _tmp19_;
			g_string_append (sb, _tmp20_);
			_g_free0 (_tmp20_);
			_g_free0 (_tmp18_);
			break;
		}
	}
	result = FALSE;
	_g_free0 (text);
	return result;
}

static gboolean
___lambda7__gregex_eval_callback (GMatchInfo* match_info,
                                  GString* _result_,
                                  gpointer self)
{
	gboolean result;
	result = __lambda7_ (match_info, _result_);
	return result;
}

static gint
vala_g_ptr_array_get_length (GPtrArray* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = (gint) self->len;
	return result;
}

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*
dc_markdown_format_markdown (const gchar* escaped,
                             GError** error)
{
	GPtrArray* segments = NULL;
	GPtrArray* _tmp0_;
	gchar* work = NULL;
	gchar* _tmp1_;
	gchar* _tmp2_ = NULL;
	GRegex* _tmp3_;
	const gchar* _tmp4_;
	GPtrArray* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_ = NULL;
	GRegex* _tmp9_;
	const gchar* _tmp10_;
	GPtrArray* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_ = NULL;
	GRegex* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_ = NULL;
	GRegex* _tmp20_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_ = NULL;
	GRegex* _tmp25_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_ = NULL;
	GRegex* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	gchar* _tmp34_ = NULL;
	GRegex* _tmp35_;
	const gchar* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	const gchar* _tmp39_;
	gchar* _tmp40_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (escaped != NULL, NULL);
	dc_markdown_ensure_regexes (&_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			return NULL;
		} else {
			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;
		}
	}
	_tmp0_ = g_ptr_array_new_full ((guint) 0, _g_free0_);
	segments = _tmp0_;
	_tmp1_ = g_strdup (escaped);
	work = _tmp1_;
	_tmp3_ = dc_markdown_cb_re;
	_tmp4_ = work;
	_tmp5_ = segments;
	_tmp6_ = dc_markdown_extract_code (_tmp3_, _tmp4_, _tmp5_, &_inner_error0_);
	_tmp2_ = _tmp6_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			return NULL;
		} else {
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			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;
		}
	}
	_tmp7_ = _tmp2_;
	_tmp2_ = NULL;
	_g_free0 (work);
	work = _tmp7_;
	_tmp9_ = dc_markdown_ic_re;
	_tmp10_ = work;
	_tmp11_ = segments;
	_tmp12_ = dc_markdown_extract_code (_tmp9_, _tmp10_, _tmp11_, &_inner_error0_);
	_tmp8_ = _tmp12_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			return NULL;
		} else {
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			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;
		}
	}
	_tmp13_ = _tmp8_;
	_tmp8_ = NULL;
	_g_free0 (work);
	work = _tmp13_;
	_tmp15_ = dc_markdown_bold_re;
	_tmp16_ = work;
	_tmp17_ = g_regex_replace (_tmp15_, _tmp16_, (gssize) -1, 0, "<b>\\2</b>", 0, &_inner_error0_);
	_tmp14_ = _tmp17_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			return NULL;
		} else {
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			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;
		}
	}
	_tmp18_ = _tmp14_;
	_tmp14_ = NULL;
	_g_free0 (work);
	work = _tmp18_;
	_tmp20_ = dc_markdown_italic_re;
	_tmp21_ = work;
	_tmp22_ = g_regex_replace (_tmp20_, _tmp21_, (gssize) -1, 0, "<i>\\1</i>", 0, &_inner_error0_);
	_tmp19_ = _tmp22_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (_tmp14_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			return NULL;
		} else {
			_g_free0 (_tmp14_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			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;
		}
	}
	_tmp23_ = _tmp19_;
	_tmp19_ = NULL;
	_g_free0 (work);
	work = _tmp23_;
	_tmp25_ = dc_markdown_italic2_re;
	_tmp26_ = work;
	_tmp27_ = g_regex_replace (_tmp25_, _tmp26_, (gssize) -1, 0, "<i>\\1</i>", 0, &_inner_error0_);
	_tmp24_ = _tmp27_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (_tmp19_);
			_g_free0 (_tmp14_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			return NULL;
		} else {
			_g_free0 (_tmp19_);
			_g_free0 (_tmp14_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			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;
		}
	}
	_tmp28_ = _tmp24_;
	_tmp24_ = NULL;
	_g_free0 (work);
	work = _tmp28_;
	_tmp30_ = dc_markdown_strike_re;
	_tmp31_ = work;
	_tmp32_ = g_regex_replace (_tmp30_, _tmp31_, (gssize) -1, 0, "<s>\\1</s>", 0, &_inner_error0_);
	_tmp29_ = _tmp32_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (_tmp24_);
			_g_free0 (_tmp19_);
			_g_free0 (_tmp14_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			return NULL;
		} else {
			_g_free0 (_tmp24_);
			_g_free0 (_tmp19_);
			_g_free0 (_tmp14_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			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;
		}
	}
	_tmp33_ = _tmp29_;
	_tmp29_ = NULL;
	_g_free0 (work);
	work = _tmp33_;
	_tmp35_ = dc_markdown_heading_re;
	_tmp36_ = work;
	_tmp37_ = g_regex_replace_eval (_tmp35_, _tmp36_, (gssize) -1, 0, 0, ___lambda7__gregex_eval_callback, NULL, &_inner_error0_);
	_tmp34_ = _tmp37_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (_tmp29_);
			_g_free0 (_tmp24_);
			_g_free0 (_tmp19_);
			_g_free0 (_tmp14_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			return NULL;
		} else {
			_g_free0 (_tmp29_);
			_g_free0 (_tmp24_);
			_g_free0 (_tmp19_);
			_g_free0 (_tmp14_);
			_g_free0 (_tmp8_);
			_g_free0 (_tmp2_);
			_g_free0 (work);
			_g_ptr_array_unref0 (segments);
			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;
		}
	}
	_tmp38_ = _tmp34_;
	_tmp34_ = NULL;
	_g_free0 (work);
	work = _tmp38_;
	_tmp39_ = work;
	_tmp40_ = dc_markdown_linkify (_tmp39_);
	_g_free0 (work);
	work = _tmp40_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp41_ = FALSE;
			_tmp41_ = TRUE;
			while (TRUE) {
				GPtrArray* _tmp43_;
				gint _tmp44_;
				gint _tmp45_;
				const gchar* _tmp46_;
				gchar* _tmp47_;
				gchar* _tmp48_;
				GPtrArray* _tmp49_;
				gconstpointer _tmp50_;
				gchar* _tmp51_;
				if (!_tmp41_) {
					gint _tmp42_;
					_tmp42_ = i;
					i = _tmp42_ + 1;
				}
				_tmp41_ = FALSE;
				_tmp43_ = segments;
				_tmp44_ = vala_g_ptr_array_get_length (_tmp43_);
				_tmp45_ = _tmp44_;
				if (!(i < _tmp45_)) {
					break;
				}
				_tmp46_ = work;
				_tmp47_ = g_strdup_printf ("\x01%d\x01", i);
				_tmp48_ = _tmp47_;
				_tmp49_ = segments;
				_tmp50_ = g_ptr_array_index (_tmp49_, (guint) i);
				_tmp51_ = string_replace (_tmp46_, _tmp48_, (const gchar*) _tmp50_);
				_g_free0 (work);
				work = _tmp51_;
				_g_free0 (_tmp48_);
			}
		}
	}
	result = work;
	_g_free0 (_tmp34_);
	_g_free0 (_tmp29_);
	_g_free0 (_tmp24_);
	_g_free0 (_tmp19_);
	_g_free0 (_tmp14_);
	_g_free0 (_tmp8_);
	_g_free0 (_tmp2_);
	_g_ptr_array_unref0 (segments);
	return result;
}

/**
         * Replace regex matches with numbered placeholders, storing the
         * matched content wrapped in <tt> tags for later restoration.
         */
static gpointer
_g_ptr_array_ref0 (gpointer self)
{
	return self ? g_ptr_array_ref (self) : NULL;
}

static Block16Data*
block16_data_ref (Block16Data* _data16_)
{
	g_atomic_int_inc (&_data16_->_ref_count_);
	return _data16_;
}

static void
block16_data_unref (void * _userdata_)
{
	Block16Data* _data16_;
	_data16_ = (Block16Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data16_->_ref_count_)) {
		_g_ptr_array_unref0 (_data16_->segments);
		g_slice_free (Block16Data, _data16_);
	}
}

static gboolean
__lambda6_ (Block16Data* _data16_,
            GMatchInfo* mi,
            GString* sb)
{
	gint idx = 0;
	gint _tmp0_;
	gint _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gboolean result;
	g_return_val_if_fail (mi != NULL, FALSE);
	g_return_val_if_fail (sb != NULL, FALSE);
	_tmp0_ = vala_g_ptr_array_get_length (_data16_->segments);
	_tmp1_ = _tmp0_;
	idx = (gint) _tmp1_;
	_tmp2_ = g_match_info_fetch (mi, 1);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat ("<tt>", _tmp3_, NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strconcat (_tmp5_, "</tt>", NULL);
	g_ptr_array_add (_data16_->segments, _tmp6_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_tmp7_ = g_strdup_printf ("\x01%d\x01", idx);
	_tmp8_ = _tmp7_;
	g_string_append (sb, _tmp8_);
	_g_free0 (_tmp8_);
	result = FALSE;
	return result;
}

static gboolean
___lambda6__gregex_eval_callback (GMatchInfo* match_info,
                                  GString* _result_,
                                  gpointer self)
{
	gboolean result;
	result = __lambda6_ (self, match_info, _result_);
	return result;
}

static gchar*
dc_markdown_extract_code (GRegex* re,
                          const gchar* input,
                          GPtrArray* segments,
                          GError** error)
{
	Block16Data* _data16_;
	GPtrArray* _tmp0_;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (re != NULL, NULL);
	g_return_val_if_fail (input != NULL, NULL);
	g_return_val_if_fail (segments != NULL, NULL);
	_data16_ = g_slice_new0 (Block16Data);
	_data16_->_ref_count_ = 1;
	_tmp0_ = _g_ptr_array_ref0 (segments);
	_g_ptr_array_unref0 (_data16_->segments);
	_data16_->segments = _tmp0_;
	_tmp2_ = g_regex_replace_eval (re, input, (gssize) -1, 0, 0, ___lambda6__gregex_eval_callback, _data16_, &_inner_error0_);
	_tmp1_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == G_REGEX_ERROR) {
			g_propagate_error (error, _inner_error0_);
			block16_data_unref (_data16_);
			_data16_ = NULL;
			return NULL;
		} else {
			block16_data_unref (_data16_);
			_data16_ = 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 NULL;
		}
	}
	_tmp3_ = _tmp1_;
	_tmp1_ = NULL;
	result = _tmp3_;
	_g_free0 (_tmp1_);
	block16_data_unref (_data16_);
	_data16_ = NULL;
	return result;
}

static gboolean
___lambda5_ (GMatchInfo* mi,
             GString* sb)
{
	gchar* url = NULL;
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (mi != NULL, FALSE);
	g_return_val_if_fail (sb != NULL, FALSE);
	_tmp0_ = g_match_info_fetch (mi, 0);
	url = _tmp0_;
	g_string_append (sb, "<a href=\"");
	g_string_append (sb, url);
	g_string_append (sb, "\"><span foreground=\"#1c71d8\" underline=\"single\">");
	g_string_append (sb, url);
	g_string_append (sb, "</span></a>");
	result = FALSE;
	_g_free0 (url);
	return result;
}

static gboolean
____lambda5__gregex_eval_callback (GMatchInfo* match_info,
                                   GString* _result_,
                                   gpointer self)
{
	gboolean result;
	result = ___lambda5_ (match_info, _result_);
	return result;
}

static gchar*
dc_markdown_linkify (const gchar* escaped)
{
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (escaped != NULL, NULL);
	{
		gchar* _tmp0_ = NULL;
		GRegex* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		dc_markdown_ensure_regexes (&_inner_error0_);
		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;
		}
		_tmp1_ = dc_markdown_link_re;
		_tmp2_ = g_regex_replace_eval (_tmp1_, escaped, (gssize) -1, 0, 0, ____lambda5__gregex_eval_callback, NULL, &_inner_error0_);
		_tmp0_ = _tmp2_;
		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;
		}
		_tmp3_ = _tmp0_;
		_tmp0_ = NULL;
		result = _tmp3_;
		_g_free0 (_tmp0_);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		gchar* _tmp4_;
		g_clear_error (&_inner_error0_);
		_tmp4_ = g_strdup (escaped);
		result = _tmp4_;
		return result;
	}
	__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;
}

DcMarkdown*
dc_markdown_construct (GType object_type)
{
	DcMarkdown* self = NULL;
	self = (DcMarkdown*) g_type_create_instance (object_type);
	return self;
}

DcMarkdown*
dc_markdown_new (void)
{
	return dc_markdown_construct (DC_TYPE_MARKDOWN);
}

static void
dc_value_markdown_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
dc_value_markdown_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		dc_markdown_unref (value->data[0].v_pointer);
	}
}

static void
dc_value_markdown_copy_value (const GValue* src_value,
                              GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = dc_markdown_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
dc_value_markdown_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
dc_value_markdown_collect_value (GValue* value,
                                 guint n_collect_values,
                                 GTypeCValue* collect_values,
                                 guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		DcMarkdown * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = dc_markdown_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
dc_value_markdown_lcopy_value (const GValue* value,
                               guint n_collect_values,
                               GTypeCValue* collect_values,
                               guint collect_flags)
{
	DcMarkdown ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = dc_markdown_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
dc_param_spec_markdown (const gchar* name,
                        const gchar* nick,
                        const gchar* blurb,
                        GType object_type,
                        GParamFlags flags)
{
	DcParamSpecMarkdown* spec;
	g_return_val_if_fail (g_type_is_a (object_type, DC_TYPE_MARKDOWN), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
dc_value_get_markdown (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_MARKDOWN), NULL);
	return value->data[0].v_pointer;
}

void
dc_value_set_markdown (GValue* value,
                       gpointer v_object)
{
	DcMarkdown * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_MARKDOWN));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_TYPE_MARKDOWN));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		dc_markdown_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_markdown_unref (old);
	}
}

void
dc_value_take_markdown (GValue* value,
                        gpointer v_object)
{
	DcMarkdown * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DC_TYPE_MARKDOWN));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DC_TYPE_MARKDOWN));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dc_markdown_unref (old);
	}
}

static void
dc_markdown_class_init (DcMarkdownClass * klass,
                        gpointer klass_data)
{
	dc_markdown_parent_class = g_type_class_peek_parent (klass);
	((DcMarkdownClass *) klass)->finalize = dc_markdown_finalize;
}

static void
dc_markdown_instance_init (DcMarkdown * self,
                           gpointer klass)
{
	self->ref_count = 1;
}

static void
dc_markdown_finalize (DcMarkdown * obj)
{
	DcMarkdown * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_MARKDOWN, DcMarkdown);
	g_signal_handlers_destroy (self);
}

/**
     * Converts markdown-formatted text to Pango markup for GTK labels.
     * Supports: bold, italic, strikethrough, inline code, code blocks,
     * headings, and URL linkification.
     */
static GType
dc_markdown_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dc_value_markdown_init, dc_value_markdown_free_value, dc_value_markdown_copy_value, dc_value_markdown_peek_pointer, "p", dc_value_markdown_collect_value, "p", dc_value_markdown_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DcMarkdownClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_markdown_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcMarkdown), 0, (GInstanceInitFunc) dc_markdown_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType dc_markdown_type_id;
	dc_markdown_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DcMarkdown", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return dc_markdown_type_id;
}

GType
dc_markdown_get_type (void)
{
	static volatile gsize dc_markdown_type_id__once = 0;
	if (g_once_init_enter (&dc_markdown_type_id__once)) {
		GType dc_markdown_type_id;
		dc_markdown_type_id = dc_markdown_get_type_once ();
		g_once_init_leave (&dc_markdown_type_id__once, dc_markdown_type_id);
	}
	return dc_markdown_type_id__once;
}

gpointer
dc_markdown_ref (gpointer instance)
{
	DcMarkdown * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
dc_markdown_unref (gpointer instance)
{
	DcMarkdown * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DC_MARKDOWN_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

