From 86682d47644674558d8d21acf7b4e27a3f766775 Mon Sep 17 00:00:00 2001 From: Matteo Nastasi Date: Thu, 19 Oct 2017 16:25:00 +0200 Subject: [PATCH 1/3] substitute '@@' code block delimiter with triple back-tick, more consistent with other markdown extensions --- rest_framework/compat.py | 2 +- tests/test_description.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index a085187aaf..239ef3def9 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..3e9034344b 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,12 @@


""" 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,13 +105,14 @@ class MockView(APIView): # hash style header # - @@ json @@ + ``` json [{ "alpha": 1, "beta: "this is a string" }] - @@""" + ```""" + print("MOCK:\n[%s]" % MockView().get_view_description()) assert MockView().get_view_description() == DESCRIPTION def test_view_description_can_be_empty(self): From b7657be31cf553a9cf6852fce6630ea3ec1d4413 Mon Sep 17 00:00:00 2001 From: Matteo Nastasi Date: Thu, 19 Oct 2017 16:33:49 +0200 Subject: [PATCH 2/3] remove development print and allow spaces between triple backtick and syntax name in codeblock --- rest_framework/compat.py | 2 +- tests/test_description.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 239ef3def9..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*``` ([^\n]+)\n(.+?)^\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 3e9034344b..4804168ab7 100644 --- a/tests/test_description.py +++ b/tests/test_description.py @@ -112,7 +112,6 @@ class MockView(APIView): }] ```""" - print("MOCK:\n[%s]" % MockView().get_view_description()) assert MockView().get_view_description() == DESCRIPTION def test_view_description_can_be_empty(self): From 07a906089ba174f19b6dca5abe954558a5a1c499 Mon Sep 17 00:00:00 2001 From: Matteo Nastasi Date: Fri, 20 Oct 2017 10:03:14 +0200 Subject: [PATCH 3/3] update comparison content for markdown test --- tests/test_description.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_description.py b/tests/test_description.py index 4804168ab7..b3e8b0f8bd 100644 --- a/tests/test_description.py +++ b/tests/test_description.py @@ -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

@@ -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