Skip to content

Added markdown support for endpoint docstrings #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ djangorestframework==3.3.2
coverage==4.0.3
flake8==2.5.1
mkdocs==0.15.3
django-markwhat==1.5
docutils==0.12
3 changes: 3 additions & 0 deletions rest_framework_docs/templates/rest_framework_docs/home.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% extends "rest_framework_docs/docs.html" %}
{% load drfdocs_filters %}

{% load markdown %}

{% block apps_menu %}
{% regroup endpoints by name_parent as endpoints_grouped %}
<li class="dropdown">
Expand Down Expand Up @@ -57,6 +59,7 @@ <h4 class="panel-title title">
<div id="{{ endpoint.path|slugify }}" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body">
{% if endpoint.docstring %}
<p class="lead">{{ endpoint.docstring|markdown:'safe' }}</p>
<p class="lead">{{ endpoint.docstring|markdown }}</p>
{% endif %}

Expand Down
14 changes: 14 additions & 0 deletions rest_framework_docs/templatetags/markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Defining a custom template tag as a wrapper around the markup template tag provided by the
django-markwhat library. This prevents the need for users to have to install django-markwhat into their
INSTALLED_APPS.
"""
from django import template
from django_markwhat.templatetags.markup import markdown as markdown_filter

register = template.Library()


@register.filter(is_safe=True)
def markdown(value, args=''):
return markdown_filter(value, args)