Markdown Textarea
Style-agnostic textarea with markdown preview toggle.
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.previewmy_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
| Name | Type | Default | Description |
|---|---|---|---|
| name | str | 'content' | Form field name |
| value | str | '' | Current textarea content |
| preview | bool | False | Whether preview mode is active (default: False) |
| toggle_event | str — renames the event | 'toggle_preview' | djust event to toggle preview mode |
| placeholder | str | 'Write markdown here...' | Placeholder text |
| rows | int | 6 | Number of textarea rows (default: 6) |
| disabled | bool | False | Whether the textarea is disabled |
| custom_class | str | '' | Additional CSS classes |
| **kwargs | — passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state | — | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.markdown_textarea | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 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. |