Skip to content

Instantly share code, notes, and snippets.

@dvinciguerra
Created December 26, 2022 16:53
Show Gist options
  • Save dvinciguerra/fd1fbda8c1ddbce3f91d416740a22d6a to your computer and use it in GitHub Desktop.
Save dvinciguerra/fd1fbda8c1ddbce3f91d416740a22d6a to your computer and use it in GitHub Desktop.
Grav CMS editor hack (change to a wysiwyg)
// prepare editor resources
editor = {
script: '<script src="https://uicdn.toast.com/editor/latest/toastui-editor-all.min.js"></script>',
style: '<link rel="stylesheet" href="https://uicdn.toast.com/editor/latest/toastui-editor.min.css" />',
}
// inject editor source in grav webpage
body = document.querySelector('body')
body.insertAdjacentHTML('beforeend', editor.style)
body.insertAdjacentHTML('beforeend', editor.script)
// disable old grav-editor
grav = {}
grav.editor = document.querySelector('div.grav-editor')
grav.textarea = document.querySelector('textarea.code-mirrored')
grav.textarea.style.display = 'block'
grav.textarea.classList.remove('code-mirrored')
grav.editor.querySelector('div.grav-editor-toolbar').style.display = 'none'
grav.editor.querySelector('div.CodeMirror').style.display = 'none'
// configure editor
editor = new toastui.Editor({
el: grav.textarea,
height: '500px',
initialValue: grav.editor.value,
initialEditType: 'wysiwyg'
})
// editor.getMarkdown()
console.log('loaded!')
console.log(document.querySelectorAll('script'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment