Markdown Editor
Split-pane markdown editor with live preview.
Preview
Usage
views.py
python
from djust import LiveView
from djust.components import MarkdownEditor
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = MarkdownEditor()my_template.html
django
{{ component }}Needs its script on the page: <script src="{% static 'djust_components/markdown-editor.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 | '' | initial markdown content |
| preview | bool | True | show preview pane (default True) |
| toolbar | bool | True | show formatting toolbar (default True) |
| placeholder | str | 'Write markdown...' | textarea placeholder text |
| rows | int | 12 | textarea rows |
| disabled | bool | False | disable editing |
| event | str — renames the event | '' | djust event on change |
| custom_class | str | '' | additional CSS classes |
| mode | str | 'markdown' | initial editing mode; visual requires the optional visual bundle |
| bubble_menu | bool | True | show a formatting menu over a selection in visual mode (default True). It never replaces the browser's context menu. |
| floating_menu | bool | False | show a block menu on an empty line in visual mode (default False) |
| **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_editor | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 8 of this component's classes at line 2139, 2141, 2142, 2144, 2145, 2146, 2147, 2682. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_components/markdown-editor.css | Defines 5 of this component's classes at line 275, 279, 282, 283, 297. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |