diff --git a/tableofcontents.pages.inc b/tableofcontents.pages.inc
index 55550fa..b0155c1 100644
--- a/tableofcontents.pages.inc
+++ b/tableofcontents.pages.inc
@@ -613,6 +613,9 @@ function _tableofcontents_comments(&$toc, $format) {
  * @return The $text with the [toc ...] replaced.
  */
 function _tableofcontents_replace_toc($text, $format, $filter) {
+  if (is_object($format)) {
+    $format = $format->format;
+  }
   // we just don't have a way to pass that around our callbacks
   // (PHP is lacking on that one) but it is still a lot faster
   // that way.
