You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Make sure the content of the `codeExample` string does **NOT** have leading spaces.
49
+
> The code should be formatted like this:
50
+
>
51
+
> ```ts
52
+
>const codeExample =`
53
+
> function greet(name) {
54
+
> console.log('Hello, ' + name);
55
+
> }
56
+
>
57
+
> greet('World');
58
+
> `;
59
+
>```
60
+
>
61
+
> Avoid writing it with leading spaces like this:
62
+
>
63
+
> ```ts
64
+
>const codeExample =`
65
+
> function greet(name) {
66
+
> console.log('Hello, ' + name);
67
+
> }
68
+
>
69
+
> greet('World');
70
+
> `;
71
+
>```
72
+
>
73
+
> Incorrect formatting may cause unexpected whitespace in the code block.
74
+
75
+
<!-- - **`codeClass`** (optional): A custom CSS class for the `<code>` element inside the block. This allows you to style the code content specifically. -->
76
+
<!-- - **`linesHighlighted`** (optional): An array of line numbers to be highlighted. Accepts an array of strings or numbers (e.g., `[1, 3]` to highlight the 1st and 3rd lines). -->
77
+
<!-- - **`wordsHighlighted`** (optional): An array of specific words to be highlighted within the code. Accepts an array of strings (e.g., `['console', 'log']`). -->
| `code` | `string` | Yes | N/A | The code you want to display, passed as a string. |
84
+
| `language` | `string` | Yes | N/A | Specifies the programming language for syntax highlighting. |
85
+
| `asElement` | `string` | No | `<pre>` | Defines the HTML element wrapping the code block (defaults to `<pre>`). |
86
+
| `numbered` | `boolean` | No | `false` | Displays line numbers when set to `true`. |
87
+
88
+
<!-- ## Custom Styling
66
89
67
90
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:
With **vuejs-code-block**, you can extend functionality to suit your needs:
97
-
98
-
-**Custom Line Numbers**: Customize how line numbers appear.
99
-
-**Syntax Themes**: Use Prism.js themes or create your own.
100
-
-**Dynamic Code Blocks**: Bind code content from your app’s data for interactive code examples.
101
-
102
-
## Conclusion
103
-
104
-
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.
Copy file name to clipboardExpand all lines: docs/why.md
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,9 @@
2
2
layout: doc
3
3
---
4
4
5
+
# Why `vuejs-code-block`?
5
6
6
-
# Why Choose vuejs-code-block?
7
-
8
-
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.
7
+
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.
9
8
10
9
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.
11
10
@@ -15,6 +14,7 @@ If you're a technical writer or developer creating documentation or blog posts,
15
14
16
15
<!-- TODO: -->
17
16
<!-- **prismjs** -->
17
+
18
18
`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:
19
19
20
20
1.**Line Numbers**: Toggle line numbers on or off.
@@ -23,7 +23,6 @@ If you're a technical writer or developer creating documentation or blog posts,
23
23
24
24
All of these features are exposed as **primitive Vue components**, giving you full flexibility to compose and style your code blocks however you want.
25
25
26
-
27
26
## Why Vue.js?
28
27
29
28
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.
0 commit comments