diff --git a/backends/markup-tree.c b/backends/markup-tree.c
index 4857cae..fc508dd 100644
--- a/backends/markup-tree.c
+++ b/backends/markup-tree.c
@@ -255,6 +255,13 @@ struct _MarkupDir
   guint is_dir_empty : 1;
 };
 
+static gint
+compare_markupdirs (MarkupDir *a,
+                    MarkupDir *b)
+{
+  return strcmp(a->name, b->name);
+}
+
 static MarkupDir*
 markup_dir_new (MarkupTree *tree,
                 MarkupDir  *parent,
@@ -271,7 +278,9 @@ markup_dir_new (MarkupTree *tree,
   if (parent)
     {
       dir->subtree_root = parent->subtree_root;
-      parent->subdirs = g_slist_prepend (parent->subdirs, dir);
+      parent->subdirs = g_slist_insert_sorted (parent->subdirs,
+                                               dir,
+                                               (GCompareFunc)compare_markupdirs);
     }
   else
     {
