Skip to content

Commit 9ec81e3

Browse files
nastasi-oqcarltongibson
authored andcommitted
substitute '@@' code block delimiter with triple backtick, more con… (#5513)
* substitute '@@' code block delimiter with triple back-tick, more consistent with other markdown extensions * remove development print and allow spaces between triple backtick and syntax name in codeblock * update comparison content for markdown test
1 parent 22a71a6 commit 9ec81e3

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

rest_framework/compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def pygments_css(style):
244244

245245
class CodeBlockPreprocessor(Preprocessor):
246246
pattern = re.compile(
247-
r'^\s*@@ (.+?) @@\s*(.+?)^\s*@@', re.M|re.S)
247+
r'^\s*``` *([^\n]+)\n(.+?)^\s*```', re.M|re.S)
248248

249249
formatter = HtmlFormatter()
250250

tests/test_description.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
2727
# hash style header #
2828
29-
@@ json @@
29+
``` json
3030
[{
3131
"alpha": 1,
3232
"beta: "this is a string"
3333
}]
34-
@@"""
34+
```"""
3535

3636
# If markdown is installed we also test it's working
3737
# (and that our wrapped forces '=' to h2 and '-' to h3)
@@ -47,12 +47,11 @@
4747
<p><br /></p>"""
4848

4949
MARKED_DOWN_NOT_HILITE = """
50-
<p>@@ json @@
50+
<p><code>json
5151
[{
5252
"alpha": 1,
5353
"beta: "this is a string"
54-
}]
55-
@@</p>"""
54+
}]</code></p>"""
5655

5756
# We support markdown < 2.1 and markdown >= 2.1
5857
MARKED_DOWN_lt_21 = """<h2>an example docstring</h2>
@@ -105,12 +104,12 @@ class MockView(APIView):
105104
106105
# hash style header #
107106
108-
@@ json @@
107+
``` json
109108
[{
110109
"alpha": 1,
111110
"beta: "this is a string"
112111
}]
113-
@@"""
112+
```"""
114113

115114
assert MockView().get_view_description() == DESCRIPTION
116115

@@ -150,15 +149,16 @@ def test_markdown(self):
150149
Ensure markdown to HTML works as expected.
151150
"""
152151
if apply_markdown:
152+
md_applied = apply_markdown(DESCRIPTION)
153153
gte_21_match = (
154-
apply_markdown(DESCRIPTION) == (
154+
md_applied == (
155155
MARKED_DOWN_gte_21 % MARKED_DOWN_HILITE) or
156-
apply_markdown(DESCRIPTION) == (
156+
md_applied == (
157157
MARKED_DOWN_gte_21 % MARKED_DOWN_NOT_HILITE))
158158
lt_21_match = (
159-
apply_markdown(DESCRIPTION) == (
159+
md_applied == (
160160
MARKED_DOWN_lt_21 % MARKED_DOWN_HILITE) or
161-
apply_markdown(DESCRIPTION) == (
161+
md_applied == (
162162
MARKED_DOWN_lt_21 % MARKED_DOWN_NOT_HILITE))
163163
assert gte_21_match or lt_21_match
164164

0 commit comments

Comments
 (0)