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
8162303b
Commit
8162303b
authored
Dec 21, 2011
by
Marko Tibold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'alazaro-master'
parents
443694eb
90ddec03
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
17 deletions
+39
-17
djangorestframework/compat.py
+20
-14
djangorestframework/tests/description.py
+19
-3
No files found.
djangorestframework/compat.py
View file @
8162303b
...
@@ -374,21 +374,22 @@ else:
...
@@ -374,21 +374,22 @@ else:
# Markdown is optional
# Markdown is optional
try
:
try
:
import
markdown
import
markdown
import
re
class
CustomSetextHeaderProcessor
(
markdown
.
blockprocessors
.
BlockProcessor
):
class
CustomSetextHeaderProcessor
(
markdown
.
blockprocessors
.
BlockProcessor
):
"""
"""
Override `markdown`'s :class:`SetextHeaderProcessor`, so that ==== headers are <h2> and ---- headers are <h3>.
Class for markdown < 2.1
Override `markdown`'s :class:`SetextHeaderProcessor`, so that ==== headers are <h2> and ---- heade
We use <h1> for the resource name.
We use <h1> for the resource name.
"""
"""
import
re
# Detect Setext-style header. Must be first 2 lines of block.
# Detect Setext-style header. Must be first 2 lines of block.
RE
=
re
.
compile
(
r'^.*?\n[=-]{3,}'
,
re
.
MULTILINE
)
RE
=
re
.
compile
(
r'^.*?\n[=-]{3,}'
,
re
.
MULTILINE
)
def
test
(
self
,
parent
,
block
):
def
test
(
self
,
parent
,
block
):
return
bool
(
self
.
RE
.
match
(
block
))
return
bool
(
self
.
RE
.
match
(
block
))
def
run
(
self
,
parent
,
blocks
):
def
run
(
self
,
parent
,
blocks
):
lines
=
blocks
.
pop
(
0
)
.
split
(
'
\n
'
)
lines
=
blocks
.
pop
(
0
)
.
split
(
'
\n
'
)
# Determine level. ``=`` is 1 and ``-`` is 2.
# Determine level. ``=`` is 1 and ``-`` is 2.
...
@@ -401,21 +402,25 @@ try:
...
@@ -401,21 +402,25 @@ try:
if
len
(
lines
)
>
2
:
if
len
(
lines
)
>
2
:
# Block contains additional lines. Add to master blocks for later.
# Block contains additional lines. Add to master blocks for later.
blocks
.
insert
(
0
,
'
\n
'
.
join
(
lines
[
2
:]))
blocks
.
insert
(
0
,
'
\n
'
.
join
(
lines
[
2
:]))
def
apply_markdown
(
text
):
def
apply_markdown
(
text
):
"""
"""
Simple wrapper around :func:`markdown.markdown` to
apply our :class:`CustomSetextHeaderProcessor`,
Simple wrapper around :func:`markdown.markdown` to
set the base level
and also set the base level
of '#' style headers to <h2>.
of '#' style headers to <h2>.
"""
"""
extensions
=
[
'headerid(level=2)'
]
extensions
=
[
'headerid(level=2)'
]
safe_mode
=
False
,
safe_mode
=
False
,
output_format
=
markdown
.
DEFAULT_OUTPUT_FORMAT
md
=
markdown
.
Markdown
(
extensions
=
markdown
.
load_extensions
(
extensions
),
if
markdown
.
version
<
(
2
,
1
):
safe_mode
=
safe_mode
,
output_format
=
markdown
.
DEFAULT_OUTPUT_FORMAT
md
=
markdown
.
Markdown
(
extensions
=
markdown
.
load_extensions
(
extensions
),
safe_mode
=
safe_mode
,
output_format
=
output_format
)
output_format
=
output_format
)
md
.
parser
.
blockprocessors
[
'setextheader'
]
=
CustomSetextHeaderProcessor
(
md
.
parser
)
md
.
parser
.
blockprocessors
[
'setextheader'
]
=
CustomSetextHeaderProcessor
(
md
.
parser
)
else
:
md
=
markdown
.
Markdown
(
extensions
=
extensions
,
safe_mode
=
safe_mode
)
return
md
.
convert
(
text
)
return
md
.
convert
(
text
)
except
ImportError
:
except
ImportError
:
...
@@ -426,3 +431,4 @@ try:
...
@@ -426,3 +431,4 @@ try:
import
yaml
import
yaml
except
ImportError
:
except
ImportError
:
yaml
=
None
yaml
=
None
djangorestframework/tests/description.py
View file @
8162303b
...
@@ -19,8 +19,11 @@ indented
...
@@ -19,8 +19,11 @@ indented
# hash style header #"""
# hash style header #"""
# If markdown is installed we also test it's working (and that our wrapped forces '=' to h2 and '-' to h3)
# If markdown is installed we also test it's working
MARKED_DOWN
=
"""<h2>an example docstring</h2>
# (and that our wrapped forces '=' to h2 and '-' to h3)
# We support markdown < 2.1 and markdown >= 2.1
MARKED_DOWN_lt_21
=
"""<h2>an example docstring</h2>
<ul>
<ul>
<li>list</li>
<li>list</li>
<li>list</li>
<li>list</li>
...
@@ -31,6 +34,17 @@ MARKED_DOWN = """<h2>an example docstring</h2>
...
@@ -31,6 +34,17 @@ MARKED_DOWN = """<h2>an example docstring</h2>
<p>indented</p>
<p>indented</p>
<h2 id="hash_style_header">hash style header</h2>"""
<h2 id="hash_style_header">hash style header</h2>"""
MARKED_DOWN_gte_21
=
"""<h2 id="an-example-docstring">an example docstring</h2>
<ul>
<li>list</li>
<li>list</li>
</ul>
<h3 id="another-header">another header</h3>
<pre><code>code block
</code></pre>
<p>indented</p>
<h2 id="hash-style-header">hash style header</h2>"""
class
TestViewNamesAndDescriptions
(
TestCase
):
class
TestViewNamesAndDescriptions
(
TestCase
):
def
test_resource_name_uses_classname_by_default
(
self
):
def
test_resource_name_uses_classname_by_default
(
self
):
...
@@ -92,4 +106,6 @@ class TestViewNamesAndDescriptions(TestCase):
...
@@ -92,4 +106,6 @@ class TestViewNamesAndDescriptions(TestCase):
def
test_markdown
(
self
):
def
test_markdown
(
self
):
"""Ensure markdown to HTML works as expected"""
"""Ensure markdown to HTML works as expected"""
if
apply_markdown
:
if
apply_markdown
:
self
.
assertEquals
(
apply_markdown
(
DESCRIPTION
),
MARKED_DOWN
)
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
)
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