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

NameTypeDefaultDescription
namestr'content'Form field name
valuestr''Current textarea content
previewboolFalseWhether preview mode is active (default: False)
toggle_eventstr — renames the event'toggle_preview'djust event to toggle preview mode
placeholderstr'Write markdown here...'Placeholder text
rowsint6Number of textarea rows (default: 6)
disabledboolFalseWhether the textarea is disabled
custom_classstr''Additional CSS classes
**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 1771, 1772, 1773, 1775, 1776. Override those rules, or the custom properties they read, in a stylesheet loaded after it.