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 |
|---|---|---|
| name | str | 'content' |
| value | str | '' |
| preview | bool | False |
| toggle_event | str — renames the event | 'toggle_preview' |
| placeholder | str | 'Write markdown here...' |
| rows | int | 6 |
| disabled | bool | False |
| custom_class | str | '' |
| **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 1744, 1745, 1746, 1748, 1749. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |