Django markdown show_preview feature throws an error

Viewed 343

I am new using markdown. I tried to use the show_preview = False to implement preview using jQuery instead.

class PostForm(forms.ModelForm):
    content = forms.CharField(widget=PagedownWidget(show_preview=False)) 
    publish = forms.DateField(widget = forms.SelectDateWidget)
    class Meta:
        model = Post
        fields = [
            "title",
            "content",
            "image",
            "draft",
            "publish",
        ]

unfortunately, it throws an error:

line 9, in PostForm
content = forms.CharField(widget=PagedownWidget(show_preview=False))
TypeError: __init__() got an unexpected keyword argument 'show_preview'

I did look into the markdown files and could not find show_preview using except here:

4          <textarea {{ attrs|safe }}>{{ body }}</textarea>
5      </div>
6      {% if show_preview %}
7      <p class="wmd-preview-title">
8          <small>HTML Preview:</small>

I am running:

Django==2.2.6
django-markdown-deux==1.0.5
django-pagedown==2.0.3
1 Answers

Are you following a guide? Django-pagedown widget used to take a number of arguments (including show_preview). Use version 1.0.6 if you want to do that. v1.0.6 is still compatible with django2.2.x.

Since v2.0.0 it is better to subclass the widget and point it to the template / css to define the preview box, see the docs for that:

Github (see the readme)

Example app with form

You can stop the preview showing by overwriting the CSS. eg, add the following to your .css file in the static folder (and ensure it is being imported into your template). Or just stick it in a style tag at the top of your template.

.wmd-preview{
    display: none;
}
Related