-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How vue-quill-editor combine with the syntax highlighter module of highlight.js #39
Comments
Can you show me your code? Mainly part of your entry file, the introduction of highlight.js part and the introduction of components of the part. |
Thanks for so rapid answer. my html file looks like: |
Is it a vue webpack project? |
Try this code. // in your main.js
import 'highlight.js'
import 'highlight.js/styles/monokai-sublime.min.css'
import VueQuillEditor from 'vue-quill-editor'
// ... or <template>
<quill-editor v-model="content" :options="editorOption"></quill-editor>
</template>
<script>
import 'highlight.js/styles/monokai-sublime.min.css'
import 'highlight.js'
import Quill from 'quill'
export default {
// something...
}
</script> |
It's a vue webpack project. I gave a shot about the suggestions above, well, it still report the same error as before. I'm not sure if the order of import will be loaded in run time. I would try again and make some experiments about the load order of lib file. thanks surmon-china, could you give me some advise about these~ |
In fact, this is because quill internal self-closure caused by the problem, the solution is as follows: editorOption: {
modules: {
syntax: {
highlight: text => window.hljs.highlightAuto(text).value
// or
/*
highlight(text) {
const result = window.hljs.highlightAuto(text)
return result.value
}
*/
}
},
theme: 'snow'
} Other parts remain the same, highlight.js still need to be introduced before the introduction of quill. import hljs from 'highlight.js'
import 'highlight.js/styles/monokai-sublime.css' Enjoy your work! |
Wow, Thanks a lot, your save me tons of time. @surmon-china |
If anyone wants to use this in NUXT:
module.exports = {
...
css: [
'highlight.js/styles/atom-one-light.css'
],
...
}
import hljs from 'highlight.js'
...
editorOption: {
theme: 'snow',
modules: {
syntax: {
highlight: text => hljs.highlightAuto(text).value
}
}
} Thanks @surmon-china for pointing out the need for a function call! |
@macnie add hightlight config, like this
|
In NUXT project, highlight.js asynchronous change 'content'. In 'onEditorChange(){}' , 'this.content' repeated assignment. So dead cycle. The code and error are as follows:
|
Hi. In the or part you are importing |
Ok. I guess i solved it finally. And it's done. |
As the document of quill said, I add the highlight.js in my page.Well, no matter where I put the library in my html file, it always run out with the issue: Error: Syntax module requires highlight.js. Please include the library on the page before Quill., I searched a lot, but with no luck. Sorry, I know here isn't the place to ask question like that, but I really couldn't figure out how to solve this. So if anyone knows solutions about that, any suggestion will be appreciated, Thx.
The text was updated successfully, but these errors were encountered: