diff --git a/djblets/util/templatetags/djblets_email.py b/djblets/util/templatetags/djblets_email.py
index 0a2337e8138611cd4ba7bf96bb45fb4d1881508f..4578628b1fbf99b7e2d191c66db3830c6002dc89 100644
--- a/djblets/util/templatetags/djblets_email.py
+++ b/djblets/util/templatetags/djblets_email.py
@@ -46,13 +46,15 @@ def quoted_email(context, template_name):
 
 @register.tag
 @blocktag
-def condense(context, nodelist):
-    """
-    Condenses a block of text so that there are never more than three
-    consecutive newlines.
+def condense(context, nodelist, max_newlines=3):
+    """Condenses a block of text.
+
+    This will ensure that there are never more than the given number of
+    consecutive newlines. It's particularly useful when formatting plain text
+    output, to avoid issues with template tags adding unwanted newlines.
     """
     text = nodelist.render(context).strip()
-    text = re.sub("\n{4,}", "\n\n\n", text)
+    text = re.sub(r'\n{%d,}' % (max_newlines + 1), '\n' * max_newlines, text)
     return text
 
 
diff --git a/djblets/util/tests.py b/djblets/util/tests.py
index 7f5d71157425cfaf61a0a3219535fdf5aa4d1908..1e3417c9e0483a96ea25441f1f0ffedc37acd523 100644
--- a/djblets/util/tests.py
+++ b/djblets/util/tests.py
@@ -329,12 +329,18 @@ class CondenseTagTest(TagTest):
     def getContentText(self):
         return "foo\nbar\n\n\n\n\n\n\nfoobar!"
 
-    def testPlain(self):
+    def test_plain(self):
         """Testing condense tag"""
         node = djblets_email.condense(self.parser,
                                       Token(TOKEN_TEXT, 'condense'))
         self.assertEqual(node.render({}), "foo\nbar\n\n\nfoobar!")
 
+    def test_with_max_indents(self):
+        """Testing condense tag with custom max_indents"""
+        node = djblets_email.condense(self.parser,
+                                      Token(TOKEN_TEXT, 'condense 1'))
+        self.assertEqual(node.render({}), "foo\nbar\nfoobar!")
+
 
 class QuoteTextFilterTest(unittest.TestCase):
     def testPlain(self):
