django-markdown-widget 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_markdown_widget-1.0.0/.claude/settings.local.json +14 -0
- django_markdown_widget-1.0.0/.github/workflows/ci-cd.yml +70 -0
- django_markdown_widget-1.0.0/.github/workflows/docs.yml +48 -0
- django_markdown_widget-1.0.0/.gitignore +143 -0
- django_markdown_widget-1.0.0/1.png +0 -0
- django_markdown_widget-1.0.0/LICENSE +21 -0
- django_markdown_widget-1.0.0/Makefile +41 -0
- django_markdown_widget-1.0.0/PKG-INFO +244 -0
- django_markdown_widget-1.0.0/README.md +222 -0
- django_markdown_widget-1.0.0/docs/changelog.md +19 -0
- django_markdown_widget-1.0.0/docs/customization/renderer.md +50 -0
- django_markdown_widget-1.0.0/docs/customization/themes.md +59 -0
- django_markdown_widget-1.0.0/docs/customization/toolbar.md +76 -0
- django_markdown_widget-1.0.0/docs/customization/upload-handler.md +42 -0
- django_markdown_widget-1.0.0/docs/development.md +90 -0
- django_markdown_widget-1.0.0/docs/getting-started/installation.md +50 -0
- django_markdown_widget-1.0.0/docs/getting-started/quickstart.md +68 -0
- django_markdown_widget-1.0.0/docs/guide/admin.md +36 -0
- django_markdown_widget-1.0.0/docs/guide/cleanup.md +68 -0
- django_markdown_widget-1.0.0/docs/guide/configuration.md +94 -0
- django_markdown_widget-1.0.0/docs/guide/templates.md +44 -0
- django_markdown_widget-1.0.0/docs/guide/widget.md +82 -0
- django_markdown_widget-1.0.0/docs/index.md +34 -0
- django_markdown_widget-1.0.0/docs/reference/api.md +149 -0
- django_markdown_widget-1.0.0/docs/reference/commands.md +48 -0
- django_markdown_widget-1.0.0/docs/reference/settings.md +49 -0
- django_markdown_widget-1.0.0/example/example_project/__init__.py +0 -0
- django_markdown_widget-1.0.0/example/example_project/settings.py +72 -0
- django_markdown_widget-1.0.0/example/example_project/urls.py +10 -0
- django_markdown_widget-1.0.0/example/example_project/wsgi.py +7 -0
- django_markdown_widget-1.0.0/example/manage.py +18 -0
- django_markdown_widget-1.0.0/example/posts/__init__.py +0 -0
- django_markdown_widget-1.0.0/example/posts/admin.py +10 -0
- django_markdown_widget-1.0.0/example/posts/forms.py +13 -0
- django_markdown_widget-1.0.0/example/posts/migrations/0001_initial.py +29 -0
- django_markdown_widget-1.0.0/example/posts/migrations/__init__.py +0 -0
- django_markdown_widget-1.0.0/example/posts/models.py +10 -0
- django_markdown_widget-1.0.0/example/posts/templates/posts/create.html +29 -0
- django_markdown_widget-1.0.0/example/posts/templates/posts/detail.html +27 -0
- django_markdown_widget-1.0.0/example/posts/templates/posts/list.html +31 -0
- django_markdown_widget-1.0.0/example/posts/urls.py +11 -0
- django_markdown_widget-1.0.0/example/posts/views.py +25 -0
- django_markdown_widget-1.0.0/mkdocs.yml +67 -0
- django_markdown_widget-1.0.0/pyproject.toml +73 -0
- django_markdown_widget-1.0.0/scripts/create_example_project.sh +119 -0
- django_markdown_widget-1.0.0/scripts/release.sh +49 -0
- django_markdown_widget-1.0.0/src/django_md_editor/__init__.py +34 -0
- django_markdown_widget-1.0.0/src/django_md_editor/admin.py +40 -0
- django_markdown_widget-1.0.0/src/django_md_editor/apps.py +7 -0
- django_markdown_widget-1.0.0/src/django_md_editor/cleanup.py +51 -0
- django_markdown_widget-1.0.0/src/django_md_editor/management/__init__.py +0 -0
- django_markdown_widget-1.0.0/src/django_md_editor/management/commands/__init__.py +0 -0
- django_markdown_widget-1.0.0/src/django_md_editor/management/commands/cleanup_markdown_media.py +83 -0
- django_markdown_widget-1.0.0/src/django_md_editor/mixins.py +54 -0
- django_markdown_widget-1.0.0/src/django_md_editor/renderers.py +31 -0
- django_markdown_widget-1.0.0/src/django_md_editor/settings.py +63 -0
- django_markdown_widget-1.0.0/src/django_md_editor/static/django_md_editor/css/editor.css +510 -0
- django_markdown_widget-1.0.0/src/django_md_editor/static/django_md_editor/js/editor.js +682 -0
- django_markdown_widget-1.0.0/src/django_md_editor/static/django_md_editor/js/marked.min.js +6 -0
- django_markdown_widget-1.0.0/src/django_md_editor/templates/django_md_editor/widget.html +50 -0
- django_markdown_widget-1.0.0/src/django_md_editor/templatetags/__init__.py +0 -0
- django_markdown_widget-1.0.0/src/django_md_editor/templatetags/md_editor.py +27 -0
- django_markdown_widget-1.0.0/src/django_md_editor/uploads.py +42 -0
- django_markdown_widget-1.0.0/src/django_md_editor/urls.py +10 -0
- django_markdown_widget-1.0.0/src/django_md_editor/views.py +79 -0
- django_markdown_widget-1.0.0/src/django_md_editor/widgets.py +52 -0
- django_markdown_widget-1.0.0/tests/__init__.py +0 -0
- django_markdown_widget-1.0.0/tests/conftest.py +7 -0
- django_markdown_widget-1.0.0/tests/django_settings.py +35 -0
- django_markdown_widget-1.0.0/tests/test_admin.py +59 -0
- django_markdown_widget-1.0.0/tests/test_cleanup.py +114 -0
- django_markdown_widget-1.0.0/tests/test_management.py +109 -0
- django_markdown_widget-1.0.0/tests/test_mixins.py +133 -0
- django_markdown_widget-1.0.0/tests/test_renderers.py +36 -0
- django_markdown_widget-1.0.0/tests/test_settings.py +62 -0
- django_markdown_widget-1.0.0/tests/test_templatetags.py +54 -0
- django_markdown_widget-1.0.0/tests/test_uploads.py +50 -0
- django_markdown_widget-1.0.0/tests/test_views.py +113 -0
- django_markdown_widget-1.0.0/tests/test_widgets.py +56 -0
- django_markdown_widget-1.0.0/tests/urls.py +5 -0
- django_markdown_widget-1.0.0/uv.lock +886 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(uv run:*)",
|
|
5
|
+
"Bash(git commit:*)",
|
|
6
|
+
"Bash(git:*)",
|
|
7
|
+
"Bash(python -m pytest tests/test_views.py -v)",
|
|
8
|
+
"Bash(python -m pytest --tb=short)",
|
|
9
|
+
"Bash(node:*)",
|
|
10
|
+
"Bash(uv build:*)",
|
|
11
|
+
"Bash(pip show:*)"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
name: CI/CD
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags:
|
|
7
|
+
- "v*"
|
|
8
|
+
pull_request:
|
|
9
|
+
branches: [main]
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
name: Test
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
20
|
+
django-version: ["5.2"]
|
|
21
|
+
include:
|
|
22
|
+
- python-version: "3.12"
|
|
23
|
+
django-version: "6.0"
|
|
24
|
+
- python-version: "3.13"
|
|
25
|
+
django-version: "6.0"
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
|
|
30
|
+
- uses: astral-sh/setup-uv@v5
|
|
31
|
+
with:
|
|
32
|
+
enable-cache: true
|
|
33
|
+
|
|
34
|
+
- name: Setup Python
|
|
35
|
+
env:
|
|
36
|
+
PYTHON_VERSION: "${{ matrix.python-version }}"
|
|
37
|
+
run: uv python install "$PYTHON_VERSION"
|
|
38
|
+
|
|
39
|
+
- name: Install dependencies
|
|
40
|
+
env:
|
|
41
|
+
DJANGO_VERSION: "${{ matrix.django-version }}"
|
|
42
|
+
run: |
|
|
43
|
+
uv sync --group dev
|
|
44
|
+
uv pip install "Django~=${DJANGO_VERSION}.0"
|
|
45
|
+
|
|
46
|
+
- name: Lint
|
|
47
|
+
run: uv run ruff check .
|
|
48
|
+
|
|
49
|
+
- name: Test
|
|
50
|
+
run: uv run pytest --cov
|
|
51
|
+
|
|
52
|
+
publish:
|
|
53
|
+
name: Publish to PyPI
|
|
54
|
+
needs: test
|
|
55
|
+
runs-on: ubuntu-latest
|
|
56
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
57
|
+
environment: pypi
|
|
58
|
+
permissions:
|
|
59
|
+
id-token: write
|
|
60
|
+
|
|
61
|
+
steps:
|
|
62
|
+
- uses: actions/checkout@v4
|
|
63
|
+
|
|
64
|
+
- uses: astral-sh/setup-uv@v5
|
|
65
|
+
|
|
66
|
+
- name: Build
|
|
67
|
+
run: uv build
|
|
68
|
+
|
|
69
|
+
- name: Publish
|
|
70
|
+
run: uv publish --trusted-publishing always
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: Deploy Docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
pages: write
|
|
11
|
+
id-token: write
|
|
12
|
+
|
|
13
|
+
concurrency:
|
|
14
|
+
group: pages
|
|
15
|
+
cancel-in-progress: true
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- uses: astral-sh/setup-uv@v5
|
|
24
|
+
with:
|
|
25
|
+
enable-cache: true
|
|
26
|
+
|
|
27
|
+
- name: Setup Python
|
|
28
|
+
run: uv python install 3.13
|
|
29
|
+
|
|
30
|
+
- name: Install docs dependencies
|
|
31
|
+
run: uv sync --group docs
|
|
32
|
+
|
|
33
|
+
- name: Build docs
|
|
34
|
+
run: uv run mkdocs build --strict
|
|
35
|
+
|
|
36
|
+
- uses: actions/upload-pages-artifact@v3
|
|
37
|
+
with:
|
|
38
|
+
path: site/
|
|
39
|
+
|
|
40
|
+
deploy:
|
|
41
|
+
needs: build
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
environment:
|
|
44
|
+
name: github-pages
|
|
45
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
46
|
+
steps:
|
|
47
|
+
- id: deployment
|
|
48
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
MANIFEST
|
|
27
|
+
|
|
28
|
+
# PyInstaller
|
|
29
|
+
# Usually these files are written by a python script from a template
|
|
30
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
.cache
|
|
44
|
+
nosetests.xml
|
|
45
|
+
coverage.xml
|
|
46
|
+
*.cover
|
|
47
|
+
.hypothesis/
|
|
48
|
+
.pytest_cache/
|
|
49
|
+
|
|
50
|
+
# Translations
|
|
51
|
+
*.mo
|
|
52
|
+
*.pot
|
|
53
|
+
|
|
54
|
+
# Django stuff:
|
|
55
|
+
*.log
|
|
56
|
+
local_settings.py
|
|
57
|
+
db.sqlite3
|
|
58
|
+
db.sqlite3-journal
|
|
59
|
+
media/
|
|
60
|
+
|
|
61
|
+
# Flask stuff:
|
|
62
|
+
instance/
|
|
63
|
+
.webassets-cache
|
|
64
|
+
|
|
65
|
+
# Scrapy stuff:
|
|
66
|
+
.scrapy
|
|
67
|
+
|
|
68
|
+
# Sphinx documentation
|
|
69
|
+
docs/_build/
|
|
70
|
+
|
|
71
|
+
# PyBuilder
|
|
72
|
+
target/
|
|
73
|
+
|
|
74
|
+
# Jupyter Notebook
|
|
75
|
+
.ipynb_checkpoints
|
|
76
|
+
|
|
77
|
+
# pyenv
|
|
78
|
+
.python-version
|
|
79
|
+
|
|
80
|
+
# celery beat schedule file
|
|
81
|
+
celerybeat-schedule
|
|
82
|
+
|
|
83
|
+
# SageMath parsed files
|
|
84
|
+
*.sage.py
|
|
85
|
+
|
|
86
|
+
# Environments
|
|
87
|
+
.env
|
|
88
|
+
.venv
|
|
89
|
+
env/
|
|
90
|
+
venv/
|
|
91
|
+
ENV/
|
|
92
|
+
env.bak/
|
|
93
|
+
venv.bak/
|
|
94
|
+
|
|
95
|
+
# Spyder project settings
|
|
96
|
+
.spyderproject
|
|
97
|
+
.spyproject
|
|
98
|
+
|
|
99
|
+
# Rope project settings
|
|
100
|
+
.ropeproject
|
|
101
|
+
|
|
102
|
+
# mkdocs documentation
|
|
103
|
+
/site
|
|
104
|
+
|
|
105
|
+
# mypy
|
|
106
|
+
.mypy_cache/
|
|
107
|
+
.dmypy.json
|
|
108
|
+
dmypy.json
|
|
109
|
+
|
|
110
|
+
# Pyre type checker
|
|
111
|
+
.pyre/
|
|
112
|
+
|
|
113
|
+
# pytype static type analyzer
|
|
114
|
+
.pytype/
|
|
115
|
+
|
|
116
|
+
# IDE
|
|
117
|
+
.idea/
|
|
118
|
+
.vscode/
|
|
119
|
+
*.swp
|
|
120
|
+
*.swo
|
|
121
|
+
|
|
122
|
+
# uv specific
|
|
123
|
+
.uv/
|
|
124
|
+
__pypackages__/
|
|
125
|
+
|
|
126
|
+
# Poetry specific
|
|
127
|
+
poetry.lock
|
|
128
|
+
|
|
129
|
+
# macOS
|
|
130
|
+
.DS_Store
|
|
131
|
+
|
|
132
|
+
# Windows
|
|
133
|
+
Thumbs.db
|
|
134
|
+
ehthumbs.db
|
|
135
|
+
Desktop.ini
|
|
136
|
+
|
|
137
|
+
# Coverage.py
|
|
138
|
+
.coverage.*
|
|
139
|
+
coverage.xml
|
|
140
|
+
htmlcov/
|
|
141
|
+
|
|
142
|
+
# Superpowers brainstorm sessions
|
|
143
|
+
.superpowers/
|
|
Binary file
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jakhongir Ganiev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
.PHONY: help venv install lint format test coverage dist publish release example clean
|
|
2
|
+
|
|
3
|
+
help: ## Show available commands
|
|
4
|
+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-12s %s\n", $$1, $$2}'
|
|
5
|
+
|
|
6
|
+
venv: ## Create virtual environment
|
|
7
|
+
uv venv
|
|
8
|
+
|
|
9
|
+
install: ## Install with dev dependencies
|
|
10
|
+
uv sync --group dev
|
|
11
|
+
|
|
12
|
+
lint: ## Check code style
|
|
13
|
+
uv run ruff check .
|
|
14
|
+
uv run ruff format --check .
|
|
15
|
+
|
|
16
|
+
format: ## Format code
|
|
17
|
+
uv run ruff check --fix .
|
|
18
|
+
uv run ruff format .
|
|
19
|
+
|
|
20
|
+
test: ## Run tests
|
|
21
|
+
uv run pytest
|
|
22
|
+
|
|
23
|
+
coverage: ## Run tests with coverage
|
|
24
|
+
uv run pytest --cov
|
|
25
|
+
|
|
26
|
+
dist: clean ## Build package
|
|
27
|
+
uv build
|
|
28
|
+
|
|
29
|
+
publish: dist ## Publish to PyPI
|
|
30
|
+
uv publish
|
|
31
|
+
|
|
32
|
+
example: ## Create example Django project
|
|
33
|
+
@./scripts/create_example_project.sh
|
|
34
|
+
|
|
35
|
+
release: lint test ## Release a version (usage: make release v=0.2.0)
|
|
36
|
+
@./scripts/release.sh $(v)
|
|
37
|
+
|
|
38
|
+
clean: ## Remove build artifacts
|
|
39
|
+
rm -rf build/ dist/ *.egg-info
|
|
40
|
+
find . -type d -name __pycache__ -exec rm -rf {} +
|
|
41
|
+
find . -type f -name '*.py[co]' -delete
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-markdown-widget
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A GitHub-style markdown editor widget for Django forms
|
|
5
|
+
Author-email: Jakhongir Ganiev <contact@jakhongir.dev>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: django,editor,github,markdown,widget
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Framework :: Django
|
|
11
|
+
Classifier: Framework :: Django :: 5.2
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: django>=5.2
|
|
19
|
+
Requires-Dist: mkdocs-material>=9.7.6
|
|
20
|
+
Requires-Dist: mkdocs>=1.6.1
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# django-md-editor
|
|
24
|
+
|
|
25
|
+
A GitHub-style markdown editor widget for Django forms and admin.
|
|
26
|
+
|
|
27
|
+
[](https://pypi.org/project/django-markdown-widget/)
|
|
28
|
+
[](https://pypi.org/project/django-markdown-widget/)
|
|
29
|
+
[](https://www.djangoproject.com/)
|
|
30
|
+
[](LICENSE)
|
|
31
|
+
[](https://ganiyevuz.github.io/django-md-editor/)
|
|
32
|
+
|
|
33
|
+
**[Documentation](https://ganiyevuz.github.io/django-md-editor/)** | **[PyPI](https://pypi.org/project/django-markdown-widget/)** | **[GitHub](https://github.com/ganiyevuz/django-md-editor)**
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- GitHub-flavored markdown editor with live preview
|
|
38
|
+
- Toolbar with common formatting actions (headings, bold, italic, code, tables, etc.)
|
|
39
|
+
- Image and file uploads with drag & drop support
|
|
40
|
+
- Light, dark, and auto theme support
|
|
41
|
+
- Django admin integration via one-line mixin
|
|
42
|
+
- Template tag and filter for rendering markdown in templates
|
|
43
|
+
- Pluggable renderer and upload handler architecture
|
|
44
|
+
- Automatic media cleanup for orphaned uploads
|
|
45
|
+
- Management command for bulk orphan detection
|
|
46
|
+
- Zero hard dependencies beyond Django (markdown library is optional)
|
|
47
|
+
- Keyboard shortcuts (Ctrl+B, Ctrl+I, Ctrl+K, etc.)
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install django-markdown-widget
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Add to your `INSTALLED_APPS` and include the URLs:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
# settings.py
|
|
59
|
+
INSTALLED_APPS = [
|
|
60
|
+
...
|
|
61
|
+
"django_md_editor",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
# urls.py
|
|
65
|
+
from django.urls import include, path
|
|
66
|
+
|
|
67
|
+
urlpatterns = [
|
|
68
|
+
...
|
|
69
|
+
path("md-editor/", include("django_md_editor.urls")),
|
|
70
|
+
]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For server-side rendering, install a markdown library:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install markdown
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
### Form Widget
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from django.forms import ModelForm
|
|
85
|
+
from django_md_editor import MarkdownEditorWidget
|
|
86
|
+
|
|
87
|
+
class PostForm(ModelForm):
|
|
88
|
+
class Meta:
|
|
89
|
+
model = Post
|
|
90
|
+
fields = ["title", "content"]
|
|
91
|
+
widgets = {
|
|
92
|
+
"content": MarkdownEditorWidget(),
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Django Admin
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from django.contrib import admin
|
|
100
|
+
from django_md_editor import MarkdownEditorAdminMixin
|
|
101
|
+
|
|
102
|
+
@admin.register(Post)
|
|
103
|
+
class PostAdmin(MarkdownEditorAdminMixin, admin.ModelAdmin):
|
|
104
|
+
list_display = ["title", "created_at"]
|
|
105
|
+
markdown_fields = ["content"] # omit to apply to all TextFields
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Template Rendering
|
|
109
|
+
|
|
110
|
+
```django
|
|
111
|
+
{% load md_editor %}
|
|
112
|
+
|
|
113
|
+
{# As a filter (recommended) #}
|
|
114
|
+
{{ post.content|markdown }}
|
|
115
|
+
|
|
116
|
+
{# As a tag #}
|
|
117
|
+
{% markdown post.content %}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Media Cleanup
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from django_md_editor import MarkdownCleanupMixin
|
|
124
|
+
|
|
125
|
+
class Post(MarkdownCleanupMixin, models.Model):
|
|
126
|
+
content = models.TextField()
|
|
127
|
+
# markdown_cleanup_fields = ["content"] # optional: limit to specific fields
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Enable in settings:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
MD_EDITOR = {
|
|
134
|
+
"CLEANUP_MEDIA": True,
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Bulk cleanup via management command:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
python manage.py cleanup_markdown_media --dry-run
|
|
142
|
+
python manage.py cleanup_markdown_media
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Configuration
|
|
146
|
+
|
|
147
|
+
All settings are optional and go under `MD_EDITOR` in your Django settings:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
MD_EDITOR = {
|
|
151
|
+
# Pluggable backend classes
|
|
152
|
+
"RENDERER_CLASS": "django_md_editor.renderers.DefaultRenderer",
|
|
153
|
+
"UPLOAD_HANDLER_CLASS": "django_md_editor.uploads.DefaultUploadHandler",
|
|
154
|
+
|
|
155
|
+
# Toolbar buttons
|
|
156
|
+
"TOOLBAR": [
|
|
157
|
+
"heading", "bold", "italic", "strikethrough", "separator",
|
|
158
|
+
"quote", "code", "code-block", "link", "image", "separator",
|
|
159
|
+
"ordered-list", "unordered-list", "task-list", "separator",
|
|
160
|
+
"horizontal-rule", "table", "details", "separator",
|
|
161
|
+
"highlight", "superscript", "subscript", "separator",
|
|
162
|
+
"attach", "mention", "ref", "separator",
|
|
163
|
+
"undo", "redo", "fullscreen",
|
|
164
|
+
],
|
|
165
|
+
|
|
166
|
+
# Upload settings
|
|
167
|
+
"ALLOWED_UPLOAD_TYPES": ["image/png", "image/jpeg", "image/gif", "image/webp"],
|
|
168
|
+
"MAX_UPLOAD_SIZE": 10 * 1024 * 1024, # 10 MB
|
|
169
|
+
"UPLOAD_PATH": "md-editor/uploads/%Y/%m/",
|
|
170
|
+
|
|
171
|
+
# Editor defaults
|
|
172
|
+
"DEFAULT_HEIGHT": "300px",
|
|
173
|
+
"PLACEHOLDER": "Add your comment here...",
|
|
174
|
+
"THEME": "auto", # "light", "dark", or "auto"
|
|
175
|
+
|
|
176
|
+
# Security
|
|
177
|
+
"REQUIRE_AUTH": True,
|
|
178
|
+
|
|
179
|
+
# Media cleanup
|
|
180
|
+
"CLEANUP_MEDIA": False,
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Custom Renderer
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from django_md_editor import BaseRenderer
|
|
188
|
+
|
|
189
|
+
class MyRenderer(BaseRenderer):
|
|
190
|
+
def render(self, markdown_text: str) -> str:
|
|
191
|
+
import markdown_it
|
|
192
|
+
md = markdown_it.MarkdownIt()
|
|
193
|
+
return md.render(markdown_text)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
MD_EDITOR = {
|
|
198
|
+
"RENDERER_CLASS": "myapp.renderers.MyRenderer",
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Custom Upload Handler
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from django_md_editor import BaseUploadHandler
|
|
206
|
+
|
|
207
|
+
class S3UploadHandler(BaseUploadHandler):
|
|
208
|
+
def validate(self, file):
|
|
209
|
+
# your validation logic
|
|
210
|
+
pass
|
|
211
|
+
|
|
212
|
+
def save(self, file) -> str:
|
|
213
|
+
# save to S3 and return the URL
|
|
214
|
+
return url
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
MD_EDITOR = {
|
|
219
|
+
"UPLOAD_HANDLER_CLASS": "myapp.uploads.S3UploadHandler",
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Development
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
git clone https://github.com/ganiyevuz/django-md-editor.git
|
|
227
|
+
cd django-md-editor
|
|
228
|
+
uv sync --group dev
|
|
229
|
+
make test
|
|
230
|
+
make lint
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Run the example app:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
cd example
|
|
237
|
+
python manage.py migrate
|
|
238
|
+
python manage.py createsuperuser
|
|
239
|
+
python manage.py runserver
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT License. See [LICENSE](LICENSE) for details.
|