diff --git a/rest_framework/compat.py b/rest_framework/compat.py
index a085187aaf..ce821402e2 100644
--- a/rest_framework/compat.py
+++ b/rest_framework/compat.py
@@ -244,7 +244,7 @@ def pygments_css(style):
class CodeBlockPreprocessor(Preprocessor):
pattern = re.compile(
- r'^\s*@@ (.+?) @@\s*(.+?)^\s*@@', re.M|re.S)
+ r'^\s*``` *([^\n]+)\n(.+?)^\s*```', re.M|re.S)
formatter = HtmlFormatter()
diff --git a/tests/test_description.py b/tests/test_description.py
index a97550ed8d..b3e8b0f8bd 100644
--- a/tests/test_description.py
+++ b/tests/test_description.py
@@ -26,12 +26,12 @@
# hash style header #
-@@ json @@
+``` json
[{
"alpha": 1,
"beta: "this is a string"
}]
-@@"""
+```"""
# If markdown is installed we also test it's working
# (and that our wrapped forces '=' to h2 and '-' to h3)
@@ -47,12 +47,11 @@
"""
MARKED_DOWN_NOT_HILITE = """
-@@ json @@
+
json
[{
"alpha": 1,
"beta: "this is a string"
-}]
-@@
"""
+}]"""
# We support markdown < 2.1 and markdown >= 2.1
MARKED_DOWN_lt_21 = """an example docstring
@@ -105,12 +104,12 @@ class MockView(APIView):
# hash style header #
- @@ json @@
+ ``` json
[{
"alpha": 1,
"beta: "this is a string"
}]
- @@"""
+ ```"""
assert MockView().get_view_description() == DESCRIPTION
@@ -150,15 +149,16 @@ def test_markdown(self):
Ensure markdown to HTML works as expected.
"""
if apply_markdown:
+ md_applied = apply_markdown(DESCRIPTION)
gte_21_match = (
- apply_markdown(DESCRIPTION) == (
+ md_applied == (
MARKED_DOWN_gte_21 % MARKED_DOWN_HILITE) or
- apply_markdown(DESCRIPTION) == (
+ md_applied == (
MARKED_DOWN_gte_21 % MARKED_DOWN_NOT_HILITE))
lt_21_match = (
- apply_markdown(DESCRIPTION) == (
+ md_applied == (
MARKED_DOWN_lt_21 % MARKED_DOWN_HILITE) or
- apply_markdown(DESCRIPTION) == (
+ md_applied == (
MARKED_DOWN_lt_21 % MARKED_DOWN_NOT_HILITE))
assert gte_21_match or lt_21_match