-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
68 lines (61 loc) · 2.79 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Heading from '@ckeditor/ckeditor5-heading/src/heading';
import List from '@ckeditor/ckeditor5-list/src/list';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
import HtmlEmbed from '@ckeditor/ckeditor5-html-embed/src/htmlembed';
import Image from '@ckeditor/ckeditor5-image/src/image';
import ImageResize from '@ckeditor/ckeditor5-image/src/imageresize';
import Autosave from '@ckeditor/ckeditor5-autosave/src/autosave';
import CodeBlock from '@ckeditor/ckeditor5-code-block/src/codeblock';
/* twig plugin files */
import TwigPlugin from './twig/twigplugin';
import './twig/plugin.css';
/* demo page scripts */
import CKEditorInspector from '@ckeditor/ckeditor5-inspector';
import prettydiff from 'prettydiff';
import hljs from 'highlight.js';
/* demo page style */
import './demo.css';
import 'highlight.js/styles/agate.css';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ Autosave, Essentials, Paragraph, Heading, List, Bold, Italic, Image, ImageResize, HtmlEmbed, CodeBlock, TwigPlugin ],
toolbar: [ 'heading', 'bold', 'italic', 'bulletedList', 'htmlEmbed', 'codeBlock', 'twigCommands' ],
autosave: {
save( editor ) {
return window.displaySource( editor );
}
},
twig: {
variables: window.availableVariables // Defined in the index.html file
},
codeBlock: {
indentSequence: false,
languages: [
{ language: 'twig', label: 'Twig' }
// You can add other languages here, see https://ckeditor.com/docs/ckeditor5/latest/features/code-blocks.html#configuring-code-block-languages
]
}
} )
.then( editor => {
// Add the inspector (see https://ckeditor.com/docs/ckeditor5/latest/framework/guides/development-tools.html)
CKEditorInspector.attach( editor, { isCollapsed: true } );
// Expose for playing in the console.
window.editor = editor;
window.displaySource( editor );
} )
.catch( error => {
console.error( error.stack );
} );
window.displaySource = function( editor ) {
prettydiff.options.mode = 'beautify';
prettydiff.options.language = 'twig';
prettydiff.options.force_indent = true;
prettydiff.options.source = editor.getData();
document.getElementById( 'output' ).textContent = prettydiff();
document.getElementById( 'output' ).removeAttribute( 'data-highlighted' );
hljs.highlightElement( document.getElementById( 'output' ) );
};