11# vue-highlightjs
22Vue3 highlightjs with line numbers.
33
4- ## Toggle theme dark/light mode component with css
4+ ## Vue highlightjs component with toggle theme dark/light mode
55
66``` vue
77<script setup>
@@ -48,10 +48,11 @@ npm install @highlightjs/vue-plugin
4848</html>
4949```
5050
51- ## Vue3 setup highlightjs component
51+ ## Vue3 highlightjs component (mini)
5252
5353``` vue
54- <!-- CodeHighlight.vue -->
54+ <!-- CodeHighlightMini.vue -->
55+
5556<script setup>
5657import 'highlight.js/styles/default.css'
5758import 'highlight.js/styles/github.min.css'
@@ -78,13 +79,17 @@ function debugCode(code, language = "php") {
7879 :language="props.language"
7980 />
8081</template>
82+
83+ <style>
84+ @import url('./css/code.css');
85+ </style>
8186```
8287
8388## Use component in vue
8489
8590``` vue
8691<script setup>
87- import CodeHighlight from '@/components/CodeHighlight.vue';
92+ import CodeHighlightMini from '@/components/utils/ CodeHighlight/CodeHighlightMini .vue';
8893
8994const code = `<?php
9095
@@ -138,83 +143,11 @@ class User extends Authenticatable
138143
139144<template>
140145 <div class="section">
141- <CodeHighlight lang="php" :code="code"/>
146+ <CodeHighlightMini lang="php" :code="code" />
142147 </div>
143148</template>
144149```
145150
146- ## Css style line numbers (optional)
147-
148- ``` css
149- :root {
150- --font-family-code : ' Fira Code' , monospace , consolas;
151- --code-font-size : 14px ;
152- --code-border : #00339911 ;
153- --code-line-numbers : #6885ba ;
154- --code-line-border : #ff2233aa ;
155- --code-line-underline : #00339911 ;
156- }
157-
158- code {
159- font-size : var (--code-font-size );
160- font-family : var (--font-family-code );
161- border : 1px solid var (--code-border );
162- padding : 20px !important ;
163- }
164-
165- pre {
166- margin : 20px 0px ;
167- }
168-
169- code , code .hljs {
170- padding : 10px !important ;
171- overflow : hidden !important ;
172- }
173-
174- /* for block of numbers */
175- .hljs-ln {
176- float : left ;
177- width : 100% ;
178- font-size : var (--code-font-size );
179- font-family : ' JetBrains Mono' , ' Fira Code' , monospace , consolas;
180- }
181-
182- .hljs-ln tbody {
183- float : left ;
184- width : 100% !important ;
185- border : 1px solid var (--code-border );
186- }
187-
188- .hljs-ln tbody tr {
189- display : flex-table;
190- border-bottom : 1px solid var (--code-line-underline );
191- }
192-
193- .hljs-ln-numbers {
194- -webkit-touch-callout : none ;
195- -webkit-user-select : none ;
196- -khtml-user-select : none ;
197- -moz-user-select : none ;
198- -ms-user-select : none ;
199- user-select : none ;
200- text-align : center ;
201- color : var (--code-line-numbers );
202- border-right : 1px solid var (--code-line-border );
203- vertical-align : top ;
204- padding : 5px 10px !important ;
205-
206- /* your custom style here */
207- /* min-width: 60px;*/
208- }
209-
210- /* for block of code */
211- .hljs-ln-code {
212- width : 100% !important ;
213- padding-left : 10px !important ;
214- line-height : 24px ;
215- }
216- ```
217-
218151## Sample
219152
220153<img src =" https://raw.githubusercontent.com/atomjoy/vue-highlightjs/main/highlightjs-vue.png " width =" 100% " />
0 commit comments