Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
bda16a51
Commit
bda16a51
authored
Aug 02, 2016
by
Tom Christie
Committed by
GitHub
Aug 02, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dedent tabs. (#4347)
parent
9f5e841d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
rest_framework/utils/formatting.py
+11
-2
tests/test_description.py
+5
-0
No files found.
rest_framework/utils/formatting.py
View file @
bda16a51
...
...
@@ -32,13 +32,22 @@ def dedent(content):
unindented text on the initial line.
"""
content
=
force_text
(
content
)
whitespace_counts
=
[
len
(
line
)
-
len
(
line
.
lstrip
(
' '
))
for
line
in
content
.
splitlines
()[
1
:]
if
line
.
lstrip
()]
whitespace_counts
=
[
len
(
line
)
-
len
(
line
.
lstrip
(
' '
))
for
line
in
content
.
splitlines
()[
1
:]
if
line
.
lstrip
()
]
tab_counts
=
[
len
(
line
)
-
len
(
line
.
lstrip
(
'
\t
'
))
for
line
in
content
.
splitlines
()[
1
:]
if
line
.
lstrip
()
]
# unindent the content if needed
if
whitespace_counts
:
whitespace_pattern
=
'^'
+
(
' '
*
min
(
whitespace_counts
))
content
=
re
.
sub
(
re
.
compile
(
whitespace_pattern
,
re
.
MULTILINE
),
''
,
content
)
elif
tab_counts
:
whitespace_pattern
=
'^'
+
(
'
\t
'
*
min
(
whitespace_counts
))
content
=
re
.
sub
(
re
.
compile
(
whitespace_pattern
,
re
.
MULTILINE
),
''
,
content
)
return
content
.
strip
()
...
...
tests/test_description.py
View file @
bda16a51
...
...
@@ -6,6 +6,7 @@ from django.test import TestCase
from
django.utils.encoding
import
python_2_unicode_compatible
from
rest_framework.compat
import
apply_markdown
from
rest_framework.utils.formatting
import
dedent
from
rest_framework.views
import
APIView
...
...
@@ -120,3 +121,7 @@ class TestViewNamesAndDescriptions(TestCase):
gte_21_match
=
apply_markdown
(
DESCRIPTION
)
==
MARKED_DOWN_gte_21
lt_21_match
=
apply_markdown
(
DESCRIPTION
)
==
MARKED_DOWN_lt_21
self
.
assertTrue
(
gte_21_match
or
lt_21_match
)
def
test_dedent_tabs
():
assert
dedent
(
"
\t
first string
\n\n\t
second string"
)
==
'first string
\n\n\t
second string'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment