Easily import snippets in your Nuxt Content documents.
- Import Code Snippets from any file
- Includes Syntax Highlighting
Warning: This module requires Nuxt Content to work. Make sure to install it first.
- Add
nuxt-content-snippet
dependency to your project
# Using pnpm
pnpm add -D nuxt-content-snippet
# Using yarn
yarn add --dev nuxt-content-snippet
# Using npm
npm install --save-dev nuxt-content-snippet
- Add
nuxt-content-snippet
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: [
'nuxt-content-snippet'
]
})
That's it! You can now use Nuxt Content Snippet in your Nuxt app ✨
You can import snippets from any file in your project. The snippet will be highlighted using the file extension.
info: By default, the snippet will be imported from the base directory
of your project. You can also specify a relative path to the file.
@@@ ./components/MyComponent.vue
@@@ @/components/MyComponent.vue
@@@ ../src/components/MyComponent.vue
If you want to highlight a specific section of the file, you can specify the lines to highlight using the following syntax:
@@@ ./components/MyComponent.vue {2-4}
Prefix is defined by default (@@@
). You can change it in your nuxt.config.ts
file:
export default defineNuxtConfig({
modules: [
'nuxt-content-snippet'
],
contentSnippet: {
prefix: '<<<'
}
})
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release