mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 21:16:22 +00:00
30 lines
1.2 KiB
JavaScript
30 lines
1.2 KiB
JavaScript
|
import {EditorState} from "prosemirror-state"
|
||
|
import {EditorView} from "prosemirror-view"
|
||
|
import {schema, defaultMarkdownParser, defaultMarkdownSerializer} from "prosemirror-markdown"
|
||
|
import {exampleSetup} from "prosemirror-example-setup"
|
||
|
|
||
|
import "prosemirror-gapcursor/style/gapcursor.css"
|
||
|
import "prosemirror-menu/style/menu.css"
|
||
|
import "prosemirror-view/style/prosemirror.css"
|
||
|
import "prosemirror-example-setup/style/style.css"
|
||
|
|
||
|
document.addEventListener('turbolinks:load', () => {
|
||
|
document.querySelectorAll('.markdown-content').forEach(mdc => {
|
||
|
let textArea = mdc.querySelector(".content"),
|
||
|
editor = mdc.querySelector(".markdown-editor");
|
||
|
|
||
|
let view = new EditorView(editor, {
|
||
|
state: EditorState.create({
|
||
|
doc: defaultMarkdownParser.parse(textArea.value),
|
||
|
plugins: exampleSetup({schema})
|
||
|
})
|
||
|
})
|
||
|
|
||
|
// Guardar los cambios al enviar el formulario y cada 10 segundos
|
||
|
textArea.form.addEventListener('submit', e => textArea.value = defaultMarkdownSerializer.serialize(view.state.doc));
|
||
|
setInterval(() => textArea.value = defaultMarkdownSerializer.serialize(view.state.doc), 10 * 1000);
|
||
|
// Ocultar el area
|
||
|
textArea.style.display = 'none'
|
||
|
})
|
||
|
})
|