-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
205 additions
and
614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
--- | ||
layout: doc | ||
--- | ||
|
||
# Get Started with vuejs-code-block | ||
|
||
|
||
## Installation | ||
|
||
To get started, install the package via npm: | ||
|
||
```bash | ||
npm install vuejs-code-block | ||
``` | ||
|
||
Alternatively, if you're using Yarn: | ||
|
||
```bash | ||
yarn add vuejs-code-block | ||
``` | ||
|
||
## Basic Usage | ||
|
||
Once installed, you can start using the `CodeBlock` component to display syntax-highlighted code in your Vue app. Here’s a simple example: | ||
|
||
```vue | ||
<template> | ||
<CodeBlock :code="exampleCode" language="javascript" /> | ||
</template> | ||
<script setup> | ||
import { CodeBlock } from 'vuejs-code-block' | ||
const exampleCode = `function greet(name) { | ||
console.log('Hello, ' + name); | ||
} | ||
greet('World'); | ||
` | ||
</script> | ||
``` | ||
|
||
### Props: | ||
- `code`: The actual code you want to display. | ||
- `language`: The programming language for syntax highlighting. | ||
|
||
## Advanced Features | ||
|
||
### Line Numbers | ||
|
||
To display line numbers alongside your code, simply use the `:show-line-numbers` prop. | ||
|
||
```vue | ||
<CodeBlock :code="exampleCode" language="javascript" :show-line-numbers="true" /> | ||
``` | ||
|
||
### Line Highlighting | ||
|
||
You can also highlight specific lines by using the `:highlight-lines` prop. | ||
|
||
```vue | ||
<CodeBlock :code="exampleCode" language="javascript" :highlight-lines="[1, 3]" /> | ||
``` | ||
|
||
## Custom Styling | ||
|
||
One of the key features of **vuejs-code-block** is that it provides **unstyled** components, allowing you to style them however you like. For example, using CSS or Tailwind classes: | ||
|
||
```vue | ||
<template> | ||
<div class="p-4 bg-gray-800 rounded-lg"> | ||
<CodeBlock :code="exampleCode" language="javascript" /> | ||
</div> | ||
</template> | ||
<script setup> | ||
import { CodeBlock } from 'vuejs-code-block' | ||
const exampleCode = `function greet(name) { | ||
console.log('Hello, ' + name); | ||
} | ||
greet('World'); | ||
` | ||
</script> | ||
<style> | ||
.my-custom-code { | ||
color: #00ff00; | ||
} | ||
</style> | ||
``` | ||
|
||
## Customization & Configuration | ||
|
||
With **vuejs-code-block**, you can extend functionality to suit your needs: | ||
|
||
- **Custom Line Numbers**: Customize how line numbers appear. | ||
- **Syntax Themes**: Use Prism.js themes or create your own. | ||
- **Dynamic Code Blocks**: Bind code content from your app’s data for interactive code examples. | ||
|
||
## Conclusion | ||
|
||
You now have everything you need to start building powerful, customizable code blocks in your Vue.js or VitePress projects using **vuejs-code-block**. For more advanced use cases, be sure to explore the documentation and available props. | ||
|
||
## Useful Links | ||
|
||
- [GitHub Repository](https://github.com/hetari/vuejs-code-block) | ||
- [Prism.js Documentation](https://prismjs.com/) | ||
- [Vue.js Documentation](https://vuejs.org/) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
layout: doc | ||
--- | ||
|
||
|
||
# Why Choose vuejs-code-block? | ||
|
||
Building code blocks can be surprisingly complex, especially when you're aiming for more than just basic syntax highlighting. While there are many libraries available that handle syntax highlighting, the moment you require additional features—like **line numbers**, **line highlighting**, or **word-level customization**—things get tricky. | ||
|
||
If you're a technical writer or developer creating documentation or blog posts, these features are often essential. However, most syntax highlighting libraries fall short, either lacking these features entirely or making it difficult to customize or extend their functionality. | ||
|
||
**vuejs-code-block** simplifies this process by focusing on the core functionality, leaving all styling and customization in your hands. Whether you need a basic code block or a highly customized one with advanced features, vuejs-code-block gives you the building blocks to achieve exactly what you want—without unnecessary bloat. | ||
|
||
## How It Works | ||
|
||
<!-- TODO: --> | ||
<!-- **prismjs** --> | ||
`vuejs-code-block` is built on top of the widely-used library for syntax highlighting. We've extended it by adding additional features such as: | ||
|
||
1. **Line Numbers**: Toggle line numbers on or off. | ||
2. **Custom Line Highlighting**: Highlight any specific lines with ease. | ||
3. **Word-Level Customization**: Highlight individual words or phrases for emphasis or further explanation. | ||
|
||
All of these features are exposed as **primitive Vue components**, giving you full flexibility to compose and style your code blocks however you want. | ||
|
||
|
||
## Why Vue.js? | ||
|
||
By offering **primitive components**, `vuejs-code-block` is incredibly flexible and allows for deep customization, unlike other libraries that come with rigid styling. As a Vue.js developer, you get to **compose** and **reuse** these components in a highly modular fashion, leveraging Vue’s reactive data and lifecycle methods for dynamic and performant code blocks. | ||
|
||
## Final Thoughts | ||
|
||
With `vuejs-code-block`, you're not just limited to out-of-the-box solutions—you’re empowered to create and style your code blocks exactly the way you envision. Whether you're building complex documentation, a technical blog, or educational material, this library lets you take full control of your code blocks without the headache of dealing with rigid styling or lack of customization. | ||
|
||
Start building custom, styled code blocks in your Vue.js projects today! |