Skip to content
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

How to render markdown without preview? #18

Closed
will-emmerson opened this issue Feb 26, 2014 · 7 comments
Closed

How to render markdown without preview? #18

will-emmerson opened this issue Feb 26, 2014 · 7 comments

Comments

@will-emmerson
Copy link

I just want to render the markdown to html in a template, without the preview.

@timmyomahony
Copy link
Owner

I presume you mean you don't want to see the preview when writing your markdown in the django admin or elsewhere? You could simply hide the preview via css:

.wmd-preview{
    display: none;
}

but there is no built in way to ommit the preview div

@will-emmerson
Copy link
Author

No, I want to see the preview in the admin and allow editing via the admin, but on other pages I just want the rendered html without the preview. Django 1.5 had a markdown template tag but 1.6 doesn't, I'm just wondering if pagedown includes any.

@wckd
Copy link

wckd commented Mar 13, 2014

@will-emmerson You can install the django-markdown-deux package, add 'markdown_deux' to INSTALLED_APPS and put {% load markdown_deux_tags %} in the head of your template.
You can then apply the markdown-filter on the variable that holds the markdown-content.

Heres an example:

{% extends 'base.html' %}
{% load markdown_deux_tags %}

{% block content %}
    <div class="blog-post">
        <h2 class="blog-post-title">{{ entry.title }}</h2>
        <p class="blog-post-meta">{{ entry.created }} by {{ entry.author.first_name }}</p>
        {{ entry.body|markdown }}
    </div>
    {% if user.is_superuser %}
        <a href="{% url 'entry_update' slug=entry.slug %}" role="button" class="btn btn-primary"> Edit</a>
    {% endif %}
{% endblock %

@timmyomahony
Copy link
Owner

I will add this to the README

@timmyomahony
Copy link
Owner

I've added a section at the bottom of the README addressing this, so hopefully it is clearer now:

https://github.com/timmyomahony/django-pagedown/blob/master/README.md#rendering-markdown-in-your-template

@hitarths
Copy link

There is a difference between the django-pagedown preview and the html generated by the django-markdown-deux. Specifically the preview from pagedown shows line breaks when I press enter, but when I render it using the deux tag, the line breaks are gone. BUT, it I put two line breaks, then deux DOES puts
tags.
I am not sure if its a bug in pagedown, or its just the fact that I am silly!

@timmyomahony
Copy link
Owner

timmyomahony commented Feb 25, 2019

@hitarths that's interesting, I haven't noticed that before. The django-markdown-deux library uses python-markdown2 behind the scenes. python-markdown2 allows configuration via "Extras". I notice a break-on-newline option there. Something like this might work (I haven't tested it though):

MARKDOWN_DEUX_STYLES = {
    "default": {
        "extras": {
            "break-on-newline": None,
        },
        # ...
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants