Markdown Textarea

Style-agnostic textarea with markdown preview toggle.

python 9 params

Preview

Usage

views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import MarkdownTextarea


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = MarkdownTextarea()

    @event_handler()
    def toggle_preview(self, **kwargs):
        self.component.preview = not self.component.preview
my_template.html
django
{{ component }}

Events this component sends to the view: toggle_preview.

Needs its script on the page: <script src="{% static 'djust_components/markdown-textarea.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.

Parameters

NameTypeDefault
namestr'content'
valuestr''
previewboolFalse
toggle_eventstr — renames the event'toggle_preview'
placeholderstr'Write markdown here...'
rowsint6
disabledboolFalse
custom_classstr''
**kwargs— passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state
Source & styles
FilePathNotes
moduledjust.components.components.markdown_textareaSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 5 of this component's classes at line 1744, 1745, 1746, 1748, 1749. Override those rules, or the custom properties they read, in a stylesheet loaded after it.