Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export transformers #1374

Merged
merged 3 commits into from Jul 22, 2022
Merged

feat: export transformers #1374

merged 3 commits into from Jul 22, 2022

Conversation

farnabaz
Copy link
Member

@farnabaz farnabaz commented Jul 22, 2022

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Simple usage

import { transformContent } from '@nuxt/content/transformers'

const parsed = await transformContent(
    'content:index.md',
    [
        '# Nuxt.js',
        '',
        '```ts',
        'console.log("Hello world!")',
        '```'
    ].join('\n')
)

Shiki transformer

import { transformContent } from '@nuxt/content/transformers'
import shiki from '@nuxt/content/transformers/shiki'

// For using the internal Shiki transformer we need to expose the global `$fetch` function
// which will be used by Shiki transformer to call highlight API
// See: https://github.com/nuxt/content/blob/main/src/runtime/server/api/highlight.ts
//
// Alternatively, you can create a custom transformer for Shiki and use that instead of the internal one
global.$fetch = () => ({})

const parsed = await transformContent(
    'content:index.md',
    [
        '# Nuxt.js',
        '',
        '```ts',
        'console.log("Hello world!")',
        '```'
    ].join('\n'),
    {
        transformers: [shiki]
    }
)

Custom transformer

import { transformContent, defineTransformer } from '@nuxt/content/transformers'

const myTransformer = defineTransformer({
    name: 'my-transformer',
    extensions: ['.*'],
    transform(parsedContent, options) {
        // Do magic here
    }
})

const parsed = await transformContent(
    'content:index.md',
    [
        '# Nuxt.js',
        '',
        '```ts',
        'console.log("Hello world!")',
        '```'
    ].join('\n'),
    {
        transformers: [myTransformer],
        myTransformer: {
            // options for my-transformer
        }
    }
)

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Jul 22, 2022

βœ… Deploy Preview for nuxt-content ready!

Name Link
πŸ”¨ Latest commit e2f0908
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt-content/deploys/62da72ed3f53bf0008909513
😎 Deploy Preview https://deploy-preview-1374--nuxt-content.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@farnabaz farnabaz merged commit e7bb0aa into main Jul 22, 2022
@farnabaz farnabaz deleted the feat/export-transformers branch July 22, 2022 09:57
@farnabaz farnabaz mentioned this pull request Aug 12, 2022
farnabaz added a commit that referenced this pull request Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants