import $ from 'jquery'
export default {
name: 'app',
data() {
return {
Editor: window.CKEDITOR
}
},
mounted() {
this.Editor.replace('editor', {
extraPlugins: 'codesnippet,preview'
})
},
methods: {
read() {
console.log(this.getData())
},
write() {
this.setData('hello world')
},
getData() {
return this.Editor.instances.editor.getData()
},
setData(html) {
this.Editor.instances.editor.setData(html)
},
addLineNumber() {
$('pre code').each(function () {
let lines = $(this).text().split('\n').length - 1
let $numbering = $('<ul/>').addClass('pre-numbering')
$(this)
.addClass('has-numbering')
.parent()
.append($numbering)
for (let i = 1; i <= lines; i++) {
$numbering.append($('<li/>').text(i))
}
})
}
}
}