mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 02:24:26 +00:00
Use auto generated api for markdown input
This commit is contained in:
parent
a71ca60270
commit
a98c924b24
@ -2,25 +2,21 @@
|
||||
import "codemirror/lib/codemirror.css";
|
||||
import "easymde/src/css/easymde.css";
|
||||
import easyMde from "easymde";
|
||||
|
||||
// This scripts dependens on Alpine but it should be loaded on every page
|
||||
import { markdownRenderMarkdown } from "#openapi";
|
||||
|
||||
/**
|
||||
* Create a new easymde based textarea
|
||||
* @param {HTMLTextAreaElement} textarea to use
|
||||
* @param {string} link to the markdown api
|
||||
**/
|
||||
window.easymdeFactory = (textarea, markdownApiUrl) => {
|
||||
window.easymdeFactory = (textarea) => {
|
||||
const easymde = new easyMde({
|
||||
element: textarea,
|
||||
spellChecker: false,
|
||||
autoDownloadFontAwesome: false,
|
||||
previewRender: Alpine.debounce(async (plainText, preview) => {
|
||||
const res = await fetch(markdownApiUrl, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ text: plainText }),
|
||||
});
|
||||
preview.innerHTML = await res.text();
|
||||
preview.innerHTML = (
|
||||
await markdownRenderMarkdown({ body: { text: plainText } })
|
||||
).data;
|
||||
return null;
|
||||
}, 300),
|
||||
forceSync: true, // Avoid validation error on generic create view
|
||||
|
@ -7,9 +7,7 @@
|
||||
<script type="text/javascript">
|
||||
addEventListener("DOMContentLoaded", (event) => {
|
||||
easymdeFactory(
|
||||
document.getElementById("{{ widget.attrs.id }}"),
|
||||
"{{ markdown_api_url }}",
|
||||
);
|
||||
document.getElementById("{{ widget.attrs.id }}"));
|
||||
})
|
||||
</script>
|
||||
</div>
|
||||
|
@ -39,7 +39,6 @@ from django.forms import (
|
||||
TextInput,
|
||||
)
|
||||
from django.templatetags.static import static
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
||||
@ -76,7 +75,6 @@ class MarkdownInput(Textarea):
|
||||
"js": static("webpack/easymde-index.js"),
|
||||
"css": static("webpack/easymde-index.css"),
|
||||
}
|
||||
context["markdown_api_url"] = reverse("api:markdown")
|
||||
return context
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user