Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
22 changes: 11 additions & 11 deletions tests/test_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -47,12 +47,11 @@
<p><br /></p>"""

MARKED_DOWN_NOT_HILITE = """
<p>@@ json @@
<p><code>json
[{
"alpha": 1,
"beta: "this is a string"
}]
@@</p>"""
}]</code></p>"""

# We support markdown < 2.1 and markdown >= 2.1
MARKED_DOWN_lt_21 = """<h2>an example docstring</h2>
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down