Skip to content

Commit

Permalink
Update to Vue 3 and add Typescript definitions (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinovantes authored May 28, 2021
1 parent 30aa26b commit b0b1efd
Show file tree
Hide file tree
Showing 15 changed files with 895 additions and 137 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
[![slack](https://badgen.net/badge/icon/slack?icon=slack&label&color=pink)](https://join.slack.com/t/highlightjs/shared_invite/zt-mj0utgqp-TNFf4VQICnDnPg4zMHChFw)


This plugin provides a `highlightjs` component for use
in your Vue.js applications:
This plugin provides a `highlightjs` component for use in your Vue.js 3 applications:

```html
<div id="app">
<div id="app">
<!-- bind to a data property named `code` -->
<highlightjs autodetect :code="code" />
<!-- or literal code works as well -->
<highlightjs language='javascript' code="var x = 5;" />
</div>
</div>
```

## Using the pre-built libraries
Expand All @@ -30,7 +29,8 @@ in your Vue.js applications:
Then simply register the plugin with Vue:

```js
Vue.use(hljsVuePlugin);
const app = createApp(App)
app.use(hljsVuePlugin)
```


Expand All @@ -39,11 +39,13 @@ Vue.use(hljsVuePlugin);
```js
import hljs from 'highlight.js/lib/core';
import javascript from 'highlight.js/lib/languages/javascript';
import vuePlugin from "@highlightjs/vue-plugin";
import hljsVuePlugin from "@highlightjs/vue-plugin";

hljs.registerLanguage('javascript', javascript);

Vue.use(vuePlugin);
const app = createApp(App)
app.use(hljsVuePlugin)
app.mount('#app')
```

Note: The plugin imports `highlight.js/lib/core` internally (but no languages). Thanks to the magic of ES6 modules you can import Highlight.js anywhere to register languages or configure the library. Any import of Highlight.js refers to the same singleton instance of the library, so configuring the library anywhere configures it everywhere.
Expand All @@ -52,8 +54,11 @@ You can also simply load all "common" languages at once (as of v11):

```js
import hljs from 'highlight.js/lib/common';
import vuePlugin from "@highlightjs/vue-plugin";
Vue.use(vuePlugin);
import hljsVuePlugin from "@highlightjs/vue-plugin";

const app = createApp(App)
app.use(hljsVuePlugin)
app.mount('#app')
```

## Building the pre-built library from source
Expand All @@ -62,4 +67,4 @@ We use rollup to build the `dist` distributable.

```
npm run build
```
```
1 change: 1 addition & 0 deletions dist/highlightjs-vue.esm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/highlightjs-vue.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/lib/utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function escapeHtml(value: string): string;
//# sourceMappingURL=utils.d.ts.map
1 change: 1 addition & 0 deletions dist/lib/utils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions dist/vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Plugin } from 'vue';
declare const plugin: Plugin;
export default plugin;
//# sourceMappingURL=vue.d.ts.map
1 change: 1 addition & 0 deletions dist/vue.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b0b1efd

Please sign in to comment.