diff --git a/CHANGES.md b/CHANGES.md
index 9c89ac91..a24d33d0 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -4,6 +4,7 @@
- [pull #519] Add support for custom extras
- [pull #519] Drop Python 3.5 support
+- [pull #568] Add `prepend` arg to toc extra (#397)
- [pull #570] Fix syntax warnings in test suite
diff --git a/lib/markdown2.py b/lib/markdown2.py
index 3a1db281..01252ff8 100755
--- a/lib/markdown2.py
+++ b/lib/markdown2.py
@@ -513,7 +513,7 @@ def toc_sort(entry):
self._toc_html = calculate_toc_html(self._toc)
# Prepend toc html to output
- if self.cli:
+ if self.cli or (self.extras['toc'] is not None and self.extras['toc'].get('prepend', False)):
text = '{}\n{}'.format(self._toc_html, text)
text += "\n"
diff --git a/test/tm-cases/toc_prepend.html b/test/tm-cases/toc_prepend.html
new file mode 100644
index 00000000..7aa0a0e5
--- /dev/null
+++ b/test/tm-cases/toc_prepend.html
@@ -0,0 +1,40 @@
+
+
+README for Blah
+
+Introduction
+
+The Meat
+
+Beef
+
+Steak
+
+Burgers
+
+Chicken
+
+Pork
+
+Mmmmmmmm, bacon
+
+At the top level again!?
diff --git a/test/tm-cases/toc_prepend.opts b/test/tm-cases/toc_prepend.opts
new file mode 100644
index 00000000..261151cd
--- /dev/null
+++ b/test/tm-cases/toc_prepend.opts
@@ -0,0 +1 @@
+{"extras": {"toc": {"prepend": True}}}
diff --git a/test/tm-cases/toc_prepend.tags b/test/tm-cases/toc_prepend.tags
new file mode 100644
index 00000000..2b2472e0
--- /dev/null
+++ b/test/tm-cases/toc_prepend.tags
@@ -0,0 +1 @@
+toc extra
diff --git a/test/tm-cases/toc_prepend.text b/test/tm-cases/toc_prepend.text
new file mode 100644
index 00000000..34f629a6
--- /dev/null
+++ b/test/tm-cases/toc_prepend.text
@@ -0,0 +1,20 @@
+# README for Blah
+
+## Introduction
+
+## The Meat
+
+### Beef
+
+##### Steak
+
+##### Burgers
+
+### Chicken
+
+### Pork
+
+#### Mmmmmmmm, bacon
+
+# At the *top* level again!?
+
diff --git a/test/tm-cases/toc_prepend.toc_html b/test/tm-cases/toc_prepend.toc_html
new file mode 100644
index 00000000..08288703
--- /dev/null
+++ b/test/tm-cases/toc_prepend.toc_html
@@ -0,0 +1,20 @@
+