Vue.js component: Beautiful code highlighter


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Vue.js component: Beautiful code highlighter

Sooner than later I will render forum discussions in Vue.js to complement the standard way of showing forum threads.

Today, I ran across this component, vue-code-highlight

Beautiful code syntax highlighting as Vue.js component.

Image

Usage

Code:
npm install vue-code-highlight --save

We can use this module in two different ways, as a component or as a directive.

Component

Code:
//We have to extract the component from the module
import { component as VueCodeHighlight } from 'vue-code-highlight';

components:{
  VueCodeHighlight,
  ...
}

HTML

Code:
<vue-code-highlight>
 //Paste code and output snippets here
</vue-code-highlight>


Window styles are already present in a component mode, but we will need to select and include a theme to properly highlight code. (See the themes section.)

Directive

In the main file:

Code:
import VueCodeHighlight from 'vue-code-highlight';

Vue.use(VueCodeHighlight) //registers the v-highlight directive

And then in any Vue component:

Code:
<div v-highlight >
 ...
</div>

HTML

All markup under the div element having the following structure will be syntax highlighted.

Code:
<pre class="language-javascript">
  <code>
    //your code goes here
  </code>
</pre>

HTML

To give the highlighter a window look in a directive mode, include the ./node_modules/vue-code-highlight/themes/window.css file somewhere in the app.

Themes

In order to visually highlight code, we need to select a theme from ./node_modules/vue-code-highlight/themes/ and import it somewhere into the component/application.

Reference: vue-code-highlight - npm

GitHub: GitHub - elisiondesign/vue-code-highlight: Beautiful code highlighter as Vue.js component.
# 2  
Also, this is a possibility:

GitHub Highlight.js

Quote:
Highlight.js is a syntax highlighter written in JavaScript. It works in the browser as well as on the server. It works with pretty much any markup, doesn’t depend on any framework, and has automatic language detection.

Reference: Web Page: highlight.js

Image
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Documenting Installation Problem with vue-beautiful-chat
Neo
REF: https://github.com/mattmezza/vue-beautiful-chat $ git clone https://github.com/mattmezza/vue-beautiful-chat.git Cloning into 'vue-beautiful-chat'... remote: Enumerating objects: 534, done. remote: Total 534 (delta 0), reused 0 (delta 0), pack-reused 534 Receiving objects: 100%...... Web Development
2
Web Development
Simple Vue.js Component to Redirect to External Web Page Using Vue Router
Neo
Vue Router has some quirks and on of the quirks is that it is not reliable when adding external links using the vue-router library. After struggling with many solutions, I have found that creating a simple Vue.js component like this one seems to work the best (so far): Component Example: ...... Web Development
0
Web Development
Turning jQuery Code into Vue.js
Neo
The following is some code I am working on the replace our navbar (someday) with a Vue component. Vue.component("unix-navbar", { template: `<div class="neo-table-border vuenavbar"><div class="flex-item" style="margin-bottom:10px;padding-top:13px;"><a class="vuenavbarhome"...... Web Development
19
Web Development
A simple UNIXtime component in Vue.js
Neo
A shout out to Scott who gave me a helping hand to turn a simple sample Vue.js app I wrote yesterday into a Vue.js component: Vue.component("unix-time", { template: `<div class="time">{{unixtime}}</div>`, data() { return { unixtime: "" }; }, methods: { ...... Web Development
1
Web Development
Ubuntu

Ubuntu is a free, open-source Linux distribution based on Debian Linux; and Ubuntu is named after the African philosophy of ubuntu, which Canonical translates as "humanity to others" or "I am what I am because of who we all are". Ubuntu is developed by Canonical and the community under a "meritocratic" governance model. Canonical provides security updates and support for each Ubuntu release, starting from the release date and until the release reaches its designated end-of-life (EOL) date. Canonical generates revenue through the sale of premium services associated with Ubuntu. Ubuntu is generally released to the public in three editions: Desktop, Server, and Core (for IoT devices and robots). Ubuntu is a popular operating system for cloud computing and supports OpenStack. Ubuntu is released every six months with long-term support (LTS) releases every two years.
Please enjoy and help our forum community by "showing your work" and posting your code, even when your code is not working as expected. To help others help you, please wrap your code blocks, sample input, sample output, error messages, and other data in CODE tags and wrap your short commands and short data objects in ICODE tags. We were all beginners in the beginning. If you have any questions about how to register or how to post, please contact us in Live Chat. Thank you and enjoy this "forever free" technical support community for UNIX, Linux and computer information technology in general.