Skip to content

Commit

Permalink
feat(prose): code block custom icon
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <[email protected]>
  • Loading branch information
ZTL-UwU committed Nov 20, 2024
1 parent 4202d29 commit 7295e57
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
8 changes: 4 additions & 4 deletions components/content/ProseCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
inStack && 'mb-0 rounded-none border-none shadow-none',
]"
>
<div v-if="!inGroup && filename" class="flex border-b p-3 font-mono text-sm">
<SmartIcon v-if="icon" :name="icon" class="mr-1.5 self-center" />
{{ filename }}
<div v-if="!inGroup && filename" class="flex items-center border-b p-3 font-mono text-sm">
<SmartIcon v-if="icon" :name="icon" class="mr-1.5" />
<span>{{ filename }}</span>
<CodeCopy :code class="ml-auto mr-1" />
</div>

Expand Down Expand Up @@ -69,7 +69,7 @@ const parsedMeta = computed(() => {
const iconMap = new Map(Object.entries(useConfig().value.main.codeIcon));
const icon = computed(() => {
const filenameLow = filename?.toLowerCase();
return (filenameLow && iconMap.get(filenameLow)) || (language && iconMap.get(language));
return parsedMeta.value.get('icon') || (filenameLow && iconMap.get(filenameLow)) || (language && iconMap.get(language));
});
</script>

Expand Down
54 changes: 39 additions & 15 deletions content/2.components/1.prose.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,36 @@ icon: lucide:letter-text

::code-group
::div{label="Preview" class="md:p-4"}
#### Code Block
```ts
export default () => {
console.log('Code block');
};
```

```ts [With Title]
export default () => {
console.log('Code block');
};
#### With Title
```ts [nuxt.config.ts]
export default defineNuxtConfig({
// My Nuxt config
});
```

```ts{2} [Highlight Lines]
#### Highlight Lines
```ts{2}
export default () => {
console.log('Code block');
};
```

```ts{1} [Line Numbers] line-numbers
#### Line Numbers
```ts{1} line-numbers
// line-numbers is enabled
const line2 = 'This is line 2';
const line3 = 'This is line 3';
```

```ts [Fixed Height] height=150
#### Fixed Height
```ts height=150
const parsedMeta = computed(() => {
const split = meta?.split(' ') ?? [];
const params = new Map<string, string | undefined>();
Expand All @@ -91,34 +96,46 @@ icon: lucide:letter-text
return params;
});
```

#### Custom Icon
```ts [Custom Icon] icon=lucide:code-xml line-numbers
// line-numbers is enabled
const line2 = 'This is line 2';
const line3 = 'This is line 3';
```
::

````md [Code]
#### Code Block
```ts
export default () => {
console.log('Code block');
};
```

```ts [With Title]
export default () => {
console.log('Code block');
};
#### With Title
```ts [nuxt.config.ts]
export default defineNuxtConfig({
// My Nuxt config
});
```

```ts{2} [Highlight Lines]
#### Highlight Lines
```ts{2}
export default () => {
console.log('Code block');
};
```

```ts{1} [Line Numbers] line-numbers
#### Line Numbers
```ts{1} line-numbers
// line-numbers is enabled
const line2 = 'This is line 2';
const line3 = 'This is line 3';
```

```ts [Fixed Height] height=150
#### Fixed Height
```ts height=150
const parsedMeta = computed(() => {
const split = meta?.split(' ') ?? [];
const params = new Map<string, string | undefined>();
Expand All @@ -131,7 +148,14 @@ icon: lucide:letter-text
return params;
});
```
````

#### Custom Icon
```ts [Custom Icon] icon=lucide:code-xml line-numbers
// line-numbers is enabled
const line2 = 'This is line 2';
const line3 = 'This is line 3';
```
````
::

### Inline Code
Expand Down

0 comments on commit 7295e57

Please sign in to comment.